Ask Your Question
0

Arduino /cmd_vel and /odom with Pololu motors w/ encoder

asked 2017-01-31 15:59:42 -0500

JamesWell gravatar image

Hi guys,

I have been struggling with my robot for 3-4 days now. I want to publish to the /cmd_vel topic and then to the /odom topic using the Arduino MEGA connected to 4 Pololu motors with encoders. I have installed rosserial and gone through the tutorials, I have tried modifying ros_arduino_bridge to fit my hardware with no success, so please do not suggest these as solutions :) I have also tried getting the ticks from the motors with a mild success, but nothing useful. I have tested all motors by sending a variety of PWM signals from the MEGA and they seem to function just fine.

Is it even possible with the motor controllers I am using? I am honestly hoping someone can direct me in the right direction. Everything online is just people linking to the rosserial tutorial page..

My robot is a 4WD platform with

A schematic showing the pinouts of the DC Motor Driver Carrier from the Pololu page MAX14870 Motor Driver

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-02-01 02:54:36 -0500

Humpelstilzchen gravatar image

updated 2017-02-01 03:01:15 -0500

Sorry, have to recommend rosserial. I recommend we focus on the problem you have with it. I use a variant of your motor in a 4wd wild thumper, so short answer: Yes it is possible.

I'm not yet sure where exactly your problem is, seems to me that there are multiple, we should identify these and solve each in its own question. You should start with sending cmd_vel to your arduino, send raw pwm values first instead of m/s, e.g.

rostopic pub -1 cmd_vel geometry_msgs/Twist '[255, 0, 0]' '[0, 0, 0.0]'

for max speed forward. Write this value in the OCR register of your arduino.

To give a short answer for reading the encoders: They use gray code, so use something like this code to decode it:

  static int8_t last;
  int8_t new, diff;
  unsigned char status = (PINA >> 4) & 0x3;

  new = 0;
  if(status & 0x1)
        new = 3;
  if(status & 0x2)
        new ^= 1;          // convert gray to binary
  diff = last - new;        // difference last - new
  if( diff & 1 ){        // bit 0 = value (1)
        last = new;          // store new as next last
        enc_delta += (diff & 2) - 1;    // bit 1 = direction (+/-)
  }
edit flag offensive delete link more

Comments

Haha recommending rosserial is totally fine, I just don't want to be linked to the tutorials. I will write a node on the Arduino that will listen to the /cmd_vel topic and write the PWM value to the motors. I hope you can give feedback after I post the code as an edit in the original question.

JamesWell gravatar imageJamesWell ( 2017-02-01 07:32:03 -0500 )edit

Here is an example I did a while ago

tonybaltovski gravatar imagetonybaltovski ( 2017-02-06 21:29:53 -0500 )edit
-1

answered 2017-01-31 22:34:47 -0500

hmchung gravatar image

Can you post a snippet of your Arduino code here? Besides, I am not exactly sure about ros_arduino_bridge, but why not just use Arduino servo_lib for PWM? It works for my Arduino Mega driving a Sabertooth 2X25?

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2017-01-31 15:59:42 -0500

Seen: 1,144 times

Last updated: Feb 01 '17