ros-mobile-robots / diffbot

DiffBot is an autonomous 2wd differential drive robot using ROS Noetic on a Raspberry Pi 4 B. With its SLAMTEC Lidar and the ROS Control hardware interface it's capable of navigating in an environment using the ROS Navigation stack and making use of SLAM algorithms to create maps of unknown environments.
https://ros-mobile-robots.com
BSD 3-Clause "New" or "Revised" License
297 stars 86 forks source link

Motors don't turn #68

Closed Russ76 closed 1 year ago

Russ76 commented 1 year ago

Cannot get the motors to run from the joystick. I checked, and it is publishing data to /diffbot/mobile_base_controller/cmd_vel. Also the /diffbot/wheel_cmd_velocities shows data from the joystick. But /motor_left and /motor_right do not show any data. If I send a command from CLI on that topic then the motors will run. I am running joy and teleop_twist_joy on the laptop. And I ran the launch file on robot called roslaunch diffbot_bringup bringup.launch

I am using the Python Grove motor controller routines. I don't have the Lidar tested yet; was saving that for after the driving was proven. The encoders seem to work correctly. The odom topic stays at zero, even when tracks are spun by hand. I tried using the rqt_robot_steering and it published but no response from program or motors.

I'm using Raspi 4.0 with 4 Gig, Ubuntu 20.04 Mate and Noetic.

What should I try next to fix this robot?

pi@raspberrypi:~$ roswtf
Loaded plugin tf.tfwtf
No package or stack in the current directory
================================================================================
Static checks summary:

No errors or warnings
================================================================================
Beginning tests of your ROS graph. These may take a while...
analyzing graph...
... done analyzing graph
running graph rules...
... done running graph rules
running tf checks, this will take a second...
... tf checks complete

Online checks summary:

Found 1 warning(s).
Warnings are things that may be just fine, but are sometimes at fault

WARNING The following node subscriptions are unconnected:
 * /diffbot/mobile_base_controller/joy_node:
   * /diffbot/mobile_base_controller/joy/set_feedback
 * /motor_driver:
   * /motor_left
   * /motor_right
 * /diffbot/diffbot_base:
   * /diffbot/measured_joint_states

Found 1 error(s).

ERROR The following nodes should be connected but aren't:
 * /diffbot/rosserial_base_controller->/diffbot/diffbot_base (/diffbot/encoder_ticks)
pi@raspberrypi:~$ roslaunch diffbot_bringup bringup.launch
... logging to /home/pi/.ros/log/ac5e6b76-6f8c-11ed-bbf4-d981b5fb025a/roslaunch-raspberrypi-2589.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://raspberrypi:37209/

SUMMARY
========

