naoki-mizuno / ds4_driver

DualShock 4 driver for both ROS1 and ROS2
http://wiki.ros.org/ds4_driver
85 stars 53 forks source link

ds4_twist_node crashes on foxy-devel #21

Closed 3mrrrx closed 2 years ago

3mrrrx commented 2 years ago

I am having trouble running the "ds4_twist_node.py " on the "foxy-devel" branch.

the python script crashes on line 73:

val = eval(expr, {}, input_vals)

as the expr is allways of type None!

thanks for the support

naoki-mizuno commented 2 years ago

Thanks for reporting! ds4_twist_node.py seems to be working in my environment. Could you elaborate more about your environment and what you tried so far?

3mrrrx commented 2 years ago

thank you for the quick reply.

I just setup every thing two days ago, so i might have newer versions of some code. but i am not sure about this.

but everything is pretty much standard. i am using the "foxy-devel" branch.

when i echo the /status topic, and the output seams normal.

i also check if the ds4_twist.py is subscribing to the topic and getting the data, which seam to be the case.

i think the error happens in the part where the data from the /status topic is beaing mapped to the twist topic.

this is the error:

` ros2 run ds4_driver ds4_twist_node.py

Traceback (most recent call last): File "/home/ubuntu/ros2_example_ws/install/ds4_driver/lib/ds4_driver/ds4_twist_node.py", line 101, in main() File "/home/ubuntu/ros2_example_ws/install/ds4_driver/lib/ds4_driver/ds4_twist_node.py", line 95, in main rclpy.spin(node) File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/init.py", line 191, in spin executor.spin_once() File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/executors.py", line 714, in spin_once raise handler.exception() File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/task.py", line 239, in call self._handler.send(None) File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/executors.py", line 429, in handler await call_coroutine(entity, arg) File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/executors.py", line 354, in _execute_subscription await await_or_execute(sub.callback, msg) File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/executors.py", line 118, in await_or_execute return callback(*args) File "/home/ubuntu/ros2_example_ws/install/ds4_driver/lib/ds4_driver/ds4_twist_node.py", line 80, in cb_status val = eval(expr, None, input_vals) TypeError: eval() arg 1 must be a string, bytes or code object `

naoki-mizuno commented 2 years ago

Okay, I was able to reproduce the problem. It happens when you don't have the inputs parameter defined. You must either specify it via command line arguments or use ros2 launch ds4_driver ds4_twist.launch.xml.

Although, I did update the code so it doesn't crash when no parameter is defined, so please try out the latest commit.

3mrrrx commented 2 years ago

great!!! thank you....

i am still in the early stages of my project... that is why i was starting the nodes directly....

would be great to add the start/launch cmd to the read me!

naoki-mizuno commented 2 years ago

No problem! The README was indeed outdated so I updated it with the correct instructions.

3mrrrx commented 2 years ago

Hallo Again,

so basically to get the ds4_twist node to work with turtlesim i had to fix another bug.

the basic turtelsim node required a "none-stamped" type for the /cmd_vel topic, but the stamped argument is not passed when set in the launch.xml file.

furthermore the line 74 of ds4_twist.py gives an error:

'AttributeError: 'Twist' object has no attribute 'twist''

and thus has to be changed to something like :

twist = to_pub #.twist

with this quick fix i was able to get turtlesim to work with this node.

the bigger picture.... what i am trying to do with this node is to map the /status topic of this ds4_node to an arbitrary topic. thus making it possilble to control motors and other functions in ros2 using the ds4 controler.

how difficult would it be to add an arbitrary confi.yaml file that would do this kind of mapping?

thank you for the support!

naoki-mizuno commented 2 years ago

The stamped parameter in ds4_twist node controls whether it should output a Twist or a TwistStamped.

naoki-mizuno commented 2 years ago

Not quite sure what you mean by "mapping to an arbitrary topic."

3mrrrx commented 2 years ago

The stamped parameter in ds4_twist node controls whether it should output a Twist or a TwistStamped.

yes... think I am a aware of this part.. but when using the "Twist" output the code using in the library didn't work for two reasons:

  1. the Stamped Var is not read from the python code...
  2. In case of a "Twist" output the "to_pub" variable does not need to be appended with a "twist" as it is it's self a Twist object. in the current implantation of the code this results in the error:

AttributeError: 'Twist' object has no attribute 'twist'

and thus has to be changed to something like :

twist = to_pub #.twist

3mrrrx commented 2 years ago

Not quite sure what you mean by "mapping to an arbitrary topic."

the idea is to have generic topic that can be mapped with the input of the DS4 for example for topic:

/set_velocity "id: 1, velocity: axis_left_y "