Build the Devastator Robot and Learn About Sensors, MCUs, Software, and Motor Control While Having Fun

By Paul Pickering

Contributed By Digi-Key's North American Editors

Building a multifunction robot from a kit is a great way to get started as a Maker, as it provides an opportunity to learn about many related fields: microcontrollers, sensors, motors, software development, and more. Plus, there’s a large selection of robot kits, add-ons, and online help for beginners and experienced Makers alike.

This article discusses some of the practical steps, issues, and possible upgrades to consider when making a robot based on the DF Robot Devastator tank platform (Figure 1).

Image of DFRobot Devastator

Figure 1: The DFRobot Devastator is a versatile platform that can help designers and Makers learn a wide range of electronic and software skills. (Image source: DFRobot)

Why the Devastator? It’s solid and durable, with aluminum construction and two metal gear brushed DC motors. It can handle a load of up to 3 kg, has multiple mounting holes for sensors, servos, robot arms, and other accessories, and it’s compatible with all the popular Maker-friendly microcontroller boards.

Building a complete robot system

The robot comes with the chassis, wheels, treads, and two motors, but leaves the choice of other components up to the designer. A complete system requires a microcontroller board, a motor driver board, and a means to input commands. Optional add-ons can include such items as a robot arm, a video camera, or a collision avoidance system to provide a degree of autonomous operation.

Choosing a microcontroller platform

The Devastator robot is compatible with several popular microcontroller platforms. The Arduino open-source development platform began in Italy in 2003 and is widely used by both novice and professional designers. The Arduino Uno (Figure 2) uses the Microchip Technology (formerly Atmel) ATmega328P 8-bit RISC microcontroller.

Other standard features include a USB port controlled by a preprogrammed ATmega16U2 microcontroller, digital inputs and outputs, an analog input port, and an in-circuit serial programming (ICSP) port for software updates. The newer Arduino Due upgrades the core to a 32-bit ARM® Cortex®-M3. This core is also used in DFRobot’s controller board, discussed below, which combines Arduino compatibility and the motor driver.

Image of Arduino Uno

Figure 2: The Arduino Uno is a popular choice for Maker projects and is based on the Microchip Technology ATmega328P 8-bit RISC microcontroller. (Image source: Arduino)

The Raspberry Pi single-board computer was originally developed to teach basic computer science in schools, but it has become extremely popular among the Maker community. The latest Raspberry Pi 3 is based on a Broadcom 64-bit quad-core CPU running at 1.2 gigahertz (GHz). It includes an 802.11n wireless LAN, Bluetooth 4.1, and Bluetooth low energy (BLE). It also has 1 GB of RAM, a micro SD card slot, 4 USB ports, HDMI and Ethernet ports, a camera interface, 40 GPIO pins, plus other specialized interfaces.

Windows gurus looking to leverage their existing experience can start with the Devastator-compatible LattePanda controller board as it comes with an installed and activated full edition of Windows 10. The board uses a quad-core CPU running at 1.8 GHz, which is bundled with a co-processor, Microchip’s 8-bit ATmega32u4, for Arduino compatibility.

The LattePanda comes with 2 GB of DDR3L RAM and up to 32 GB of storage, one USB 3.0 and two USB 2.0 ports, Wi-Fi, Bluetooth 4.0, a co‐processor, and a total of 22 GPIOs split between the two processors.

Controlling the motors

After settling on the microcontroller core, the next step is to select a motor control board. The Devastator contains two 6 volt (V) motors operating at 160 rpm (no-load). Each one has a maximum output torque of 0.8 kgf.cm (0.058 ft-lb.), and a maximum stall current of 2.8 amps (A).

The Raspberry Pi requires a plugin expansion board for robot specific functions, but DFRobot’s DFR0398 Romeo BLE Quad board provides a single-board option for Arduino enthusiasts that contains both the microcontroller and the motor drivers (Figure 3). The board provides a more powerful core than UNO derivatives, but maintains Arduino software compatibility.

The microcontroller is STMicroelectronics’ STM32F103RET6: this device uses the ARM® Cortex®-M3 32-bit core running at 72 megahertz (MHz) and includes 512 Kbytes of flash memory, a motor control pulse-width modulation (PWM) block, 16 channels of 12-bit analog-to-digital conversion (ADC), and two channels of 12-bit digital-to-analog conversion (DAC).

Image of DFRobot DFR0398 Romeo BLE Quad

Figure 3: The DFR0398 Romeo BLE Quad is an Arduino-compatible robot control board with Bluetooth capability and drivers for four motors. (Image source: DFRobot)

The motor drivers are courtesy of two Microsemi HR8833 devices. Each MOSFET driver includes two H-bridge drivers for bidirectional control of the Devastator motors. The Romeo BLE Quad includes four encoder interfaces, and also integrates the CC2540 RF transceiver from Texas Instruments for Bluetooth 4.0 wireless connectivity.

Adding power

The microcontroller boards themselves can run on the 5 volts from the USB connector, but the motors require a portable (i.e. battery) source with higher voltage and current. Many Makers adapt inexpensive rechargeable battery packs originally designed for radio-controlled (RC) cars. These usually have voltages of 7 volts or higher and capacities of greater than 5000 milliamp-hours (mAh), and it’s an easy job to swap out the original connector. The Romeo BLE Quad servo power port can accept 7 to 10 volts DC.

Programming the microcontroller board

It’s simple to install software on the microcontroller board, and Maker-friendly suppliers have step-by-step instructions on their web sites.

When deciding on an operating system (OS), the choices differ by platform. The LattePanda board comes with Windows already installed. Raspberry Pi offers multiple options, including Windows IoT Core, and various Linux distributions. Raspbian, a variant of the open-source Debian Linux OS, is the most common choice among Makers.

Arduino, on the other hand, doesn’t use a traditional OS. Instead, Arduino platforms use a cyclic executive that repetitively loops through a code sequence. Developers write and install code with the open-source Arduino integrated development environment (IDE). It’s a cross-platform application written in Java and available for Windows, Mac OS X, and Linux host machines.  The Arduino environment has its own terminology for several items. For example, an Arduino-compatible plugin board is a “shield”, and a software module is a “sketch”.

Programming with the Romeo BLE Quad

Since the Romeo BLE Quad board is a single-board robot solution with advanced peripherals, it will be used for the discussion that follows.

To get started, choose the preferred OS for the host machine and download the appropriate IDE from the Arduino web site. Although the DF Romeo BLE Quad doesn’t use the same ATmega328 processor as the standard Arduino hardware, the software development process is similar since the board is compatible with the Arduino IDE.

The IDE accommodates more than twenty-five boards from several manufacturers, but the Romeo BLE Quad is not among them. The Romeo BLE Quad is a version of another DFRobot board, the Bluno M3, with motor drivers added. To configure the IDE, the Bluno M3 file must first be downloaded from the open-source GitHub site.

To install this file:

  1. Open the Arduino IDE and go to File -> Preferences. Copy the GitHub link into the “Additional Boards Manager URLs” box, and click “OK”.
  2. Go to Tools-> Board -> Board Manager, enter “Bluno M3” in the search box, and click “Install”.  This will download the configuration file.
  3. Select the Bluno M3 board from the Tools -> Board menu.

The system is now ready for application development. The standard IDE supports programming in C and C++, and includes multiple code examples. Developers use the text editor to write sketches (programs) (Figure 4).

Image of Arduino IDE screen and text editor

Figure 4: The Arduino IDE screen and text editor: a new program includes the two required functions. (Image source: Arduino)

The IDE then debugs the code, cross-compiles it, and uploads the result to the microcontroller board via the in-circuit serial programming (ICSP) port. The Romeo BLE Quad can also be programmed via its Bluetooth port.

The text editor begins a new program with two preloaded required functions, ready to add code: setup() configures the initial conditions and executes once, then loop() runs continuously.

Two Arduino libraries must be downloaded and installed to run the Devastator motors with the Romeo BLE Quad: Motor.h and PID_v1.h.

The code for the motor begins by requesting these two libraries as header files via an include statement, defines the I/O pins and some initial constants, then configures the motors in the setup() section (Listing 1).

Copy
/*!
* @file RemeoBLEQuadDrive.ino
* @brief RemeoBLEQuadDrive.ino PID control system of DC motor
*
*  RemeoBLEQuadDrive.ino Use PID control 4 way DC motor direction and speed
* 
* @author linfeng(490289303@qq.com)
* @version  V1.0
* @date  2016-4-14
*/
 
#include "PID_v1.h"
#include "Motor.h"
 
