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

Sending negative values via SDO #333

Open
Aragya1642 opened this issue Nov 15, 2024 · 1 comment
Open

Sending negative values via SDO #333

Aragya1642 opened this issue Nov 15, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Aragya1642
Copy link

Describe the bug
I am trying to send a negative target velocity via a SDO service call. However, when I attempt to do this, it is not possible as the data may only be sent as an unsigned integer (defined in the COWrite.srv file). The object code to which I am writing to supports negative values in the .eds file so I believe that this should work but is just not supported through the ros2_canopen package.

To Reproduce
Use the /sdo_write service to try and write a negative value to an object which should support negative values. This is the specific call I was writing which gave me an issue:
ros2 service call /motor1/sdo_write canopen_interfaces/srv/COWrite "{index: 0x60FF, subindex: 0x0, data: -100}"

Expected behavior
My motor was spinning clockwise, I would have expected the motor to spin counter-clockwise once a negative value was set. I was also expecting to receive a true status once the SDO was received which it never was and thus I never received this status.

Logs
When I had the COWrite.srv data as a uint this is the error output I see:

agoyal1642@agoyal1642-HP-Laptop-14-dq1xxx:~/Documents/Zoe2/zoe2$ ros2 service call /motor1/sdo_write canopen_interfaces/srv/COWrite "{index: 0x60FF, subindex: 0x0, data: -2000}"
requester: making request: canopen_interfaces.srv.COWrite_Request(index=24831, subindex=0, data=-2000)

OverflowError: can't convert negative value to unsigned int

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/ros/iron/bin/ros2", line 33, in <module>
    sys.exit(load_entry_point('ros2cli==0.25.6', 'console_scripts', 'ros2')())
  File "/opt/ros/iron/lib/python3.10/site-packages/ros2cli/cli.py", line 91, in main
    rc = extension.main(parser=parser, args=args)
  File "/opt/ros/iron/lib/python3.10/site-packages/ros2service/command/service.py", line 41, in main
    return extension.main(args=args)
  File "/opt/ros/iron/lib/python3.10/site-packages/ros2service/verb/call.py", line 58, in main
    return requester(
  File "/opt/ros/iron/lib/python3.10/site-packages/ros2service/verb/call.py", line 102, in requester
    future = cli.call_async(request)
  File "/opt/ros/iron/lib/python3.10/site-packages/rclpy/client.py", line 119, in call_async
    sequence_number = self.__client.send_request(request)
SystemError: <built-in method send_request of PyCapsule object at 0x7b993b04f3f0> returned a result with an exception set

However, when I changed the data to an int32, this was the terminal output I saw and the motor did spin the other way like I wanted it to:

agoyal1642@agoyal1642-HP-Laptop-14-dq1xxx:~/Documents/Zoe2/zoe2$ ros2 service call /motor1/sdo_write canopen_interfaces/srv/COWrite "{index: 0x60FF, subindex: 0x0, data: -2000}"
requester: making request: canopen_interfaces.srv.COWrite_Request(index=24831, subindex=0, data=-2000)

response:
canopen_interfaces.srv.COWrite_Response(success=True)

Setup:

  • Device: Linux Machine
  • OS: Ubuntu 22.04.4
  • ROS-Distro: Iron
  • Branch/Commit: Iron but this should apply to all

Additional context
When I try and build with changing the .srv file, warnings pop up relating to this change. This will probably require further investigation as to how to approach the issue.

@Aragya1642 Aragya1642 added the bug Something isn't working label Nov 15, 2024
@danzimmerman
Copy link

If you're using the CiA402 driver and want to send signed position or velocity targets, you can use the /motor1/target service which expects a COTargetDouble with a float64 type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants