Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No support for uint8_t and unsigned char arrays #851

Open
wflowersa opened this issue Nov 15, 2024 · 0 comments
Open

No support for uint8_t and unsigned char arrays #851

wflowersa opened this issue Nov 15, 2024 · 0 comments

Comments

@wflowersa
Copy link

Describe the bug
SWIG wrapper does not support arrays of type uint8_t and unsigned char

To reproduce

  1. Make copy of CModuleTemplateMsgPayload called TemplateCharMsgPayload and change dataVector type from double to unsigned char or uint8_t.
  2. Run script posted below (condensed version of example from stand-alone message tutorial)
  3. See error: TypeError: in method 'TemplateCharMsgPayload_dataVector_set', argument 2 of type 'unsigned char [3]'

Expected behavior
Script should be able to set dataVector array without error.

System Info

  • OS: Ubuntu
  • Version: 22.04.5 LTS
  • Python version: 3.10.12

Additional context
This appears to be an extension of this issue that was resolved with this pull request; however, support for uint8_t and unsigned char were not added. By adding the following lines to basilisk/src/architecture/_GeneralModuleFiles/swig_conly_data.i in their respective ARRAYASLIST and ARRAY2ASLIST locations, the issue appears to be resolved on my local machine:

ARRAYASLIST(uint8_t, PyLong_FromUnsignedLong, PyLong_AsUnsignedLong)
ARRAYASLIST(unsigned char, PyLong_FromUnsignedLong, PyLong_AsUnsignedLong)
ARRAY2ASLIST(uint8_t, PyLong_FromUnsignedLong, PyLong_AsUnsignedLong)
ARRAY2ASLIST(unsigned char, PyLong_FromUnsignedLong, PyLong_AsUnsignedLong)

Example script:

import sys
import matplotlib.pyplot as plt
from Basilisk.architecture import messaging
from Basilisk.moduleTemplates import cppModuleTemplate
from Basilisk.utilities import SimulationBaseClass
from Basilisk.utilities import macros
from Basilisk.utilities import unitTestSupport

def run():
    #  Create a sim module as an empty container
    scSim = SimulationBaseClass.SimBaseClass()

    #  create the simulation process
    dynProcess = scSim.CreateNewProcess("dynamicsProcess")

    # create the dynamics task and specify the integration update time
    dynProcess.addTask(scSim.CreateNewTask("dynamicsTask", macros.sec2nano(1.)))

    # create modules
    mod1 = cppModuleTemplate.CppModuleTemplate()
    mod1.ModelTag = "cppModule1"
    scSim.AddModelToTask("dynamicsTask", mod1)

    # create stand-alone input message
    msgData = messaging.TemplateCharMsgPayload()
    msgData.dataVector = [1, 2, 3]
    print(msgData.dataVector)
    msg = messaging.TemplateCharMsg().write(msgData)

    msgData.dataVector = [4, 5, 6]
    print(msgData.dataVector)
    msg = messaging.TemplateCharMsg().write(msgData)

if __name__ == "__main__":
    run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant