ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Can anyone tell me how to control the DC motors using ROS and Arduino

asked 2017-02-12 00:23:47 -0600

antonchi gravatar image

updated 2017-02-13 11:38:12 -0600

i am fairly new to ROS. I'm trying to control 2 DC motors through ROS and Arduino. I've been using rosserial package and also i've tried ros_arduino_bridge.

edit retag flag offensive close merge delete


The title is fort a short 'title', could you please try to edit your question into a title (one line) and a question (as long as needed?)

NEngelhard gravatar image NEngelhard  ( 2017-02-12 15:18:50 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2017-02-12 13:15:21 -0600

Mark Rose gravatar image

On the smaller Arduinos with only 2kb RAM I've had trouble using rosserial because of the amount of RAM consumed, so I've abandoned that for ros_arduino_bridge. If you are using a motor driver not already supported by ros_arduino_bridge, you'll have to modify the code in a couple of places.

First, in ROSArduinoBridge.ino, look at this code (lines 48-64):

//#define USE_BASE      // Enable the base controller code
#undef USE_BASE     // Disable the base controller code

/* Define the motor controller and encoder library you are using */
#ifdef USE_BASE
   /* The Pololu VNH5019 dual motor driver shield */
   #define POLOLU_VNH5019

   /* The Pololu MC33926 dual motor driver shield */
   //#define POLOLU_MC33926

   /* The RoboGaia encoder shield */
   #define ROBOGAIA

   /* Encoders directly attached to Arduino board */

You need to uncomment the definition of USE_BASE, comment out ROBOGAIA, and then add your own define for your motor controller, say #define RKI1340_MOTOR_CONTROLLER.

Then, in motor_driver.ino, you'll need to add code to support that motor driver. The bottom of that file looks like this:

  #error A motor driver must be selected!

You'll need to add an #elif before the #else for RKI1340_MOTOR_CONTROLLER, and add a definition of void setMotorSpeeds(int leftSpeed, int rightSpeed).

There are other changes required to support encoders different from the ones already coded. You might compare with the changes Marco Walther made to support the Pololu A-Star board with onboard motor driver. (I've contributed to his mods.)

edit flag offensive delete link more

answered 2017-02-12 04:47:22 -0600

duck-development gravatar image

how do you like to controll the Motors? the Turnspeed? or the Postion? or only on and off?

Greet Anton

edit flag offensive delete link more


first i want to turn it on and off the apply speed control also.

antonchi gravatar image antonchi  ( 2017-02-12 04:53:52 -0600 )edit

may this help the other questen is with kind of motor driver Chip ddo you have?

duck-development gravatar image duck-development  ( 2017-02-12 05:05:01 -0600 )edit

i'm using rki 1340 dc motor driver..and thanks for the link

antonchi gravatar image antonchi  ( 2017-02-12 05:24:55 -0600 )edit

Question Tools


Asked: 2017-02-12 00:23:47 -0600

Seen: 2,723 times

Last updated: Feb 13 '17