Training Session 4:
Programming robots and actuators
Monday 30 July, 6pm-8pm, Postdoc Centre, 16 Mill Lane, Cambridge (Register here)
The robot consists of: Arduino UNO compatible main control board; Light Sensor, Me Ultrasonic Sensor, Me Line Follower Sensor; Bluetooth/USB communication ports
1.5V AA Batteries*4 power supply
170 * 130 *90mm（L*W*H）1034g.
The basic chassis has two electric motors that individually power its wheels, with ultrasonic sonar sensor for distance measurement and infrared sensors for line tracking. However, the chassis allows mounting of additional sensors and actuators.
More details at: https://www.makeblock.com/steam-kits/mbot
Instructional youtube videos: click here
Arduino ports for onboard devices
Light sensor A6
2x Neopixel RGB LEDS D13
Motor 1: D6, D7
Motor 2: D4, D5
IR emitter: D3
IR receiver: D2
The board also has solder points for ports A0-3, D9-12 and I2C SDA,SCL
1. Assemble the robot
The mBot devices are provided as a kit with full assembly instructions. Please assemble. This should take around 20-30 minutes. A PDF version of the instruction manual can be found at the following link:
The robots can be controlled using the provided IR controller, Bluetooth or programmed via XOD, using the USB port. When it is first turned on, the mBot has 3 pre-set control modes: Obstacle avoidance mode, Line-follow mode, and Manual control mode. These can be switched using the IR controller or button on the robot (details in the manual), and used to test the device after assembly.
Before you can connect your mBot to your PC, Mac or mobile device, you need to install the mBot USB drivers. The mBot manufacturers have provided a range of programming tools that can be used with the robot: https://www.makeblock.com/steam-kits/mbot/software. Installing the MakeBlock software packages also provides access to the USB drivers - and this may the simplest way to get up and running. This will also provide an alternative programming platform to explore.
Alternatively, drivers for the CH340/341 USB-serial chip can be found online
Troubleshooting guide for mBot: https://www.vernier.com/til/4136/
2. XOD PID controller for the mBot
Max Danilin (https://twitter.com/gabbapeople) has created some excellent tutorials for the use of XOD with the MakeBlock mBot. In one, he describes the use of the XOD pid-controller node to control self-navigation of the mBot. (A proportional–integral–derivative controller or PID-controller is a control loop feedback mechanism used in automatic control systems to maintain the value of the measured parameter.)
The article describes control of the mBot - including (i) an mbot-motors node to drive robot movement, (ii) an mbot-ultrasonic-sensor node that calculates the distance to obstacles from the mBot ultrasonic sensor. These are connected to the XOD pid-controller node.
The PID controller calculates an “error” value as the difference between a measured input value and the desired setpoint. The controller attempts to minimize the error by adjusting the output. To control the output, a PID-controller uses coefficients Kp, Ki, and Kd which are based on error changes.
The PID controller will be set with a target value or set point - and provided with a measured value.
You will need to Kp pin = proportional factor. Coefficient Kp is proportional to the current value of error.
Ki pin = integral factor. This coefficient is used to neutralize the accumulating part of the error. It can eliminate system errors accumulate after a certain amount of algorithm loops.
Kd pin = derivative factor. It estimates the trend of future errors using Kd rate of change. The more rapidly the rate of error changes, the higher the controlling or dampening effect of PID-controller will be.
There are no specific values of Kp, Ki, Kd coefficients. Different systems with a PID-controller will have individually tuned ratios.
Set up the mBot to approach an obstacle and remain at a fixed distance. Experiment with PID parameters. Add basic navigation routines and collision avoidance.
XOD library for tutorial session
A .xodball library of XOD code for the tutorials can be downloaded here.
(You will need to pay attention to the ports used for your circuit - and to match these with the XOD programme).
3. mBot navigation and line following
The mBot comes with dual infrared emitter-sensors that are mounted in the front of the robot - to allow line-following. The use of these are described in Max Danilin's second tutorial article.
The sensors are connected to one of the mBots RJ25 ports. The bot-line-sensor node communicates with the hardware through the S1 and S2 input pins. It has two output pins L and R according to the left and right infrared sensor on the board. True value on an output pin means that there is a white or bright color in front of the infrared sensor. In turn, false value means that the color is black or dark.
- Situation 1. Both IR LEDs are on the line. mbot-line-sensor node puts false to the L and R pins. mBot should move forward.
- Situation 2. The left IR LED is on the line while the right deviates to the right. mbot-line-sensor node puts false to the L pin, and true to the R. mBot should turn to the left.
- Situation 3. The right IR LED is on the line while the left deviates to the left. mbot-line-sensor node puts true to the L pin, and false to the R. mBot should turn to the right.
- Situation 4. Both IR LEDs are out of the line. mbot-line-sensor node outputs two true values. mBot should turn around to find the missing line.
A PID-controller requires a single variable input while the mbot-line-sensor outputs two. To solve this problem, subtract node is added. This node subtracts two boolean variables and produces a number. In this way, the subtract node can output the values:
- 0 for the first situation;
- -1 for the second situation;
- 1 for the third situation;
- 0 for the fourth situation.
We use those four situations to form the “error” concept for the PID-controller. The situation when the incoming value is 0 and both IR LEDs are in line is ideal for us. That’s why we should set up the the TARG pin to 0.
But this patch in its form can work correctly only with the second and third situations. When mBot completely loses the line the incoming value for the pid-controller node will be 0 too. For this case special logic needs to be introduced, which is explained in detail at:
Additional article on building a modified, self- balancing mBot with accelerometer and XOD software also from Max Danilin. Extensive testing and description of PID controller parameters can be found at: https://medium.com/xodlang/xod-and-pid-powered-self-balancing-mbot-6c420600271e
The mBot is equipped with a range of peripheral devices - can include these in any of your programmes - for example to provide collision warnings or feedback?
A0 RJ25 plug 4 (default not-connected)
A1 RJ25 plug 4 (default not-connected)
A2 RJ25 plug 3 ultrasonic
A3 RJ25 plug 3 ultrasonic
A6 light sensor
D2 IR RCV
D3 IR TX
D4 DIR2 - direction motor2
D5 PWM2 - pwm motor2
D6 PWM1 - pwn motor1
D7 DIR1 - direction motor1
D9 RJ25 plug 2 linefollower
D10 RJ25 plug 2 linefollower
D11 RJ25 plug 1 (default not-connected)
D12 RJ25 plug 1 (default not-connected)
D13 2 WS2812 Neopixel RGB LEDs
The board also has solder points for ports A0-3, D9-12 and I2C SDA,SCL, so additional components could be added to the robots.Can you engineer robot-robot sensing and communication?
More details about mBot ports at: http://blog.hmpg.net/2016/04/makeblock-mcore-information.html
XOD libraries for the mBOT: https://xod.io/libs/gabbapeople/mbot-lib/ (gabbapeople/mbot-lib loaded in XOD)
We've collected the relevant code from the gabbapeople/mbot-lib library and placed it in the tutorial session code.
MakeBlock downloads for mBot series: https://www.makeblock.com/steam-kits/mbot/downloads
(Instructions, videos, schematics, etc.)
MakeBlock programming information for the mBot: http://learn.makeblock.com/en/mbot-programming/
Thingiverse 3D printed accessories for mBot: https://www.thingiverse.com/tag:mbot
(Including brackets, pen holders, bumpers, etc.)
Collection of mBlock pseudo-code for controlling the mBot: http://www.mblock.cc/example/introduction/
(includes control of mCore onboard LEDs, sensors, etc.)
MakeBlock Github site: https://github.com/Makeblock-official
PID Controller Basics Using XOD and Arduino: https://medium.com/@victoriandeolrn/pid-controller-basics-using-xod-and-arduino-d1eb604b46d