Both it is even a problem when I just use the ROS-Arduino-Bridge.ino and miniterm. When I type o 255 255 or negative it works fine. When I type o 255 -255 the motors don’t turn at all.
After fooling around with it quite a bit, I do see that it is the PID values, possible something else as well. I could sit and fool with the values, but the behavior is still strange (the motors start slow and rev up to the required speed, but overshoot it and reverse directions). Open loop control works great. I would love to rewrite this thing at some point. I’m fuzzy on a few things I need to research first, like how to translate input tick count to speed to PWM. I’m also not sure what “Ko” is in the PID code. Josh, what are the RPM speeds of your motors? I think mine are about 250 or so, maybe too much for this application (if that even makes a difference). Anyway, I’ll keep fussing with it.
[INFO] [launch]: All log files can be found below /home/cliff/.ros/log/2023-06-11-09-19-26-129315-cliff-Legion-4342
[INFO] [launch]: Default logging verbosity is set to INFO
Task exception was never retrieved
future: <Task finished name='Task-2' coro=<LaunchService._process_one_event() done, defined at /opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py:226> exception=PackageNotFoundError("package 'twist_mux' not found, searching: ['/home/cliff/dev_ws/install/serial_motor_demo', '/home/cliff/dev_ws/install/serial_motor_demo_msgs', '/home/cliff/dev_ws/install/diffdrive_arduino', '/home/cliff/dev_ws/install/serial', '/home/cliff/dev_ws/install/articubot_one', '/opt/ros/foxy']")>
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-packages/ament_index_python/packages.py", line 50, in get_package_prefix
content, package_prefix = get_resource('packages', package_name)
File "/opt/ros/foxy/lib/python3.8/site-packages/ament_index_python/resources.py", line 48, in get_resource
raise LookupError(
LookupError: Could not find the resource 'twist_mux' of type 'packages'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 228, in _process_one_event
await self.__process_event(next_event)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 248, in __process_event
visit_all_entities_and_collect_futures(entity, self.__context))
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
[Previous line repeated 1 more time]
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 38, in visit_all_entities_and_collect_futures
sub_entities = entity.visit(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/action.py", line 108, in visit
return self.execute(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch_ros/actions/node.py", line 453, in execute
ret = super().execute(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/actions/execute_process.py", line 823, in execute
self.__expand_substitutions(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/actions/execute_process.py", line 668, in __expand_substitutions
cmd = [perform_substitutions(context, x) for x in self.__cmd]
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/actions/execute_process.py", line 668, in <listcomp>
cmd = [perform_substitutions(context, x) for x in self.__cmd]
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/perform_substitutions_impl.py", line 26, in perform_substitutions
return ''.join([context.perform_substitution(sub) for sub in subs])
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/perform_substitutions_impl.py", line 26, in <listcomp>
return ''.join([context.perform_substitution(sub) for sub in subs])
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_context.py", line 232, in perform_substitution
return substitution.perform(self)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch_ros/substitutions/executable_in_package.py", line 76, in perform
package_prefix = super().perform(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch_ros/substitutions/find_package.py", line 79, in perform
result = self.find(package)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch_ros/substitutions/find_package.py", line 96, in find
return get_package_prefix(package_name)
File "/opt/ros/foxy/lib/python3.8/site-packages/ament_index_python/packages.py", line 52, in get_package_prefix
raise PackageNotFoundError(
ament_index_python.packages.PackageNotFoundError: "package 'twist_mux' not found, searching: ['/home/cliff/dev_ws/install/serial_motor_demo', '/home/cliff/dev_ws/install/serial_motor_demo_msgs', '/home/cliff/dev_ws/install/diffdrive_arduino', '/home/cliff/dev_ws/install/serial', '/home/cliff/dev_ws/install/articubot_one', '/opt/ros/foxy']"
Task exception was never retrieved
future: <Task finished name='Task-8' coro=<LaunchService._process_one_event() done, defined at /opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py:226> exception=RuntimeError('Signal event received before subprocess transport available.')>
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 228, in _process_one_event
await self.__process_event(next_event)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 248, in __process_event
visit_all_entities_and_collect_futures(entity, self.__context))
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 38, in visit_all_entities_and_collect_futures
sub_entities = entity.visit(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/action.py", line 108, in visit
return self.execute(context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/actions/opaque_function.py", line 75, in execute
return self.__function(context, *self.__args, **self.__kwargs)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/actions/execute_process.py", line 443, in __on_signal_process_event
raise RuntimeError('Signal event received before subprocess transport available.')
RuntimeError: Signal event received before subprocess transport available.
[INFO] [robot_state_publisher-1]: process started with pid [4345]
[robot_state_publisher-1] Parsing robot urdf xml string.
[robot_state_publisher-1] Link base_footprint had 0 children
[robot_state_publisher-1] Link chassis had 4 children
[robot_state_publisher-1] Link camera_link had 1 children
[robot_state_publisher-1] Link camera_link_optical had 0 children
[robot_state_publisher-1] Link caster_wheel had 0 children
[robot_state_publisher-1] Link face_link had 0 children
[robot_state_publisher-1] Link laser_frame had 0 children
[robot_state_publisher-1] Link left_wheel had 0 children
[robot_state_publisher-1] Link right_wheel had 0 children
[robot_state_publisher-1] [INFO] [1686455366.472416353] [robot_state_publisher]: got segment base_footprint
[robot_state_publisher-1] [INFO] [1686455366.472564150] [robot_state_publisher]: got segment base_link
[robot_state_publisher-1] [INFO] [1686455366.472588526] [robot_state_publisher]: got segment camera_link
[robot_state_publisher-1] [INFO] [1686455366.472606757] [robot_state_publisher]: got segment camera_link_optical
[robot_state_publisher-1] [INFO] [1686455366.472624637] [robot_state_publisher]: got segment caster_wheel
[robot_state_publisher-1] [INFO] [1686455366.472642309] [robot_state_publisher]: got segment chassis
[robot_state_publisher-1] [INFO] [1686455366.472659212] [robot_state_publisher]: got segment face_link
[robot_state_publisher-1] [INFO] [1686455366.472675486] [robot_state_publisher]: got segment laser_frame
[robot_state_publisher-1] [INFO] [1686455366.472692599] [robot_state_publisher]: got segment left_wheel
[robot_state_publisher-1] [INFO] [1686455366.472709362] [robot_state_publisher]: got segment right_wheel
[ERROR] [robot_state_publisher-1]: process[robot_state_publisher-1] failed to terminate '5' seconds after receiving 'SIGINT', escalating to 'SIGTERM'
[INFO] [robot_state_publisher-1]: sending signal 'SIGTERM' to process[robot_state_publisher-1]
[ERROR] [robot_state_publisher-1]: process has died [pid 4345, exit code -15, cmd '/opt/ros/foxy/lib/robot_state_publisher/robot_state_publisher --ros-args --params-file /tmp/launch_params_zw350_hn'].
Cant find whats actually going wrong, feels like its ros not building properly
Very odd, I’m suspicious of maybe a wiring issue with the motors/driver/arduino?
Do
o 255 0
o -255 0
o 0 255
-
o 0 -255
All work as expected?
Interesting, I have had similar problems with other motors. I still got them to work but they were a bit more sensitive to the PID settings.
Yeah me too. I didn’t write the Arduino code (just made some small mods) and would like to do it from scratch.
I also found this confusing. I believe this and also the reason everything is done in “encoder ticks per loop” is to avoid doing floating point arithmetic in the Arduino. So the Ko
just scales things up. E.g. if we want Kp = 0.5
(and Ko = 1
) we can’t do that, so instead we set Kp = 5
and Ko = 10
.
It’s a little while since I dug into it though so that might be not quite right.
Pretty sure they are 110RPM. 250 is pretty fast, especially if your encoders aren’t super fast. E.g. your requests might boil down to the difference between a few integers in counts per loop and the PID will be jumping rapidly between them.
Make sure when posting code blocks (I have edited yours) you put backticks (the ~
key without shift) around it to make it easier to read, like this:
```
My code here
```
Your issue here is you don’t have twist_mux
installed (sudo apt install ros-foxy-twist-mux
).
This error should be clearer, except I have not explicitly made twist_mux
a dependency of articubot_one
so it tries to run without checking that it exists, and you get that very messy error.
I found the problem it seems to be some internal problem with the Arduino uno, it works fine on the nano.
I think I will take a stab at writing new Arduino code. Josh, if you were personally to do this would you continue using Serial or would you go for something like MicroROS (keeping in mind one could no longer use the Nano if that were the case)? I use the Teensy quite a bit so perhaps I’ll try something for both (I’d like to learn MicroROS myself). This is out of scope so I’ll start a new topic for discussion later.
Hey Josh, wanted to let you know I purchased a couple of 100RPM motors and that seemed to do the trick. Everything is now running smoothly. Those other motors were probably just too fast for the PID/encoders to handle.
BTW, is it possible to get permissions to create new topics? It doesn’t look like I have (unless I’m not supposed to).
Nice, I’m very glad that sorted it (it’s always disappointing when you sink money into extra hardware and it doesn’t help!)
Yeah, creating new topics is restricted to paid members over at Patreon however I have tried to make the bottom tier very affordable. This also gets you access to the Discord server and helps support the channel.
I haven’t got Patreon and Discourse synced up yet though and have to update user permissions manually, so don’t be afraid to remind me if needed
Sounds fair. I have now joined Patreon.
Maybe the answer to this is in my face and I don’t see it, but I’m going to ask anyway. I’ve created a launch file for the physical robot after success with all the simulations. It runs and teleoperates just fine. When I open RVIZ, however, I noticed that the model’s wheels are screwed up because the wheel transforms can’t be resolved (we used to cheat and run joint_state_publisher_gui to resolve this). This does not happen when running RVIZ with the Gazebo simulation. Is this behavior correct? Is there something I can do (besides running the JSP gui) to fix this issue?
Edit: I figured it out. I had the wheels parented to the base_link. When I changed the parent to the chassis the joints are now recognized. I’m leaving this post for anyone who might have the same issue with their design.
Im having issues where my Twist msgs from teleop is having the following problems:
-not updating my robot position correctly
-unstable, moves slow sometimes and very fast other times
-when moving straight, it never updates the position except for a fixed 0.1 meter even if i keep going straight for more.
-after a few turns, it gets stuck and i cant use teleop anymore until i manually nudge the wheel.
note: the updates and revolutions are exact when im turning the wheels using my hands. the problems start when i use teleop.
and i am also confused about where to change my PID values because there are ones in the diffdrive_arduino.cpp (arduino_.setPidValues(30,20,0,100)) and ones in the arduino file, which ones should i be changing?
All the code works up until the gazebo simulation and mapping.
im using ros humble and have updates my files appropriately using your most recent video.
Any help as to where to start fixing the issue would be very very appreciateddd
FIXED!! = The issue was very very lame, even though i spent days changing the code assuming its the cause. The issue was wiring and power! the encoders and logic were getting the power from the controller because i forgot to provide it power and ground it from and to the arduino, and it caused it to keep shutting off and on and acting crazy.
Glad you got it sorted.
I was going to suggest checking that you were running the joint_state_broadcaster
which is responsible for publishing the joint states when using ros2_control, which are then read by robot_state_publisher
to broadcast the transforms. Including that as a note in case someone has a similar (but different!) issue to what you did
Ahh yep those kiind of wiring issues can be a real pain and cause very sporadic behaviour (or kill your encoders as some people have found ) I’m glad it’s fixed for you though.
Re the PID values, from memory on the Foxy version you should change the hardcoded values in the cpp, and on Humble you can set them as a parameter. If you change them on the Arduino I think that will be changing the default value which is the case if diffdrive_arduino
never sends an override.
(I think that’s all correct, I haven’t looked at it for a little while)
Hi @JoshNewans
i installed RO2 Humble. I am getting this error when trying to build diffdrive_arduino with colcon build. Can you help me?
Starting >>> serial
Starting >>> articubot_one
Finished <<< articubot_one [0.88s]
Finished <<< serial [1.39s]
Starting >>> diffdrive_arduino
— stderr: diffdrive_arduino
In file included from /home/robot/rasp_ws/src/diffdrive_arduino/src/fake_robot.cpp:1:
/home/robot/rasp_ws/src/diffdrive_arduino/include/diffdrive_arduino/fake_robot.h:7:10: fatal error: hardware_interface/base_interface.hpp: No such file or directory
7 | #include “hardware_interface/base_interface.hpp”
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [CMakeFiles/fake_robot.dir/build.make:76: CMakeFiles/fake_robot.dir/src/fake_robot.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:165: CMakeFiles/fake_robot.dir/all] Error 2
gmake[1]: *** Waiting for unfinished jobs…
In file included from /home/robot/rasp_ws/src/diffdrive_arduino/src/diffdrive_arduino.cpp:1:
/home/robot/rasp_ws/src/diffdrive_arduino/include/diffdrive_arduino/diffdrive_arduino.h:7:10: fatal error: hardware_interface/base_interface.hpp: No such file or directory
7 | #include “hardware_interface/base_interface.hpp”
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
gmake[2]: *** [CMakeFiles/diffdrive_arduino.dir/build.make:76: CMakeFiles/diffdrive_arduino.dir/src/diffdrive_arduino.cpp.o] Error 1
gmake[2]: *** Waiting for unfinished jobs…
gmake[1]: *** [CMakeFiles/Makefile2:139: CMakeFiles/diffdrive_arduino.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
Failed <<< diffdrive_arduino [23.8s, exited with code 2]
Summary: 2 packages finished [26.4s]
1 package failed: diffdrive_arduino
1 package had stderr output: diffdrive_arduino
@JoshNewans . I installed diffdrive_arduino of GitHub - Buzzology/diffdrive_arduino: A simple ROS Control Hardware Interface for differential drive control of robot whose motors are connected via an Arduino (or similar microcontroller).. I can run teleop_twist_keyboard
to drive my around. My motors can work. But when I open rviz2 for tracking, when I press some letters ‘i’ and ‘m’ on the keyboard, the robot runs circle around base_link , doesn’t go straight ( forward and backward). I installed ROS2 HUMBLE. Can you help me, plz?
I’m a bit confuse
When using SIM mode
The file ros2_control.xacro define the differential wheel plug in for gazebo through the yaml files
the file gazebo_control.xacro define diff_drive plugin
isn’t redundant? what do I miss with my understanding?
@JoshNewans Hi! Firstly, amazing tutorial which clearly explains how to interface to a real robot. However, I am facing an issue when launching the real robot. The error is as below
[ros2_control_node-2] [INFO] [1694504172.944274701] [resource_manager]: Loading hardware ‘RealRobot’
[ros2_control_node-2] [INFO] [1694504172.946497851] [resource_manager]: Initialize hardware ‘RealRobot’
[ros2_control_node-2] terminate called after throwing an instance of ‘std::invalid_argument’
I figured the error occurs in the ros2_control/hardware_interface/resource_manager.cpp file. The specific line where the error occurs I think is this:
const rclcpp_lifecycle::State new_state = hardware.initialize(hardware_info);
I’m using an Arduino Mega instead. I have tested my bot with the ros_arduino_bridge package and it works fine when running miniterm. Is there a way to resolve this? Thank you!
Hi, thank you for all your work on those videos, which I love learning from.
I’m trying to create my own robot under ROS 2 Humble. It seems that I have successfully managed to use Nav2. However, I don’t understand how ROS 2 Control is used by Nav2. What does Nav2 Controller Server and Planner use to work? And finally, the most important question: Is there any controller from ROS 2 Control for controlling a 3-wheel omnidirectional robot?