Tag Archives: Arduino

BalanceBot – Motor Controller

I used a Pololu Dual VNH5019 Motor Driver Shield for Arduino as the motor controller. It has two VNH5019 MOSFET H-Bridge brushed DC motor controller IC’s mounted on an Arduino Shield. The motor controller can drive up to 12A continuous current per motor, 30A maximum. The motors are controlled via a PWM signal generated by the Arduino, and sent to the controller ICs, which in turn drive the MOFETS to control the speed and direction of the motors. The controllers can work up to 24v, but we are using 12v motors with a stall current of 5A, so the controller shouldn’t even break in to a sweat.

VNH5019 Shield

VNH5019 Shield

The shield comes with an Arduino library, making the programming simple. There is a function setSpeeds (int m1Speed, int m2Speed); which takes an integer speed for each motor, from +400 (full speed ahead) to -400 (full speed reverse), with 0 being stop.

There are quite a few other functions on the controller including braking and current monitoring, but I doubt we’ll use them in this project.

The only down side of using this particular shield is it takes lots of IO pins. There is a PWM signal for each motor, direction indicators, the current sensing output, enable lines and error signals. All in all the shield uses 10 IO pins of the 20 pins in total. This isn’t a show stopper, we still have enough left over (just) but there is one problem.

The shield uses pin 12 for the M2EN signal. We need pin 12 for SPI. The SPI signals are pins 11,12 & 13. There is the feature on the board to cut the track for control signals so you can move them. I had to cut the track and solder a thin wire from the jumper to the new pin. I picked pin A2 as we don’t need that and I updated the library with the new pin details.

VNH5019 Shield Schematic
VNH5019 Shield Schematic

In the library source code (arduino-1.0.x\libraries\DualVNH5019MotorShield\DualVNH5019MotorShield.cpp) just chnage the default constructor code to use the new pin :

DualVNH5019MotorShield::DualVNH5019MotorShield()
{
  //Pin map
  _INA1 = 2;
  _INB1 = 4;
  _EN1DIAG1 = 6;
  _CS1 = A0;
  _INA2 = 7;
  _INB2 = 8;
  _EN2DIAG2 = A2; // = 12;
  _CS2 = A1;
}

The controller worked fine first time. It’s powered directly from the battery. There is a jumper on the shield to power the Arduino from an on board regulator, so the motor battery powers the Arduino too. The library makes programming easy, and the motors are fast and responsive. The only thing you need to remember to do is wire one of the motors to the shield in revere. For the robot to travel forward with both motors at “+400”, one motor needs to be wired in reverse to the other as they are on either sides of the robot, clockwise is forwards for one motor, and anti-clockwise is forwards for the other. This doesn’t affect the motors at all, and it makes the code slightly easier to read.

BalanceBot – Components

The main components for BalanceBot are :

  • Two geared motors with quadrature encoders
  • A Motor controller
  • An Arduino Uno for a brain
  • A 9 DoF sensor stick to provide the IMU
  • A custom board to interface the quadrature encoder counters
  • A 12v rechargeable battery.

The motors are Pololu metal gear motors and Pololu have a nice motor controller shield that matches the requirements of the motors. The motor shield has a built in regulator to power the 5v Arduino from the motor power coming from the battery, so I could power everything from a single 12v rechargeable battery. A perfect fit. Pololu also sell mounting brackets for the motors and wheels. So that’s the mechanics covered in a single order.

The brain is an Arduino Duemilanove with an ATmega328p microcontroller but this is essentially the same as the newer Arduino Uno.

I read a lot about various IMUs and considered using an all-in-one unit with a built in CPU and code. I have an UM6-LT Orientation Sensor from CH Robotics for a different project and they are easy to interface to and do all the Kalman filtering for you on board, but I needed it for the other project, and they’re expensive, so I decided to use a raw 9 DoF sensor board and do the data fusion and filtering in code on the Arduino.

These 9 DoF boards are cool from FreeIMU but at the time I was researching this, there weren’t many online stores selling them, so I decided to use a SparkFun Sensor Stick. The FreeIMU site provides a GNU GPL license library for Arduino which supports not only the FreeIMU boards but also the SparkFun boards and the DIYDrones ArduIMU.

I was hoping to find an existing 3rd party Quadrature decoder Arduino shield, but I couldn’t one. I found some quadrature counter ICs LS7366 with an SPI interface. These count the quadrature pulses from the motors so the Arduino can read the count totals using SPI. I prototyped a shield for them using wire wrap and then manufactured a custom PCB using BatchPCB.com.

The frame is made from MicroRax which gave me the flexibility to build the frame to any dimensions to mount the motors and controller boards. Its strong and easy to construct and it also meant I could change my mind 🙂

The other components are from Maplins. A standard sealed 12v battery and some switches.

Finally, to make it look more professional I have some custom acrylic sheets laser cut for the base and top. These made mounting the PCBs and switches easier and made it look less Heath Robinson.

A sad note, Fabio Varesano (http://www.varesano.net/) the 28 year old student behind FreeIMU died suddenly over Christmas last year. Such a terrible shame for such a talented young man. He invested so much effort designing and developing FreeIMU and provided lots of support and encouragement to the robotics community. The information from his site was part of my research for this project and I’m sure he will be missed by the community. My heartfelt sympathy goes to his family and friends.

BalanceBot – My First Post

The plan for BalanceBot is a two wheeled self-balancing robot. I’ve always wanted to build one since school, but never got around to it. The robot consists of some distinct building blocks and could be described as just a system integration project :-). However the project gave me the opportunity and motivation to play with a number of technologies I’ve not used in a while. Specifically, I wanted to understand IMUs & Kalman Filters and PID Controllers. The maths can be very complex, but I like a challenge. I also discovered Quaternions, while researching IMU’s, which I never even knew existed. Don’t you love learning new stuff !? 🙂

BalanceBot

BalanceBot

I’ve never had a custom PCB made by a fab house before, I used to etch my own years ago but the technology has become more accessible since then, the costs are tiny and there’s great free software. I’ve also never had anything laser cut and this was a great opportunity to learn about the tools and process. So all in all, a project I’ve always wanted to build, with lots of cool new tools to play with and learn. Last but by no means least, I’ve never blogged before. I don’t even tweet. So, I thought I’d start a blog about the BalanceBot build and then continue it for my other tinkering projects.

Quite a lot of goals in a single project. The first challenge is time. I don’t have much spare time, so what should have taken me a couple of weeks, took months, with just a few hours each weekend and nothing in the middle. The blog plan didn’t work either, as instead of blogging as I went along, I kind of saved everything up until the end.

But here goes…