It's only been within the past year that I've really started getting into electronics as a proper hobby, Arduino being a 'gateway drug', and now I'm hooked! So I decided I wanted to build an obstacle avoiding robot for my first fully fledged attempt.
This quickly evolved, and I felt the need to add new parts as I went. Wireless communications was something I'd never touched before, so I decided to use Xbees to turn the robot into an RC rover! I struggled at first but eventually managed to get it working, by building my own remote control from strip-board. The LCD screen and LED search lights were other new additions as well!
The end-result is a rover style robot, with autonomous and RC capabilities, and a treaded drive system to overcome most obstacles!
This project (being my first serious forage into the world of robots) was really for me to learn a whole lot about robotic locomotion, communications and simple autonomous algorithms. The other purpose, of course, was to build a robot that was able to be either remote controlled or autonomous, allowing the user to toggle between the modes while the robot was running. The bullet points summarise the main aims.
- Being able to avoid obstacles.
- Being able to do the above on the fly. In other words, being able to scan for obstacles without stopping.
- Being powerful to overcome most small (5cm high) obstacles.
- Being able to be remote controlled.
- Being able to switch between autonomous and remote controlled on the fly.
From first glimpse, the robot may appear to be bit complex. The picture below is the context diagram, a basic illustration of inputs, outputs and what's in-between.
At the top is the Remote control. This is formed of an Arduino Pro Mini, a load of push-button switches, and an XBee Wireless module. The switches are there to form the buttons, that will be used to control the rover.
The Arduino Pro Mini is used to read the state of the switches, and make choose which serial command should be sent to the XBee.
When the XBee receives a serial command (in my case, a serial command was a character corresponding to a specific button), it broadcasts it to all other XBees on the same network.
The Rover uses another XBee as a reciever, to sense any wireless characters sent from the remote. The range of the XBee is about 30 metres indoors, but I found this reduced to around 10 metres if there are walls in the way. Outdoor range is apparently around 500 metres, but I haven't tested this yet!
The ultrasound sensor form the eyes of the rover, and is used to sense the distance of any objects it is pointed at. The sensor can detect any object up to 4 metres away directly in front of it. The output of the sensor is a pulse, with the pulse length corresponding to distance. Using the Mega's timer functionality and some built in math, it's easy to convert this to cm.
There are two LDRs on the Rover, used to sense light level. The LDRs are connected up to voltage divider circuits, allowing a convenient voltage range (From 0.3V to 4.6V) corresponding to light level, to be measured using one of the Mega's many analogue inputs.
The wheel encoders are of the quadrature type, and are actually built into the gear assembly on the rover. They allow the Mega to be able to sense how far each motor has moved, useful for precise turning!
The outputs of the rover are also relatively straight forward.
The four wheels are all linked via the rubber treads, so it is important to avoid drive linked motors at different speeds. The motors for the wheels are driven using PWM signals generated from the Arduino Mega. At motor driver interface board is used to drive the motors.
The Pan Servo Motor is mounted within the pan and tilt bracket, and is used to change the direction in which the ultrasound sensor faces. This allows the rover to map out its surroundings without having to move its entire body.
The LEDs are more an aesthetic addition. They are driven directly from the Mega using a PWM signal to control the brightness. The brightness is dependent on the value from the LDRs.
The Arduino Mega is connected to an Arduino Uno via Serial communication. The Uno is also connected to an LCD display which is driven using an SPI interface. This allows the rover to display text to the user, having two separate, dedicated processors from display and movement control. Of course, it also means you can display smileys!
The diagram below is a system diagram, basically a more detailed context diagram.
The enhanced photo below highlights some of the system components.
The bottom part of the body was pre-bought. I cut perplex sheets to hold the Arduinos. The Pan and Tilt servo was a kit assembly.
1 Rover 5 Tank platform (includes motors, gears and encoders)
2 Rubber treads
Pieces of perspex sheet
1 Pan and Tilt Servo Bracket
Power sources and related hardware
1 1.V 2200mAH, 3S, 25C Lipo battery
1 9V PP3 battery
Two LM317 Voltage Regulators
4 1uF Capacitors (for decoupling)
1 Arduino Mega
1 Arduino Uno
1 Arduino Pro Mini
2 XBee Series 1, 1mW Wireless radios
1 Adafruit Motor Shield
1 Sainsmart LCD Shield
1 Ultrasonic sensor
2 Light Dependant Resistors
4 Encoders (built into tank platform)
1 Large rocker switch
1 Small rocker switch
7 Momentary Push-button switches
4 Motors (built into tank platform)
2 Tower pro MG995 Servos
1 LCD Screen
Various nuts and screws
Lots of wire and cable ties!
Since there are three Arduinos being used in this project, there are three separate codes. It's simpler to look at each one separately
Code on Arduino Pro Mini (on remote control)
On the remote, the buttons are all connected between a potential divider circuit and an analogue input.
The code is constantly polling the voltage on that analogue input. If the voltage falls within a specific range, the Arduino generates and sends a specific character to the onboard XBee. Each specific character corresponds to a specific voltage range which, in turn, corresponds to a specific button. The XBee is in transparent mode (it will transmit whatever it receives without modifying the data), so no code is running on it.
Code on Arduino UNO (LCD display driver)
This code simple scans for serial data from the Arduino Mega, and displays it on the LCD screen.
Code on Arduino Mega (Main Rover controller)
The state machine below describes the code running on the Mega.
Here's a video of the OARC Rover in action.
Problems Faced and Solutions
Limited IO pins on the Arduino Pro Mini - This meant I had to use a potential divider circuit with the switches, instead of each one having its own digital input. This meant only one button could be pressed at a time, limiting the range of movement possible with remote control.
Limitations of the ultrasound sensor - Ultrasound sensors are great with flat objects. However if an object is angled away from the sensor, they tend not to read a value. Long distance measurements (up to four metres) are only really possible with direct flat surface. By rotating the sensor, it does overcome this issue to a degree, but it does not eliminate it.
Limitations of the Arduino programming environment - In the Arduino IDE, it isn't possible to achieve parallel loops via multithreading. Instead, all the code exists within a single loop. This was quite limiting as it meant I was unable to separate the task of moving the pan servo and moving the motors. Instead, they had to be constantly updated within a single loop, meaning that the servo would pause whilst the rover was turning.
Considering this was my first main attempt at robotics, I felt this went pretty well.
If I decide to build an improved version, I would probably make the following changes.
- Build my own tank chassis
- Implement variable speed control using the remote control
- Add an accelerometer the remote control for tilt steering
- Develop a smoother method of turning (instead of just turning on the spot).
- Improve the obstacle avoidance algorithm.
- Perhaps use a different controller, and use multithreading.
- Add a speaker to be able to output sound.
If you have any questions or would like to see the code, let me know and I'd be happy to share what I've learnt!
For my next project I want to construct a custom built biped or quadruped. Eventually I'd quite like to build a custom built, webcam enabled quadcopter.