I want to use the robot based on ROS2 and python scripts.
Currently, I am trying to set the robot mode - like in Node Red - in order to be allowed to drive. However, I have problems with the format of the service message, both at command line as well as in Python. The reason seems to be the format.
I see the format string is not correct. The mode in the service contains the message type Mode which also contains the filed mode. → Please try “{mode: {mode: 4}}” instead. Btw only values != 0 has to be set. In this case only “mode”.
Second python example:
Below you will find a code snippet with which we have already set the mode in Python.Please note that this is only copied together and that the lines below belong in a function such as main.
import rclpy
from edu_robot.srv import SetMode
from edu_robot.msg import Mode
_srv_set_mode = None
def set_mode_robot(mode) -> None:
global _srv_set_mode
set_mode_request = SetMode.Request()
set_mode_request.mode.mode = mode
if (_srv_set_mode.service_is_ready() is False):
print('Service set mode not ready --> cancel operation')
return
future = _srv_set_mode.call_async(set_mode_request)
rclpy.spin_until_future_complete(_node, future)
if (future.result() is None):
print("New mode wasn't accepted by the robot.")
else:
print("Robot accepted new mode.")
// put below in a function like main()
rclpy.init(args=None)
_node = rclpy.create_node('edu_web_joy')
_srv_set_mode = _node.create_client(SetMode, 'set_mode')
set_mode_robot(Mode.REMOTE_CONTROLLED)
rclpy.spin(_node)
_node.destroy_node()
rclpy.shutdown()