PARAMETERS
 * /diffbot/debug/base_controller: True
 * /diffbot/debug/hardware_interface: False
 * /diffbot/encoder_resolution: 542
 * /diffbot/gain: 1.0
 * /diffbot/hardware_interface/joints: ['front_left_whee...
 * /diffbot/joint_state_controller/extra_joints: [{'name': 'rear_c...
 * /diffbot/joint_state_controller/publish_rate: 50
 * /diffbot/joint_state_controller/type: joint_state_contr...
 * /diffbot/mobile_base_controller/angular/z/has_acceleration_limits: True
 * /diffbot/mobile_base_controller/angular/z/has_velocity_limits: True
 * /diffbot/mobile_base_controller/angular/z/max_acceleration: 6.0
 * /diffbot/mobile_base_controller/angular/z/max_velocity: 8.0
 * /diffbot/mobile_base_controller/base_frame_id: base_footprint
 * /diffbot/mobile_base_controller/left_wheel: front_left_wheel_...
 * /diffbot/mobile_base_controller/linear/x/has_acceleration_limits: True
 * /diffbot/mobile_base_controller/linear/x/has_velocity_limits: True
 * /diffbot/mobile_base_controller/linear/x/max_acceleration: 0.6
 * /diffbot/mobile_base_controller/linear/x/max_velocity: 0.3
 * /diffbot/mobile_base_controller/pose_covariance_diagonal: [0.001, 0.001, 0....
 * /diffbot/mobile_base_controller/publish_rate: 50
 * /diffbot/mobile_base_controller/right_wheel: front_right_wheel...
 * /diffbot/mobile_base_controller/twist_covariance_diagonal: [0.001, 0.001, 0....
 * /diffbot/mobile_base_controller/type: diff_drive_contro...
 * /diffbot/mobile_base_controller/wheel_radius: 0.0325
 * /diffbot/mobile_base_controller/wheel_separation: 0.145
 * /diffbot/motor_constant: 1.0
 * /diffbot/pwm_limit: 1.0
 * /diffbot/robot_description: <?xml version="1....
 * /diffbot/trim: 0.0
 * /rosdistro: noetic
 * /rosversion: 1.15.14

NODES
  /diffbot/
    controller_spawner (controller_manager/spawner)
    diffbot_base (diffbot_base/diffbot_base)
    robot_state_publisher (robot_state_publisher/robot_state_publisher)
    rosserial_base_controller (rosserial_python/serial_node.py)

ROS_MASTER_URI=http://192.168.1.149:11311

process[diffbot/rosserial_base_controller-1]: started with pid [2599]
process[diffbot/diffbot_base-2]: started with pid [2600]
process[diffbot/controller_spawner-3]: started with pid [2601]
process[diffbot/robot_state_publisher-4]: started with pid [2602]
[ INFO] [1669688872.159374857]: Waiting for model URDF on the ROS param server at location: /diffbot/diffbot/robot_description
[ INFO] [1669688872.458654923]: mobile_base_controller/wheel_radius: 0.0325
[ INFO] [1669688872.459160499]: mobile_base_controller/linear/x/max_velocity: 9.23077
[ INFO] [1669688872.459535815]: encoder_resolution: 542
[ INFO] [1669688872.459898835]: gain: 1
[ INFO] [1669688872.460260207]: trim: 0
[ INFO] [1669688872.460684153]: motor_constant: 1
[ INFO] [1669688872.461061506]: pwm_limit: 1
[ INFO] [1669688872.587988059]: Initializing DiffBot Hardware Interface ...
[ INFO] [1669688872.588351449]: Number of joints: 2
[ INFO] [1669688872.588831932]: pid namespace: pid/left_motor
[ INFO] [1669688872.589166600]: Initialize PID
[ INFO] [1669688872.589441823]: Initializing dynamic reconfigure in namespace /diffbot/pid/left_motor
[ INFO] [1669688873.155046982]: Update PID Gains: F=0.8, P=0.35, I=0.5, D=0.01, out_min=-9.23077, out_max=9.23077
[INFO] [1669688873.232623]: ROS Serial Python Node
[INFO] [1669688873.240327]: Controller Spawner: Waiting for service controller_manager/load_controller
[ INFO] [1669688873.364933075]: Initialized dynamic reconfigure
[ INFO] [1669688873.365176335]: Initialized PID: F=0.8, P=0.35, I=0.5, D=0.01, out_min=-9.23077, out_max=9.23077
[ INFO] [1669688873.365339206]: Update PID output limits: lower=9.23077, upper=-9.23077
[ INFO] [1669688873.365568207]: pid namespace: pid/right_motor
[ INFO] [1669688873.365807170]: Initialize PID
[ INFO] [1669688873.365938301]: Initializing dynamic reconfigure in namespace /diffbot/pid/right_motor
[INFO] [1669688873.642192]: Connecting to /dev/ttyACM0 at 115200 baud
[ INFO] [1669688873.778586700]: Update PID Gains: F=0.8, P=0.35, I=0.5, D=0.01, out_min=-9.23077, out_max=9.23077
[ INFO] [1669688873.833593473]: Initialized dynamic reconfigure
[ INFO] [1669688873.833895419]: Initialized PID: F=0.8, P=0.35, I=0.5, D=0.01, out_min=-9.23077, out_max=9.23077
[ INFO] [1669688873.834055067]: Update PID output limits: lower=9.23077, upper=-9.23077
[ INFO] [1669688873.835291757]: ... Done Initializing DiffBot Hardware Interface
[ INFO] [1669688873.835604351]: Get number of measured joint states publishers
[ INFO] [1669688873.835764814]: Waiting for measured joint states being published...
[INFO] [1669688875.782482]: Requesting topics...
[INFO] [1669688875.836128]: Note: publish buffer size is 512 bytes
[INFO] [1669688875.849856]: Setup publisher on encoder_ticks [diffbot_msgs/Encoders]
[WARN] [1669688876.089304]: Could not process inbound connection: topic types do not match: [diffbot_msgs/EncodersStamped] vs. [diffbot_msgs/Encoders]{'callerid': '/diffbot/diffbot_base', 'md5sum': '162975f999a4d19c3bdc0165594516da', 'tcp_nodelay': '0', 'topic': '/diffbot/encoder_ticks', 'type': 'diffbot_msgs/EncodersStamped'}
[INFO] [1669688876.100320]: Setup publisher on imu/data_raw [sensor_msgs/Imu]
[INFO] [1669688876.137299]: Note: subscribe buffer size is 512 bytes
[INFO] [1669688876.148397]: Setup subscriber on reset [std_msgs/Empty]
[INFO] [1669688876.167773]: Initialize DiffBot Wheel Encoders
[INFO] [1669688876.189302]: Reset both wheel encoders to zero
[ERROR] [1669688883.847392374]: No measured joint states publishers. Timeout reached.
[ INFO] [1669688883.847636764]: Publish /reset to encoders
[INFO] [1669688883.870655]: Reset both wheel encoders to zero
[INFO] [1669688884.094214]: Controller Spawner: Waiting for service controller_manager/switch_controller
[INFO] [1669688884.129574]: Controller Spawner: Waiting for service controller_manager/unload_controller
[INFO] [1669688884.159781]: Loading controller: joint_state_controller
[INFO] [1669688884.318724]: Loading controller: mobile_base_controller
[ INFO] [1669688884.394240071]: Controller state will be published at 50Hz.
[ INFO] [1669688884.405349795]: Wheel separation will be multiplied by 1.
[ INFO] [1669688884.423917861]: Left wheel radius will be multiplied by 1.
[ INFO] [1669688884.424095640]: Right wheel radius will be multiplied by 1.
[ INFO] [1669688884.430501959]: Velocity rolling window size of 10.
[ INFO] [1669688884.436123349]: Velocity commands will be considered old if they are older than 0.5s.
[ INFO] [1669688884.441565201]: Allow mutiple cmd_vel publishers is enabled
[ INFO] [1669688884.456231920]: Base frame_id set to base_footprint
[ INFO] [1669688884.464825191]: Odometry frame_id set to odom
[ INFO] [1669688884.470855472]: Publishing to tf is enabled
[ INFO] [1669688884.662570169]: Odometry params : wheel separation 0.145, left wheel radius 0.0325, right wheel radius 0.0325
[ INFO] [1669688884.689471339]: Adding left wheel with joint name: front_left_wheel_joint and right wheel with joint name: front_right_wheel_joint
[ INFO] [1669688884.848075530]: Dynamic Reconfigure:
DynamicParams:
    Odometry parameters:
        left wheel radius multiplier: 1
        right wheel radius multiplier: 1
        wheel separation multiplier: 1
    Publication parameters:
        Publish executed velocity command: disabled
        Publication rate: 50
        Publish frame odom on tf: enabled
[INFO] [1669688884.918523]: Controller Spawner: Loaded controllers: joint_state_controller, mobile_base_controller
[INFO] [1669688885.018769]: Started controllers: joint_state_controller, mobile_base_controller
pi@raspberrypi:~$ rostopic list -v

Published topics:
 * /rosout [rosgraph_msgs/Log] 7 publishers
 * /rosout_agg [rosgraph_msgs/Log] 1 publisher
 * /diagnostics [diagnostic_msgs/DiagnosticArray] 2 publishers
 * /diffbot/mobile_base_controller/joy [sensor_msgs/Joy] 1 publisher
 * /diffbot/mobile_base_controller/cmd_vel [geometry_msgs/Twist] 1 publisher
 * /tf [tf/tfMessage] 2 publishers
 * /tf_static [tf2_msgs/TFMessage] 1 publisher
 * /diffbot/motor_left [std_msgs/Int32] 1 publisher
 * /diffbot/motor_right [std_msgs/Int32] 1 publisher
 * /diffbot/wheel_cmd_velocities [diffbot_msgs/WheelsCmdStamped] 1 publisher
 * /diffbot/reset [std_msgs/Empty] 1 publisher
 * /diffbot/pid/left_motor/parameter_descriptions [dynamic_reconfigure/ConfigDescription] 1 publisher
 * /diffbot/pid/left_motor/parameter_updates [dynamic_reconfigure/Config] 1 publisher
 * /diffbot/pid/right_motor/parameter_descriptions [dynamic_reconfigure/ConfigDescription] 1 publisher
 * /diffbot/pid/right_motor/parameter_updates [dynamic_reconfigure/Config] 1 publisher
 * /diffbot/encoder_ticks [diffbot_msgs/Encoders] 1 publisher
 * /diffbot/imu/data_raw [sensor_msgs/Imu] 1 publisher
 * /diffbot/joint_states [sensor_msgs/JointState] 1 publisher
 * /diffbot/mobile_base_controller/odom [nav_msgs/Odometry] 1 publisher
 * /diffbot/mobile_base_controller/parameter_descriptions [dynamic_reconfigure/ConfigDescription] 1 publisher
 * /diffbot/mobile_base_controller/parameter_updates [dynamic_reconfigure/Config] 1 publisher

Subscribed topics:
 * /rosout [rosgraph_msgs/Log] 1 subscriber
 * /diffbot/mobile_base_controller/joy/set_feedback [sensor_msgs/JoyFeedbackArray] 1 subscriber
 * /diffbot/mobile_base_controller/joy [sensor_msgs/Joy] 1 subscriber
 * /motor_left [std_msgs/Int32] 1 subscriber
 * /motor_right [std_msgs/Int32] 1 subscriber
 * /diffbot/joint_states [sensor_msgs/JointState] 1 subscriber
 * /diffbot/encoder_ticks [diffbot_msgs/Encoders] 1 subscriber
 * /diffbot/measured_joint_states [sensor_msgs/JointState] 1 subscriber
 * /diffbot/reset [std_msgs/Empty] 1 subscriber
 * /diffbot/mobile_base_controller/cmd_vel [geometry_msgs/Twist] 1 subscriber
fjp commented 1 year ago

The issue seems to be that the grove_motor_driver node is subscribed to motor_left/right without the /diffbot/ prefix.

Just to clarify, the diffbot_base is actually providing two "output" interfaces:

The interface you are currently using with the encoder(-bno).ino script is the high-level PID approach and that one works with the motor commands, publishing setup is here:

https://github.com/ros-mobile-robots/diffbot/blob/e1a4a13089c1fa5341c1814479cac6e99bf677f7/diffbot_base/src/diffbot_hw_interface.cpp#L58-L60

The diffbot_base is launched with the /diffbot namespace

https://github.com/ros-mobile-robots/diffbot/blob/e1a4a13089c1fa5341c1814479cac6e99bf677f7/diffbot_base/launch/diffbot.launch#L13

So the options that should fix the issue you have is to

Note In case you use the encoder-bno.ino you have to tune the high-level PID

Russ76 commented 1 year ago

Franz, you are right, now they run! Forward and backward looks good, however, the turning power is much too low. How do I boost the turning power? The angular boost?

fjp commented 1 year ago

Great, glad that helped! You should be able to tune the high-level PID controller using dynamic reconfigure through rqt. I am guessing the P gain can be turned up a bit.

Russ76 commented 1 year ago

I will work on that, thanks! My Python on laptop is messed up and won't run Rqt tools, but I can do it some other way. I tried boosting the angular from teleop_twist_joy but that didn't work.

Russ76 commented 1 year ago

I was not able to get the angular command to increase without also increasing the linear, and it is enough already. I tried adjusting all the variables. However, even with weak turning, two of us were able to drive the robot around successfully even on carpet. Maybe this will work with move_base and other software.

The encoder topic is a problem. They aren't connected, as can be seen above. The Teensy code has topic "Encoder" and the Raspi code looks for topic "EncoderStamped" These are not the same! Did you get the package to work like this? How?

fjp commented 1 year ago

I was not able to get the angular command to increase without also increasing the linear, and it is enough already. I tried adjusting all the variables. However, even with weak turning, two of us were able to drive the robot around successfully even on carpet. Maybe this will work with move_base and other software.

Have you tried adapting the limits in the diff_drive_controller config? Maybe that could help (see also a full configuration example of all values here).

https://github.com/ros-mobile-robots/diffbot/blob/e1a4a13089c1fa5341c1814479cac6e99bf677f7/diffbot_control/config/diffbot_control.yaml#L45-L57

After that you most likely have to tune the PID gains again.

The encoder topic is a problem. They aren't connected, as can be seen above. The Teensy code has topic "Encoder" and the Raspi code looks for topic "EncoderStamped" These are not the same! Did you get the package to work like this? How?

Right, that is an issue I introduced while switching from the high-level PID to the low-level PID approach. Sorry for that :-/

I'd recommend to update the encoder.ino / encoder-bno.ino to also use the diffbot_msgs::EncodersStamped message as it includes a time stamp, which might be useful.

https://github.com/ros-mobile-robots/diffbot/blob/e1a4a13089c1fa5341c1814479cac6e99bf677f7/diffbot_base/scripts/encoders/encoders-bno/encoders-bno.ino#L16

https://github.com/ros-mobile-robots/diffbot/blob/e1a4a13089c1fa5341c1814479cac6e99bf677f7/diffbot_base/scripts/encoders/encoders-bno/encoders-bno.ino#L57

Russ76 commented 1 year ago

Well, I tried to get that to work, and it compiles, and the topic connects, but there is no ticks data showing in the message!

fjp commented 1 year ago

That is strange. Is the published topic from the mcu containing something when you inspect it, e.g. with something similar to rostopic echo /diffbot/encoder_ticks? If not then there seems to be an issue while creating the message. I am assuming that diffbot_msgs::Encoders is present as an (arudino) library. For PlatformIO I placed the header in diffbot_base/scripts/base_controller/lib/ros_lib/diffbot_msgs. The way that diffbot_msgs::Encoders is used for the new base_controller firmware is shown below:

https://github.com/ros-mobile-robots/diffbot/blob/e1a4a13089c1fa5341c1814479cac6e99bf677f7/diffbot_base/scripts/base_controller/lib/base_controller/base_controller.h#L523-L532

This is slightly different to how it is currently done in the encoders-bno.ino:

https://github.com/ros-mobile-robots/diffbot/blob/e1a4a13089c1fa5341c1814479cac6e99bf677f7/diffbot_base/scripts/encoders/encoders-bno/encoders-bno.ino#L95-L96

However, because it compiles I am guessing there is no issue here.

What I would also try to verify is that rosmsg show diffbot_msgs/Encoders will correctly show the message. ^msg

If all this doesn't help, I will try to find time near the end of the month to test this setup myself.

Russ76 commented 1 year ago

Yes, that block of code what what I needed. Now we got it working: encoders stamped has time, sequence, and ticks data! I had to add "diffbot" to the "encoder_diffbot.h" reference in the #include list, for the Arduino IDE to find the header file. Now the only error in starting the main nodes on Raspi is complaining about no "joint states publishers", which I suppose is not important. Thanks, Franz!

Russ76 commented 1 year ago

Let the robots roam!