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

ImportError: dynamic module does not define module export function (PyInit_bindings) #58

Open
skavrx opened this issue Dec 21, 2024 · 5 comments · May be fixed by #59
Open

ImportError: dynamic module does not define module export function (PyInit_bindings) #58

skavrx opened this issue Dec 21, 2024 · 5 comments · May be fixed by #59
Assignees

Comments

@skavrx
Copy link

skavrx commented Dec 21, 2024

Hi, I've been trying to install the actuator package onto my Jetson Nano. It is an older one, running JetPack 4.6 on Ubuntu 18.04 Bionic.

Jtop Output:

image

I setup a python virtual env with python 3.11 and used pip to install the actuator from pypip. Got this error. I also tried installing from the github source, got the same error.

(bike-env) ltr@defoliation-droid:~/Desktop$ python test_robstride.py 
Traceback (most recent call last):
  File "/home/ltr/Desktop/test_robstride.py", line 5, in <module>
    from actuator import RobstrideMotorsSupervisor
  File "/home/ltr/Desktop/bike-env/lib/python3.11/site-packages/actuator/__init__.py", line 3, in <module>
    from .bindings import (
ImportError: dynamic module does not define module export function (PyInit_bindings)

I am just trying to run the test code from the current docs:

import argparse
import math
import time
 
from actuator import RobstrideMotorsSupervisor
 
# Parse command line arguments.
parser = argparse.ArgumentParser()
parser.add_argument("--port-name", type=str, default="/dev/ttyUSB0")
parser.add_argument("--motor-id", type=int, default=1)
parser.add_argument("--motor-type", type=str, default="01")
parser.add_argument("--sleep", type=float, default=0.0)
parser.add_argument("--period", type=float, default=10.0)
parser.add_argument("--amplitude", type=float, default=1.0)
parser.add_argument("--verbose", action="store_true")
args = parser.parse_args()
 
amplitude = args.amplitude
period = args.period
 
# This creates a motor supervisor, which sends commands to all the actuators on
# the same CAN bus at a regular interval.
supervisor = RobstrideMotorsSupervisor(args.port_name, {args.motor_id: args.motor_type})
 
# This is used to set the KP and KD parameters for the MIT Cheetah-style
# PD controller.
supervisor.set_kp(args.motor_id, 10.0)
supervisor.set_kd(args.motor_id, 1.0)
 
start_time = time.time()
 
try:
    while True:
        elapsed_time = time.time() - start_time
        target_position = amplitude * math.sin(elapsed_time * 2 * math.pi / period)
        target_velocity = amplitude * 2 * math.pi / period * math.cos(elapsed_time * 2 * math.pi / period)
        supervisor.set_position(args.motor_id, target_position)
        supervisor.set_velocity(args.motor_id, target_velocity)
        time.sleep(args.sleep)
        if args.verbose:
            feedback = supervisor.get_latest_feedback()
            print(feedback)
 
except KeyboardInterrupt:
    supervisor.stop()
    time.sleep(0.1)
    raise
@WT-MM WT-MM linked a pull request Dec 21, 2024 that will close this issue
@WT-MM
Copy link
Member

WT-MM commented Dec 21, 2024

Oh - we recently made a bunch of changes that haven't been updated in the docs yet. Let me verify that the Python bindings work but until then, could you try this test script instead?

# Example of reading a motor using the supervisor.

import argparse
import time

from actuator import RobstrideActuatorConfig, RobstrideSupervisor


def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument("--port-name", type=str, default="/dev/ttyCH341USB0")
    parser.add_argument("--motor-id", type=int, default=1)
    parser.add_argument("--motor-type", type=str, default="04")
    parser.add_argument("--sleep", type=float, default=0.0)
    parser.add_argument("--period", type=float, default=10.0)
    parser.add_argument("--amplitude", type=float, default=1.0)
    parser.add_argument("--verbose", action="store_true")
    args = parser.parse_args()

    _amplitude = args.amplitude
    _period = args.period

    supervisor = RobstrideSupervisor(
        ports=[args.port_name],
        py_actuators_config=[(args.motor_id, RobstrideActuatorConfig(args.motor_type))],
        polling_interval=args.sleep,
    )

    while True:
        print(supervisor.get_actuators_state([args.motor_id]))
        time.sleep(1)


if __name__ == "__main__":
    # python -m examples.supervisor
    main()

@skavrx
Copy link
Author

skavrx commented Dec 22, 2024

Still getting the same error with that script

(bike-env) ltr@defoliation-droid:~/Desktop$ python test.py
Traceback (most recent call last):
  File "/home/ltr/Desktop/test.py", line 6, in <module>
    from actuator import RobstrideActuatorConfig, RobstrideSupervisor
  File "/home/ltr/Desktop/bike-env/lib/python3.11/site-packages/actuator/__init__.py", line 3, in <module>
    from .bindings import (
ImportError: dynamic module does not define module export function (PyInit_bindings)

@WT-MM
Copy link
Member

WT-MM commented Dec 22, 2024

Can you try replacing RobstrideSupervisor with RobstrideActuator everywhere?

Actually there are some build problems - i'll get back to you in a bit

@WT-MM WT-MM self-assigned this Dec 22, 2024
@skavrx
Copy link
Author

skavrx commented Dec 22, 2024

I have tried replacing it with RobstrideActuator everywhere I could think of, and I tried some older code I had working. The same code works fine on Windows machine with WSL, but fails on the Jetson Nano.

@WT-MM
Copy link
Member

WT-MM commented Dec 23, 2024

Sorry, the python bindings for this have been a lot more work than I expected. If you check the linked pr, I've got an example script that reads the motors but sending commands isn't fully working yet. I expect it'll take another few days so until then, you could also look at the source Rust code or even kos to run motors.

Also super weird that it works with WSL. Not sure why that'd be the case but I've been testing this code on a Jetson AGX

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

Successfully merging a pull request may close this issue.

2 participants