ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How to include motor wheel encoder ticks to ros_control hardware interface

asked 2021-06-08 15:51:18 -0500

balint.tahi gravatar image


I have an FC-03 motor wheel encoder (infrared speed sensor module with the LM393 comparator) which I would like to use with my differential drive robot.

I can get the ticks from the sensor, the encoder disc has 20 ticks / rotation, which seems to work fine.


1) How to include this into the hardware interface for the ros_control? The encoder don't know the direction of the movement, it can only provide the pulses / ticks, so basically it will be an incremental number.

2) Do I need to calculate the odom, or it will be done automatically by ros_control?

3) Is there any example?

Any help would be greatly appreciated!


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2021-10-07 04:45:06 -0500

fjp gravatar image

updated 2021-10-07 05:10:08 -0500

The open source project I am working on is quite similar to yours and might be helpful: The current robot model is based on Nvidia Jetbot including a 3D printable platform for RPLidar A2. I am using the DG01D-E motors (sparkfun) which include quadrature wheel encoders (542 ticks).

You can find the ROS Control hardware interface here. The "high level hardware interface" from ROS Control is communicating with the "low level base_controller" via custom messages, see also the related msgs package. The low level code, running on the microcontroller and implementing two PID controllers (one for each wheel), is in the diffbot_base/scripts/base_controller package.

Regarding your questions.

1.) You can either switch to quadrature encoders or you can try to incorporate the knowledge of your command that you send to the robot from the diff drive controller. If it is positive cmd_vel (moving forward) you can count up otherwise (negative velocity) count the ticks down. However, I never tried this and switch to the cheap DG01D-E motor/quatrature encoder.

2.) Odom will be calculated by ROS control:

3.) As mentioned, I have never tried it with your motors but you could go with 1.) or switch to REMO robot platform and the DG01D-E motors.

edit flag offensive delete link more

answered 2021-06-09 02:47:17 -0500

Humpelstilzchen gravatar image

updated 2021-06-09 02:48:27 -0500

1) Had the same problem once, my solution was to compute the direction from the given direction. So e.g. if I send the command to the motor to drive counter-clockwise I had it counting the ticks upwards, for clockwise downwards.

2) ros_control can do that with diff_drive_controller

3) This is answered here: ros_control code sample for a diff_drive

edit flag offensive delete link more


Thanks! I am calculating the direction based on the last velocity command to the wheel. Not a perfect solution, but better than nothing.

I used the my_ROS_mobile_robot as an example, it helped me in some steps, but made me some headache in others ... (pos and vel calculation in the read() function). Now it looks ok.

balint.tahi gravatar image balint.tahi  ( 2021-06-14 11:17:08 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2021-06-08 15:51:18 -0500

Seen: 315 times

Last updated: Oct 07 '21