Robot Chassis

The Magician Chassis from Sparkfun is a very good option for a beginner robot.  It’s cheap but not cheapo.  $15 is such a good price, i want to assemble an army of these (Not sure why it’s $28 everywhere else).  Even includes a screwdriver.
It was dirt simple to assemble, took all of 15 minutes.  The instructions are a little vague, but just remember that the wheel attaches to the side of the motor with the little protruding stub.  You’ll see what I mean when you first try to orient the motors.
The next day I hooked up a couple of components to the top.  A Sparkfun Arduino Pro 5V and a Polulu TB6612FNG Dual Motor Driver.  After soldering some headers, the Pro easily attaches using some extra hardware that comes with the Magician.  For the Motor Driver, I stuck a mini breadboard to a piece of cardboard and screwed that on with more Magician hardware.
When driving DC motors, the standard practice seems to be using separate power sources for the Motors and the Arduino (and everything else).  On an earlier robot  learned this the hard way when I started seeing very strange sensor readings  when a motor kicked in.  I used the 4 AA pack (which came with the Magician) for VMOT, and USB for the Arduino for now.
Hook up the Motor Driver as follows:
  • GND’s to a common ground (Arduino’s GND and GND from motor battery).
  • VCC to Arduino 5V
  • STBY to Arduino 5V (unless you want to control this in code)
  • VMOT to motor battery pack
  • AO1 and AO2 to one motor
  • BO1 and BO2 to other motor
  • the rest to your Arduino as the code suggests
Polulu TB6612FNG Dual Motor Driver
Here’s the code, which I found on the Arduino forum here (great stuff cause it’s concise), and then modified and made into a C++ class called MotorDriver.  Check Github for the latest version of the code.
#include “MotorDriver.h”
#define out_A_PWM 11
#define out_A_IN1 12
#define out_A_IN2 13
#define out_B_PWM 10
#define out_B_IN1 9
#define out_B_IN2 8
MotorDriver leftMotor = MotorDriver(12, 13, 11);
MotorDriver rightMotor = MotorDriver(9, 8, 10);
void setup()
{
  Serial.begin(9600);
  Serial.println(“begin”);
}
void loop()
{
  for (int i=-20; i<20; i++) {
    leftMotor.setSpeed(i);
    rightMotor.setSpeed(i);
    delay(20);
  }
  leftMotor.setSpeed(0);
  rightMotor.setSpeed(0);
  delay(1000);
}

MotorDriver.h

#ifndef MotorDriver_h
#define MotorDriver_h
#include “Arduino.h”
class MotorDriver
{
public:
  MotorDriver(int pinFwd,int pinRev,int pinPwm);
  void setSpeed(int speed);
  int getSpeed();
private:
  int _pinFwd;
  int _pinRev;
  int _pinPwm;
  int _speed;
  int _pwm;
};
#endif

MotorControl.cpp

#include “Arduino.h”
#include “MotorDriver.h”
MotorDriver::MotorDriver(int pinFwd,int pinRev, int pinPwm)
{
  pinMode(pinFwd, OUTPUT);
  pinMode(pinRev, OUTPUT);
  pinMode(pinPwm, OUTPUT);
  _pinFwd = pinFwd;
  _pinRev = pinRev;
  _pinPwm = pinPwm;
}
void MotorDriver::setSpeed(int speed)
{
  _speed = constrain(speed, 100, 100);
  _pwm = map(abs(_speed), 0, 100, 50, 255);
  if (_speed > 0)
  {
    digitalWrite(_pinFwd, HIGH );
    digitalWrite(_pinRev, LOW);
  }
  else if (_speed == 0)
  {
    digitalWrite(_pinFwd, HIGH);
    digitalWrite(_pinRev, HIGH);
  }
  else if (_speed < 0)
  {
    digitalWrite(_pinFwd, LOW);
    digitalWrite(_pinRev, HIGH);
  }
  analogWrite (_pinPwm, _pwm);
}
int MotorDriver::getSpeed()
{
  return _speed;
}
I’ve realized that the Arduino Pro is not going to have enough pins.  Just this 1 component takes up almost half it’s digital pins.  I could try a 8-bit shift register, but it will take up precious space and I’ll have to keep adding more. Instead, I decided to swap out the Pro for a Mega.
Another modification, I replaced the screws holding the battery pack with one of my favorite prototyping tools – velcro.  This will make it easier to replace batteries.

One comment

  1. Pingback: Solar Tracker on wheels – here we go | Jamie Gilmartin

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>