This article is the eighth is a series about building a full-sized, intelligent robot. You can view all of the previous articles here. There is also a YouTube playlist of all of the videos for your enjoyment.

Introduction

Now that we have the mechanical components on the base (or “Navigation Layer”) built it’s time to turn our attention to the motor controller.

In this installment, I will just go over the design criteria for the controller. In the next part of this series, we will look at some of the code used to program it.

Motor Controllers

There are actually two motor controllers, one for each of the DC gear motors used to propel the robot. Each controller is identical and they are completely independent, although they both use the same Emergency Stop input.

Build Real Robot-Episode 8

Each of the devices is controlled using the I2C bus, and they each have their own I2C address.

ATmega328

The controller design will be based upon the ATmega328P, which is the microcontroller chip at the heart of the Arduino Uno, The Arduino Nano, and the Arduino Pro Mini.  The device could be built around any of these controllers, or it could use just an ATMega328P chip with the appropriate support hardware.

I was originally planning to build my controller using two Arduino Nano devices, I thought that having an onboard USB port for each controller might turn out to be a useful feature during development.

However, my plans were somewhat thwarted due to a computer mishap in my workshop! The SSD drive on my workshop Linux computer failed, so I needed to move a Windows notebook in to take over until I could repair the shop computer.

This is not a problem, as the Windows computer has all of the software that I require to develop Arduino software. However, it was lacking the driver for the USB on the Nano clone I was using, and every attempt to install that driver failed.

So I have switched development over to an Arduino Uno so I can carry on. As it uses the same microcontroller chip as the Nano it would be possible to transfer the software to a Nano once I have my workshop Linux box functioning.

I’ve actually been considering just using the ATMega328P chip on its own for the final design, and will likely do just that. However, you could certainly take the code I produce and use an Arduino Nano or Pro Mini if you find it easier to wire.

Design Criteria

Before embarking on any design of considerable size I like to establish some design criteria. These are preliminary design specs and could (and likely will) change as the design progresses.

Here is what my controller(s) will need to do:

  • Provide a PWM output for the Cytron motor driver board. This will control the motor speed.
  • Provide a DIR (direction)signal for the Cytron motor driver board.
  • Have an input for the rotary encoder used on my gear motors.
  • Have an I2C interface so it can be controlled by the Arduino Mega 2560. Each controller will have its own I2C address.
  • Have Emergency Stop inputs.
  • Be capable of accepting commands and reporting status, via the I2C bus.

I also want these controllers to be relatively “universal, so that if you are building a robot that doesn’t use the same motors or motor drivers yo can use the same design.  This means that the controllers need to be able to have some adjustable parameters for things like:

  • Wheel Size
  • Number of steps per rotation from the rotary encoders

This implies that the controller will need some form of non-volatile memory. As the ATmega328P does have a bit of NV memory this might suffice, otherwise, an external EEPROM or similar device will need to be employed.

Controller Hookup

The following diagram illustrates how the controller will fit into the DB1 robot design:

Motor Controller Hookup

Note that although only one controller, motor and motor driver are shown there will actually be two of each. If you are designing a 4-motor robot then, of course, you will need four of each device.

The controller will connect to the Arduino Mega 2560 using I2C. Only SDA, SCL and Ground are required as the controller has its own 5-volt power supply input.

The Emergency Stop input also connects to one of the digital I/O pins on the Arduino Mega 2560. There will be other Emergency Stop inputs as well.  A signal on this line will stop all motor activity and the controller will no longer respond to movement commands until the stop is cleared.

The Driver Output connects to the Cytron MD10C motor driver. It has a PWM, DIR and Ground signal.

The Rotary Encoder input takes the output from the rotary encoder on the DC gear motor. It also supplies 5-volts and ground to the encoder.

Controller Commands

The controller will accept commands on the I2C bus. I have defined some of these commands already, please note that this is just a preliminary list and could be expanded upon as the design progresses.

Motor Controller Commands

Many of the commands have additional parameters. The parameters in brackets are optional, those not encased in brackets are mandatory.

Here is a brief description of each command, along with any parameters it may have.

MovePWM

This moves the motor in a specific direction at a specific PWM speed.  The motor can move for a specified time, or it can move until another command is received.

  • SpeedPWM – The motor speed in PWM, valid values are 1-255
  • Direction – A binary indicator of the motor direction
  • Time – An optional parameter that specifies the time the motor should move. If this is omitted then the motor will move indefinitely, until another command is received to stop it or reset its speed.
  • Accelerate – An optional parameter that specifies if the motor should accelerate to reach the desired speed. If this is omitted the motor will come to the desired speed immediately.
  • Decelerate – An optional parameter that specifies if the motor should decelerate before stopping. If this is omitted then the motor will come to an abrupt stop.  This is only applicable if a Time parameter has also been provided.

MoveRPM

This is almost identical to the previous command, the exception being that the speed will be specified in RPM instead of PWM speed. The input from the rotary encoder will measure and regulate the speed.

The controller will also need to be aware of the maximum RPM that the motor can rotate, any value above this will simply cause the motor to operate at full speed.

MoveDistance

This command will move the robot motor a specified distance. The distance is calculated using the motor RPM readings from the rotary encoder and the stored wheel diameter.

  • DistanceCM – The distance, specified in centimeters.
  • Direction – A binary indicator of the motor direction.
  • SpeedPWM – The motor speed in PWM, valid values are 1-255
  • Accelerate – An optional parameter that specifies if the motor should accelerate to reach the desired speed. If this is omitted the motor will come to the desired speed immediately.
  • Decelerate – An optional parameter that specifies if the motor should decelerate before stopping. If this is omitted then the motor will come to an abrupt stop.

Stop

This command stops the motor. An optional Decelerate parameter can be used, otherwise, the motor will come to an abrupt stop.

ReadRPM

This command will return the current RPM of the motor.

ClearStop

This command will clear the stop executed due to an Emergency Stop.  It is the only command that the controller will respond to after an Emergency Stop has been executed.

GetStatus

This command will return the current status of the motor and motor controller.

Conclusion

It’s been a short article (and video) this week, there is a lot of design work to get done. Next week I will report on the progress I have made on the controller design.

I might even have my Linux box working again! Stay tuned.

Build a Real Robot – Part 8 – Motor Controller 1
Summary
Build a Real Robot - Part 8 - Motor Controller Part 1
Article Name
Build a Real Robot - Part 8 - Motor Controller Part 1
Description
Today I will go over the design criteria for the DB1 motor controller. I will also list the commands that the controller will respond to and show you how it integrates into the DB1 robot design.
Tagged on:
Subscribe
Notify of

1 Comment
Oldest
Newest
Inline Feedbacks
View all comments
david
5 years ago

Bill – you were saying your Chinese clone Arduino nano’s were playing up – I had a similar issue, the IDE would not recognize them, and I just couldn’t upload code to them – I don’t know how I fixed them, but I tried plugging/unplugging, closing the IDE, and also went into device manger, and expanded the ports node, and found the device there, opened it, changed nothing, and then it seemed to “kickstart” them. All three went through the same issue, but once connected each for the first time, I never had issues with that board from then on… Read more »