ros-controls / ros2_control_demos

This repository aims at providing examples to illustrate ros2_control and ros2_controllers
https://control.ros.org
Apache License 2.0
365 stars 174 forks source link

Demo 14 crashing when using description from topic #455

Open fmauch opened 4 months ago

fmauch commented 4 months ago

Describe the bug Without further investigating this it seems that demo14 is currently broken at least on the master branch.

To Reproduce Run demo 14 as described in the docs

Update: To reproduce use the version from #456.

ros2 launch ros2_control_demo_example_14 rrbot_modular_actuators_without_feedback_sensors_for_position_feedback.launch.py

Output:

[INFO] [launch]: All log files can be found below /home/ubuntu/.ros/log/2024-02-29-19-32-42-042374-jamy-33260                                                                                                                                                                                                               
[INFO] [launch]: Default logging verbosity is set to INFO                                                                                                                                                                                                                                                                   
[INFO] [ros2_control_node-1]: process started with pid [33264]                                                                                                                                                                                                                                                              
[INFO] [robot_state_publisher-2]: process started with pid [33266]                                                                                                                                                                                                                                                          
[INFO] [spawner-3]: process started with pid [33268]                                                                                                                                                                                                                                                                        
[robot_state_publisher-2] [INFO] [1709235162.259080771] [robot_state_publisher]: Robot initialized                                                                                                                                                                                                                          
[ros2_control_node-1] [INFO] [1709235162.296861203] [controller_manager]: Subscribing to '/robot_description' topic for robot description.                                                                                                                                                                                  
[ros2_control_node-1] [INFO] [1709235162.297108401] [controller_manager]: update rate is 100 Hz                                                                                                                                                                                                                             
[ros2_control_node-1] [WARN] [1709235162.297235058] [controller_manager]: Could not enable FIFO RT scheduling policy. Consider setting up your user to do FIFO RT scheduling. See [https://control.ros.org/master/doc/ros2_control/controller_manager/doc/userdoc.html] for details.                                        
[ros2_control_node-1] [INFO] [1709235162.307313025] [controller_manager]: Received robot description from topic.                                                                                                                                                                                                            
[ros2_control_node-1] [INFO] [1709235162.307854653] [resource_manager]: Loading hardware 'RRBotModularPositionSensorJoint1'                                                                                                                                                                                                 
[ros2_control_node-1] [INFO] [1709235162.309086054] [resource_manager]: Initialize hardware 'RRBotModularPositionSensorJoint1'                                                                                                                                                                                              
[ros2_control_node-1] [INFO] [1709235162.309315034] [RRBotSensorPositionFeedback]: Setting socket options.                                                                                                                                                                                                                  
[ros2_control_node-1] [INFO] [1709235162.309327406] [RRBotSensorPositionFeedback]: Binding to socket address.                                                                                                                                                                                                               
[ros2_control_node-1] [INFO] [1709235162.309417033] [resource_manager]: Successful initialization of hardware 'RRBotModularPositionSensorJoint1'                                                                                                                                                                            
[ros2_control_node-1] [INFO] [1709235162.309436681] [RRBotSensorPositionFeedback]: Listening for connection on port 23286.                                                                                                                                                                                                  
[ros2_control_node-1] [INFO] [1709235162.309587643] [resource_manager]: Loading hardware 'RRBotModularPositionSensorJoint2'                                                                                                                                                                                                 
[ros2_control_node-1] [INFO] [1709235162.309663852] [resource_manager]: Initialize hardware 'RRBotModularPositionSensorJoint2'                                                                                                                                                                                              
[ros2_control_node-1] [INFO] [1709235162.309700970] [RRBotSensorPositionFeedback]: Setting socket options.                                                                                                                                                                                                                  
[ros2_control_node-1] [INFO] [1709235162.309707412] [RRBotSensorPositionFeedback]: Binding to socket address.                                                                                                                                                                                                               
[ros2_control_node-1] [INFO] [1709235162.309759944] [resource_manager]: Successful initialization of hardware 'RRBotModularPositionSensorJoint2'                                                                                                                                                                            
[ros2_control_node-1] [INFO] [1709235162.309777021] [RRBotSensorPositionFeedback]: Listening for connection on port 23287.                                                                                                                                                                                                  
[ros2_control_node-1] [INFO] [1709235162.309808843] [resource_manager]: Loading hardware 'RRBotModularJoint1'                                                                                                                                                                                                               
[ros2_control_node-1] [INFO] [1709235162.310270555] [resource_manager]: Initialize hardware 'RRBotModularJoint1'                                                                                                                                                                                                            
[ros2_control_node-1] [INFO] [1709235162.310459729] [RRBotActuatorWithoutFeedback]: Trying to connect to port 23286.                                                                                                                                                                                                        
[ros2_control_node-1] [INFO] [1709235162.310562841] [RRBotActuatorWithoutFeedback]: Connected to socket                                                                                                                                                                                                                     
[ros2_control_node-1] [INFO] [1709235162.310576795] [resource_manager]: Successful initialization of hardware 'RRBotModularJoint1'                                                                                                                                                                                          
[ros2_control_node-1] [INFO] [1709235162.310567684] [RRBotSensorPositionFeedback]: Accepting on socket.                                                                                                                                                                                                                     
[ros2_control_node-1] [INFO] [1709235162.310622175] [RRBotSensorPositionFeedback]: Creating thread for incoming data and read them with 1000 Hz to not miss any data.                                                                                                                                                       
[ros2_control_node-1] [INFO] [1709235162.310779968] [resource_manager]: Loading hardware 'RRBotModularJoint2'                                                                                                                                                                                                               
[ros2_control_node-1] [INFO] [1709235162.310835259] [resource_manager]: Initialize hardware 'RRBotModularJoint2'                                                                                                                                                                                                            
[ros2_control_node-1] [INFO] [1709235162.310910182] [RRBotActuatorWithoutFeedback]: Trying to connect to port 23287.                                                                                                                                                                                                        
[ros2_control_node-1] [INFO] [1709235162.310951499] [RRBotActuatorWithoutFeedback]: Connected to socket                                                                                                                                                                                                                     
[ros2_control_node-1] [INFO] [1709235162.310954184] [RRBotSensorPositionFeedback]: Accepting on socket.                                                                                                                                                                                                                     
[ros2_control_node-1] [INFO] [1709235162.310966863] [RRBotSensorPositionFeedback]: Creating thread for incoming data and read them with 1000 Hz to not miss any data.                                                                                                                                                       
[ros2_control_node-1] [INFO] [1709235162.310960704] [resource_manager]: Successful initialization of hardware 'RRBotModularJoint2'
[ros2_control_node-1] [INFO] [1709235162.311196939] [resource_manager]: 'configure' hardware 'RRBotModularJoint2' 
[ros2_control_node-1] [INFO] [1709235162.311221129] [resource_manager]: Successful 'configure' of hardware 'RRBotModularJoint2'
[ros2_control_node-1] [INFO] [1709235162.311235706] [resource_manager]: 'activate' hardware 'RRBotModularJoint2' 
[ros2_control_node-1] [INFO] [1709235162.311241783] [RRBotActuatorWithoutFeedback]: Activating ...please wait...
[ros2_control_node-1] [INFO] [1709235162.311684397] [RRBotSensorPositionFeedback]: Receiving data
[ros2_control_node-1] [INFO] [1709235162.312043305] [RRBotSensorPositionFeedback]: Receiving data
[ros2_control_node-1] [INFO] [1709235162.317357018] [RRBotActuatorWithoutFeedback]: Writing command: nan
[ros2_control_node-1] [INFO] [1709235162.317383404] [RRBotActuatorWithoutFeedback]: Sending data command: nan
[ros2_control_node-1] [INFO] [1709235162.317411609] [RRBotActuatorWithoutFeedback]: Joints successfully written!
[ros2_control_node-1] terminate called after throwing an instance of 'std::invalid_argument'
[ros2_control_node-1]   what():  Failed converting string to real number
[ros2_control_node-1] Stack trace (most recent call last) in thread 33311:
[ros2_control_node-1] #17   Object "", at 0xffffffffffffffff, in
[ros2_control_node-1] [INFO] [1709235162.327358845] [RRBotActuatorWithoutFeedback]: Writing command: nan
[ros2_control_node-1] [INFO] [1709235162.327373636] [RRBotActuatorWithoutFeedback]: Sending data command: nan
[ros2_control_node-1] [INFO] [1709235162.327394251] [RRBotActuatorWithoutFeedback]: Joints successfully written!
[ros2_control_node-1] [INFO] [1709235162.337357589] [RRBotActuatorWithoutFeedback]: Writing command: nan
[ros2_control_node-1] [INFO] [1709235162.337371146] [RRBotActuatorWithoutFeedback]: Sending data command: nan
[ros2_control_node-1] [INFO] [1709235162.337395131] [RRBotActuatorWithoutFeedback]: Joints successfully written!
[ros2_control_node-1] [INFO] [1709235162.347403064] [RRBotActuatorWithoutFeedback]: Writing command: nan
[ros2_control_node-1] [INFO] [1709235162.347429687] [RRBotActuatorWithoutFeedback]: Sending data command: nan
[ros2_control_node-1] [INFO] [1709235162.347457466] [RRBotActuatorWithoutFeedback]: Joints successfully written!
[ros2_control_node-1] [INFO] [1709235162.357372600] [RRBotActuatorWithoutFeedback]: Writing command: nan
[ros2_control_node-1] [INFO] [1709235162.357396582] [RRBotActuatorWithoutFeedback]: Sending data command: nan
[ros2_control_node-1] [INFO] [1709235162.357424274] [RRBotActuatorWithoutFeedback]: Joints successfully written!
[ros2_control_node-1] [INFO] [1709235162.367364811] [RRBotActuatorWithoutFeedback]: Writing command: nan
[ros2_control_node-1] [INFO] [1709235162.367384170] [RRBotActuatorWithoutFeedback]: Sending data command: nan
[ros2_control_node-1] [INFO] [1709235162.367413240] [RRBotActuatorWithoutFeedback]: Joints successfully written!
[ros2_control_node-1] #16   Source "../sysdeps/unix/sysv/linux/x86_64/clone3.S", line 81, in __clone3 [0x7f7d7be7c84f]
[ros2_control_node-1] #15   Source "./nptl/pthread_create.c", line 442, in start_thread [0x7f7d7bdeaac2]
[ros2_control_node-1] #14   Object "/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30", at 0x7f7d7c05b252, in 
[ros2_control_node-1] #13   Object "/home/ubuntu/checkout/ros2_control/colcon_ws/install/ros2_control_demo_example_14/lib/libros2_control_demo_example_14.so", at 0x7f7d706e0a07, in std::thread::_State_impl<std::thread::_Invoker<std::tuple<ros2_control_demo_example_14::RRBotSensorPositionFeedback::on_init(hardware_i
nterface::HardwareInfo const&)::{lambda()#1}> > >::_M_run()
[ros2_control_node-1] #12   Object "/home/ubuntu/checkout/ros2_control/colcon_ws/install/ros2_control_demo_example_14/lib/libros2_control_demo_example_14.so", at 0x7f7d706e0a23, in std::thread::_Invoker<std::tuple<ros2_control_demo_example_14::RRBotSensorPositionFeedback::on_init(hardware_interface::HardwareInfo co
nst&)::{lambda()#1}> >::operator()()                                           
[ros2_control_node-1] #11   Object "/home/ubuntu/checkout/ros2_control/colcon_ws/install/ros2_control_demo_example_14/lib/libros2_control_demo_example_14.so", at 0x7f7d706e0a4d, in rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn std::thread::_Invoker<std::tuple<ros2_control_demo_example_14
::RRBotSensorPositionFeedback::on_init(hardware_interface::HardwareInfo const&)::{lambda()#1}> >::_M_invoke<0ul>(std::_Index_tuple<0ul>)
[ros2_control_node-1] #10   Object "/home/ubuntu/checkout/ros2_control/colcon_ws/install/ros2_control_demo_example_14/lib/libros2_control_demo_example_14.so", at 0x7f7d706e0a9f, in std::__invoke_result<ros2_control_demo_example_14::RRBotSensorPositionFeedback::on_init(hardware_interface::HardwareInfo const&)::{lamb
da()#1}>::type std::__invoke<ros2_control_demo_example_14::RRBotSensorPositionFeedback::on_init(hardware_interface::HardwareInfo const&)::{lambda()#1}>(ros2_control_demo_example_14::RRBotSensorPositionFeedback::on_init(hardware_interface::HardwareInfo const&)::{lambda()#1}&&)
[ros2_control_node-1] #9    Object "/home/ubuntu/checkout/ros2_control/colcon_ws/install/ros2_control_demo_example_14/lib/libros2_control_demo_example_14.so", at 0x7f7d706e0adb, in rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn std::__invoke_impl<rclcpp_lifecycle::node_interfaces::Lifecyc
leNodeInterface::CallbackReturn, ros2_control_demo_example_14::RRBotSensorPositionFeedback::on_init(hardware_interface::HardwareInfo const&)::{lambda()#1}>(std::__invoke_other, ros2_control_demo_example_14::RRBotSensorPositionFeedback::on_init(hardware_interface::HardwareInfo const&)::{lambda()#1}&&)
[ros2_control_node-1] #8    Object "/home/ubuntu/checkout/ros2_control/colcon_ws/install/ros2_control_demo_example_14/lib/libros2_control_demo_example_14.so", at 0x7f7d706db8b6, in ros2_control_demo_example_14::RRBotSensorPositionFeedback::on_init(hardware_interface::HardwareInfo const&)::{lambda()#1}::operator()()
 const                                                                         
[ros2_control_node-1] #7    Object "/home/ubuntu/checkout/ros2_control/colcon_ws/install/hardware_interface/lib/libhardware_interface.so", at 0x7f7d7bbcb19f, in hardware_interface::stod(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)
[ros2_control_node-1] #6    Object "/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30", at 0x7f7d7c02d4d7, in __cxa_throw
[ros2_control_node-1] #5    Object "/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30", at 0x7f7d7c02d276, in std::terminate()
[ros2_control_node-1] #4    Object "/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30", at 0x7f7d7c02d20b, in 
[ros2_control_node-1] #3    Object "/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.30", at 0x7f7d7c021b9d, in 
[ros2_control_node-1] #2    Source "./stdlib/abort.c", line 79, in abort [0x7f7d7bd7e7f2]
[ros2_control_node-1] #1    Source "../sysdeps/posix/raise.c", line 26, in raise [0x7f7d7bd98475]
[ros2_control_node-1] #0  | Source "./nptl/pthread_kill.c", line 89, in __pthread_kill_internal
[ros2_control_node-1]     | Source "./nptl/pthread_kill.c", line 78, in __pthread_kill_implementation
[ros2_control_node-1]       Source "./nptl/pthread_kill.c", line 44, in __pthread_kill [0x7f7d7bdec9fc]
[ros2_control_node-1] Aborted (Signal sent by tkill() 33264 1000)
[ERROR] [ros2_control_node-1]: process has died [pid 33264, exit code -6, cmd '/home/ubuntu/checkout/ros2_control/colcon_ws/install/controller_manager/lib/controller_manager/ros2_control_node --ros-args --params-file /home/ubuntu/checkout/ros2_control/colcon_ws/install/ros2_control_demo_example_14/share/ros2_contro
l_demo_example_14/config/rrbot_modular_actuators_without_feedback_sensors_for_position_feedback.yaml'].

Expected behavior I would expect things not to crash ;-)

Environment (please complete the following information): ROS 2 rolling with ros2_control workspace with current master everywhere:

========= control_msgs =========
74e69e3a056279196236392673688f64e3d593a8
========= control_toolbox =========
759d95422893e03fdc88bfe0430370b13902b6f7
========= gz_ros2_control =========
c5b0b9049ce75410e75d1828242c1dfd5b19bb80
========= kinematics_interface =========
6b5d811e73d2f019af98988805160bba96b3940c
========= realtime_tools =========
8995b494d4a0f3b0655f1aa9bffb92d43a988c46
========= ros2_control =========
0711cd6274eace78dde90f56b7994e60edba7697
========= ros2_control_demos =========
044db05c476c1bd99132b511e491fc00c8eabd56
========= ros2_controllers =========
00172ab5dbd4948df78493e5acd40901a7227976

Additional context I didn't investigate this all too much but did not want that to get lost on the way.

christophfroehlich commented 4 months ago

I can't reproduce it with a clean build of colcon build --packages-up-to ros2_control_demo_example_14

fmauch commented 4 months ago

Thanks for checking. Then I'll look around locally.

saikishor commented 4 months ago

I can't reproduce it as well. It works for me :)

fmauch commented 4 months ago

OK, the problems seems indeed to come from my change in #456. Looks like when using the description topic it tries to send commands to the hardware before it is activated.

[ros2_control_node-1] [INFO] [1709235162.311241783] [RRBotActuatorWithoutFeedback]: Activating ...please wait...
[ros2_control_node-1] [INFO] [1709235162.311684397] [RRBotSensorPositionFeedback]: Receiving data
[ros2_control_node-1] [INFO] [1709235162.312043305] [RRBotSensorPositionFeedback]: Receiving data
[ros2_control_node-1] [INFO] [1709235162.317357018] [RRBotActuatorWithoutFeedback]: Writing command: nan
[ros2_control_node-1] [INFO] [1709235162.317383404] [RRBotActuatorWithoutFeedback]: Sending data command: nan
[ros2_control_node-1] [INFO] [1709235162.317411609] [RRBotActuatorWithoutFeedback]: Joints successfully written!

vs. using the description parameter:

[ros2_control_node-1] [INFO] [1709406595.828694734] [RRBotActuatorWithoutFeedback]: Activating ...please wait...                                                                                                                                                                                                            
[spawner-3] [INFO] [1709406596.132883688] [spawner_joint_state_broadcaster]: Waiting for '/controller_manager' services to be available                                                                                                                                                                                     
[ros2_control_node-1] [INFO] [1709406596.828821648] [RRBotActuatorWithoutFeedback]: 2.0 seconds left...                                                                                                                                                                                                                     
[ros2_control_node-1] [INFO] [1709406597.829122935] [RRBotActuatorWithoutFeedback]: 1.0 seconds left...
[ros2_control_node-1] [INFO] [1709406597.829185501] [RRBotActuatorWithoutFeedback]: Successfully activated!
[ros2_control_node-1] [INFO] [1709406597.829215398] [resource_manager]: Successful 'activate' of hardware 'RRBotModularJoint1'
[ros2_control_node-1] [INFO] [1709406597.829412333] [resource_manager]: 'configure' hardware 'RRBotModularPositionSensorJoint2' 
[ros2_control_node-1] [INFO] [1709406597.829475210] [RRBotSensorPositionFeedback]: Configuration successful.
[ros2_control_node-1] [INFO] [1709406597.829491110] [resource_manager]: Successful 'configure' of hardware 'RRBotModularPositionSensorJoint2'
[ros2_control_node-1] [INFO] [1709406597.829526538] [resource_manager]: 'activate' hardware 'RRBotModularPositionSensorJoint2' 
[ros2_control_node-1] [INFO] [1709406597.829540464] [RRBotSensorPositionFeedback]: Activating ...please wait...
[spawner-3] [INFO] [1709406598.160180152] [spawner_joint_state_broadcaster]: Waiting for '/controller_manager' services to be available
[ros2_control_node-1] [INFO] [1709406598.829744724] [RRBotSensorPositionFeedback]: 1.0 seconds left...
[ros2_control_node-1] [INFO] [1709406598.829808242] [RRBotSensorPositionFeedback]: Successfully activated!
[ros2_control_node-1] [INFO] [1709406598.829836718] [resource_manager]: Successful 'activate' of hardware 'RRBotModularPositionSensorJoint2'
[ros2_control_node-1] [INFO] [1709406598.829935389] [resource_manager]: 'configure' hardware 'RRBotModularPositionSensorJoint1' 
[ros2_control_node-1] [INFO] [1709406598.829959936] [RRBotSensorPositionFeedback]: Configuration successful.
[ros2_control_node-1] [INFO] [1709406598.829973430] [resource_manager]: Successful 'configure' of hardware 'RRBotModularPositionSensorJoint1'
[ros2_control_node-1] [INFO] [1709406598.830003075] [resource_manager]: 'activate' hardware 'RRBotModularPositionSensorJoint1' 
[ros2_control_node-1] [INFO] [1709406598.830015991] [RRBotSensorPositionFeedback]: Activating ...please wait...
[ros2_control_node-1] [INFO] [1709406599.830308578] [RRBotSensorPositionFeedback]: 1.0 seconds left...
[ros2_control_node-1] [INFO] [1709406599.830371781] [RRBotSensorPositionFeedback]: Successfully activated!
[ros2_control_node-1] [INFO] [1709406599.830399869] [resource_manager]: Successful 'activate' of hardware 'RRBotModularPositionSensorJoint1'
[ros2_control_node-1] [INFO] [1709406599.842852174] [controller_manager]: update rate is 100 Hz
[ros2_control_node-1] [WARN] [1709406599.842956793] [controller_manager]: Could not enable FIFO RT scheduling policy. Consider setting up your user to do FIFO RT scheduling. See [https://control.ros.org/master/doc/ros2_control/controller_manager/doc/userdoc.html] for details.
[ros2_control_node-1] [INFO] [1709406599.843048536] [RRBotSensorPositionFeedback]: Reading...
[ros2_control_node-1] [INFO] [1709406599.843066684] [RRBotSensorPositionFeedback]: Got measured velocity nan
[ros2_control_node-1] [INFO] [1709406599.843072846] [RRBotSensorPositionFeedback]: Got state 0.00000 for joint 'joint1'!
[ros2_control_node-1] [INFO] [1709406599.843078447] [RRBotSensorPositionFeedback]: Joints successfully read!
[ros2_control_node-1] [INFO] [1709406599.843083413] [RRBotSensorPositionFeedback]: Reading...
[ros2_control_node-1] [INFO] [1709406599.843086367] [RRBotSensorPositionFeedback]: Got measured velocity nan
[ros2_control_node-1] [INFO] [1709406599.843089180] [RRBotSensorPositionFeedback]: Got state 0.00000 for joint 'joint2'!
[ros2_control_node-1] [INFO] [1709406599.843092310] [RRBotSensorPositionFeedback]: Joints successfully read!
[ros2_control_node-1] [INFO] [1709406599.843112064] [RRBotActuatorWithoutFeedback]: Writing command: 0.000000
[ros2_control_node-1] [INFO] [1709406599.843128883] [RRBotActuatorWithoutFeedback]: Sending data command: 0
[ros2_control_node-1] [INFO] [1709406599.843169503] [RRBotActuatorWithoutFeedback]: Joints successfully written!

I didn't consider this at first, as I merely changed the way the description was fed and the node ended up with the correct description. However, using the description from the topic completely changes initialization. I'll update the title accordingly.

However, the question is: Where's the fault? It seems weird that write() is actually being called before the hardware is actually active.

This demo example is an interesting special case since the on_activate() artificially takes a couple of seconds which is usually probably not the case.

Or is it a requirement that on_activate() is required to be real-time-safe and run in one control cycle? Now that I'm aware of the reason I remember I've seen something similar on the UR driver before we restructured things in on_configure and on_activate correctly.

So my main question would be: Is this behavior to be expected and the requirements for the on_activate() aren't fulfilled or do we have to update something in the controller_manager / resource_manager?


Edit: I think, I understand now why this happens. During initialization, the hw interface sets the buffer command to NaN:

https://github.com/ros-controls/ros2_control_demos/blob/044db05c476c1bd99132b511e491fc00c8eabd56/example_14/hardware/rrbot_actuator_without_feedback.cpp#L52

Then, in on_activate(), there is an artificial sleep to "simulate" processes taking some time. After that, the command buffer is set to 0.0:

https://github.com/ros-controls/ros2_control_demos/blob/044db05c476c1bd99132b511e491fc00c8eabd56/example_14/hardware/rrbot_actuator_without_feedback.cpp#L147-L151

Since urdf loading and activating the hardware isn't blocking the update() loop and the resource manager calls write() for all command interface independent of their state.

So, one way of "fixing" this short term would be a check in the write() method whether the command is NaN and long term to finally implement command interfaces that are not available for writing when not being active as discussed in https://github.com/ros-controls/ros2_control/pull/884

christophfroehlich commented 4 months ago

Thanks for analyzing this.

This demo example is an interesting special case since the on_activate() artificially takes a couple of seconds which is usually probably not the case.

Or is it a requirement that on_activate() is required to be real-time-safe and run in one control cycle? Now that I'm aware of the reason I remember I've seen something similar on the UR driver before we restructured things in on_configure and on_activate correctly.

So my main question would be: Is this behavior to be expected and the requirements for the on_activate() aren't fulfilled or do we have to update something in the controller_manager / resource_manager?

I just checked the docs about that, (here or here). It seems that this should be real-time safe:

    on_configure() - reads parameters and configures controller.

    on_activate() - called when controller is activated (started) (real-time)

    on_deactivate() - called when controller is deactivated (stopped) (real-time)

Is there a difference from controllers and hardware components regarding this? We should check if this is really the case in the CM (@saikishor maybe?), clarify that in the docs here for example and fix the examples of the demos.

Since urdf loading and activating the hardware isn't blocking the update() loop and the resource manager calls write() for all command interface independent of their state.

So, one way of "fixing" this short term would be a check in the write() method whether the command is NaN and long term to finally implement command interfaces that are not available for writing when not being active as discussed in ros-controls/ros2_control#884

I'm fine with the fix, and agree for the need for the "final" solution upstream.

fmauch commented 4 months ago

Short term solution now included in #456

saikishor commented 4 months ago

Hello!

I'd rather go with a proper fix, because if this happened in the demos, this might happen in reality, we would need to check why it is happening and find a proper solution for upstream. What do you guys think?

fmauch commented 4 months ago

Yes, I think a proper fix would be better. That's why I didn't mark this issue to be resolved by #456. I just like this issue to not block migrating towards the topic inside the demos.

saikishor commented 4 months ago

After looking at the code, I believe this is happening because we call the write method also for the inactive components https://github.com/ros-controls/ros2_control/blob/master/hardware_interface%2Fsrc%2Fsystem.cpp#L247 and https://github.com/ros-controls/ros2_control/blob/master/hardware_interface%2Fsrc%2Factuator.cpp#L251

The only fix I can think of is how @fmauch has handled it in the hardware itself. I'm wondering why this is not happening with the parameter. I would like to check this part.

If we need to properly fix it, I think we might need a new method called dynamic_configure where all the gpio interfaces go in and then the main hardware command interfaces can go in the write method, in this way we can call this new dynamic_configure method and avoid calling write method in the inactive state.