Motor motor[4];
int motorSpeed[4] = {-200,200,400,-400};/*Set 4 speed motor*/
/* Speed=motorSpeed/(32*(setSampleTime/1000))(r/s) */
const int motorDirPin[4][2] = { //Forward, Backward
/*Motor-driven IO ports*/
  {8,23},
  {7,9},   
  {24,14},
  {4,25}
};
 
 
//const double motorPidParam[3]={0.6,1,0.03};/*DC MOTOR,Yellow??180degree*/
//const double motorPidParam[3]={1.5,1,0.05};/*DC MOTOR,Yellow??90 degree*/
const double motorPidParam[3]={1.2,0.8,0.05};/*Encoder V1.0,160rd/min ;19500/min; 32:1,Kr=3.5*/
void setup( void )
{
  Serial1.begin(115200);
     for(int i=0;i<4;i++){
                                motor[i].setPid(motorPidParam[0],motorPidParam[1],motorPidParam[2]);/*Tuning PID parameters*/
                                motor[i].setPin(motorDirPin[i][0],motorDirPin[i][1]);/*Configure IO ports*/
                                motor[i].setSampleTime(100);/*Sets the sampling period*/
                motor[i].setChannel(i);/*Sets the motor channel */
                                motor[i].ready();/*Motor enable*/
                motor[i].setSpeed(motorSpeed[i]);/*Set motor speed*/
                }
}
 
void loop( void )
{
                for(int i = 0; i < 4; i++){
                                motor[i].calibrate();/*motor PID calibrate*/
                }
 
}

Listing 1: This example of C code configures and controls four Arduino motors for the Romeo BLE Quad. (Code source: DFRobot)

The setup() and loop() sections configure and control four motor channels. Since the Devastator chassis only needs two, the spares are available for accessories such as the robot arm discussed below.

Controlling the robot wirelessly

It’s possible to plug a USB cable into the control board and steer the robot around that way, but it’s much more convenient to control it wirelessly via Wi-Fi or Bluetooth and a smartphone, tablet, or computer. As mentioned earlier, Romeo BLE Quad includes the same Bluetooth 4.0 module as the Bluno platform. Open-source apps for iOS 7.0+ and Android 4.3+ are available from GitHub. With these apps, the designer can control the robot and upload a new sketch remotely.

Upgrades to the basic design

After assembling the basic design, a popular next step is to add accessories so that the robot can perform some useful tasks (Figure 5). Here are a few upgrades to try.

Image of DFRobot URM37 v4.0 ultrasonic sensor and Adafruit’s 397 camera module

Figure 5: The DFRobot URM37 v4.0 ultrasonic sensor (left) and Adafruit’s 397 camera module (right) are two popular accessories (Image sources: DFRobot and Adafruit)

Detecting and avoiding obstacles is a desirable feature in a mobile robot. The DFRobot URM37 v4.0 ultrasonic sensor outputs a voltage proportional to distance, and is compatible with both Arduino and Raspberry Pi. The sensor detects the presence of an object or wall, then the code executes a random turn and the robot continues in the new direction.

Turning the robot into a mobile camera is another popular upgrade. Adafruit’s 397 camera module can capture video or still pictures. The camera with its CMOS image sensor can capture a 640 x 480 pixel image at thirty frames per second (fps), and has a motion detection feature.

Consider mounting the camera on a robot arm, such as the DF05BB tilt/pan assembly (Figure 6). The kit includes two brackets and two DF05 servo motors and is designed for horizontal mounting.

Image of DFRobot DF05BB tilt/pan mounting

Figure 6: The DFRobot DF05BB tilt/pan mounting comes with two servo motors and two brackets. (Image source: DFRobot)

Putting it all together

A complete Devastator robot includes the chassis, the controller board, an expansion board, and an ultrasonic sensor (Figure 7). The two boards are located on the upper platform for convenience, but there’s also a lower mounting platform if a top-mounted movable camera is desired. 

 Image of Devastator chassis, controller board, a motor control expansion board, and an ultrasonic sensor

Figure 7: This example of a complete design includes the Devastator chassis, controller board, a motor control expansion board, and an ultrasonic sensor. (Image source: DFRobot)

Conclusion

The DFRobot is an excellent Maker-based platform for designers and Makers alike to explore software development, microcontroller functionality, sensor options and motor control in a fun, well-supported environment.

In addition, many resources are available on Digi-Key’s website. For example, learn more about programming the Arduino platform here. Digi-Key also offers help with programming Raspberry Pi with Python, the most popular Pi language. All of the products discussed above have extensive documentation, application notes, and tutorials.

After completing this project, there are many others to try. Maker.io is devoted to the Maker movement, with dozens of featured projects, resources, sources of funding, and more.

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of Digi-Key Electronics or official policies of Digi-Key Electronics.

About this author

Paul Pickering

About this publisher

Digi-Key's North American Editors