If you've read my other Instructables you know I have a love for LED and lighting. Another area that also simultaneously intrigues and frustrates me is robotics.
Two wheeled robots are very popular as they can teach you a great deal about robotics, electronics and programming. They also provide a nice low cost and usable way to drive a robot around. Four wheel and six wheel designs for example require a lot more mechanics and number crunching to be able to drive them around effectively.
In this Instructable my aim is to show you how to create your own two wheel robot as well as creating the firmware to drive it and even if you wish simulate it on a computer.
I finish the topic by highlighting some of the two wheel robot projects I have been a part of, how I helped to design them and how well they have performed. We have also just launched a kick starter campaign for the latest robot so I thought it was worth a cheeky mention.
Step 1: Designing a robot
Designing a robot can be as easy or complicated as you want to make it.
The first thing to realise is that you will likely need more than two wheels touching the floor to keep the robot upright (unless your making an auto balancing bot). The first picture shows two additional skids which touch the floor and allow the robot to remain fairly perpendicular with the floor. The skids are placed so that they are aligned with the wheels. This simply allows the robot to easily turn on the spot without much fuss.
I begin by shopping around for components, order samples of the components and then break out my trusty digital callipers and open up the Sketchup software. Sketchup is good because it is very simple to use after following a few tutorials, it is free and with a bit of tweaking will generate CAD for 3D printers or CNC routers.
Shown in the images are some of the files I made while playing around with concepts for a new two wheeled robot.
The photos showing the red 3D printed parts show my attempt at creating a motor and battery housing that could easily be attached to a PCB. The battery is a single Lipo cell and sits in the upper most box under the FF cutout. A piece of black card is placed on top of the battery to make the FF cutout pop a bit more and to help protect the battery. The sketchup and 3D printable stl model files are attached should you wish to see how I have done things.
Step 2: Installing Flowcode
The Flowcode software from MatrixTSL is a very nice Flowchart based programming language for Microcontrollers. The latest version v6 also allows you to create your own components and simulate them in a virtual 3D environment so this is what we will be using to create both the firmware to drive our real world robot and the simulation. Flowcode currently only works with Windows based computers so sorry to all you Linux users out there.
The free version of Flowcode 6 will be fine for creating the simulation. When we want to program the real world robot we can simply activate the 30-day trial license of Flowcode and this then allows you to compile your code into machine code that can be recognised by a microcontroller.
Once you have downloaded the Flowcode installer you need to run the file to install Flowcode onto your computer.
You can sign up for your 30-day trial by visiting this page and creating an account. Once you have created an account go to the Help -> Activate menu in Flowcode. Enter your username and password and you now have access to a full professional license with all chips packs for the next 30-days.
The video is something I put together when Flowcode 6 was launched to highlight some of the new features.
Step 3: Using existing robots components in Flowcode
Flowcode comes with a lot of components pre-installed as standard.
The Formula Flowcode robot is an example of a two wheeled robot which can be driven around in the simulation or downloaded to the real hardware.
There is also a maze builder component which is useful if you want to practice maze solving or object avoidance techniques.
Finally you can use panel primitives to create a line which the robot can follow.
Attached are some working example programs that use the current Formula Flowcode component to perform a task. The programs work equally well in simulation and in real life on the hardware.
Step 4: Building components part 1
The video shows the steps to create the underlying simulation to drive the robot around on the Flowcode panel.
We begin by using the primitive objects to create the chassis and the wheels.
We then create macros to allow us to set the motor speed and how to update the objects on the panel to match.
The macros and simulation are then exported to create a component that another user can simply drag onto their panel to start using your code.
Instead of using primitive objects you could always use your own meshes instead. Flowcode will import .stl mesh files simply by dragging them onto the Flowcode panel. Adding the mesh file to the resource manager allows the mesh file to be packaged into the component export.
Step 5: Building components part 2
The video shows the steps to control the real world hardware using pulse width modulated (PWM) based outputs. The PWM outputs drive a H-Bridge motor driver IC such as the L293D. Each motor has a PWM signal to set the speed and a second signal to control the motor direction.
When the direction signal is a logic 0 a PWM duty of 255 is full speed and a duty of 0 is stopped.
When the direction signal is a logic 1 to reverse the direction of the motor a PWM duty of 255 is stopped and a duty of 0 is full speed.
Step 6: Building components part 3
The video shows the steps to create distance and line sensors to be able to start sensing the surrounding environment.
We begin by creating a very simple distance sensor by creating a hidden position object and checking for collisions. The line sensors use exactly the same principal.
The real world robot can simply use an IR sensor and the on-board ADC to take proximity readings so we also add the code to drive this. Image G shows the IR proximity sensor circuitry and Image C shows the IR line sensor circuitry.
To account for ambient light levels we first take an ADC reading with the IR emitter switched off. We then switch on the IR emitter and wait a short amount of time for the IR receiver to react. We finish by taking a second ADC reading and switching off the IR emitter to save battery power. The first IR reading is subtracted from the second to give us the valid proximity reading.
Also attached are the component source, component export and my component test program.
Step 7: The brain
Flowcode can create code for 8-bit PICs, 16-bit PICs and 8-bit AVR devices including Arduino targets.
I would rate the microcontrollers in this order in terms of their ability to do the job. This is simply my opinion, I don't want to spark a microcontroller fan war!
16-bit PICs especially the EP range of devices can run at up to 70 16-bit million operations per second (MIPs), have lots of available ROM and RAM and tonnes of highly configurable peripherals including UARTs, PWM, SPI and I2C. They can also do floating point calculations much faster than an 8-bit device.
8-bit AVRs / Arduino can run at up to 20 8-bit MIPs and have generally have a good amount of memory and peripherals.
8-bit PICs can run at up to 12 8-bit MIPs again with lots of memory and peripherals. Due to the architecture of these devices and the compiler your using they can sometimes struggle to work with data arrays larger than 256 bytes in length. They also seem to struggle a bit more with floating point type maths, again largely dependent on the compiler.
The PICs can be programmed using a programmer such as an EB006 E-block or using a 6-pin ICSP header on your circuitry and a Microchip tool such as a PICkit 3.
The AVRs can be programmed using a programmer such as an AVRISP mkII. Arduinos already have an on-board bootloader and USB connection allowing them to be reprogrammed without any additional hardware.
Step 8: Extras, sensors, actuators and communications
Once you have the basic setup of two motors connected to two wheels you can start to add in extras.
Here are some additional items you might want to add to your robot.
- User switches
- IR based range sensors
- Ultrasonic based range sensors
- Laser based range sensors
- IR based line following sensors
- Hall effect based cable following sensors
- Communications (Bluetooth / Wifi)
- Firmware Updates (Bootloader - USB / Bluetooth / Wifi)
- Encoders - to feedback the amount the motors move
- Battery charging and management
- Audio - in/out
- Storage - SD card, Flash or RAM IC
- Servo motor outputs to make simple moveable limbs or grippers
- Cameras - Tricky unless you use a dedicated wireless video transmitter & receiver or Wifi IP cam
- Laser Pointer
- Nerf / BB cannon...
Here are some additional items you might also want to think about before diving into a fixed design.
- Processing power required
- Memory usage
- Triangulation using IR beacons
- Triangulation using ultrasonic pings
- Mapping using range sensors and encoders
- Behavioral functionality
There are lots of good circuits out there so Google the circuit you want to add and then add that to your controller circuitry. Circuits off the internet might not always work fist time so it is usually a good idea to knock things together using breadboard / veroboard first before committing to a more permanent design such as a PCB.
Flowcode has components built in to drive a wide range of external devices. TheFlowcode wiki usually has some good examples and if the component is based on an E-block then you can refer to the E-block datasheet for a complete schematic of the electronics.
Step 9: Early attempts
Early on in my embedded career I had a quick go at making my own robots using home made PCBs, PIC microcontrollers and pager motors. I got fairly far but driving the wheels directly from the motor shaft proved to be a bit much for the motors. Unfortunately these appear to have been throw out now or I would have taken pictures.
It was time to add some gears.
Shown is my next attempt using 3D printed parts and a breadboard as the chassis and PCB. This worked but was fairly far from ideal.
Step 10: Using servo motors
Servo motors are great in that they are very cheap to buy from sites like eBay, they don't require a separate motor driver IC and they also provide a large gearing ratio to generate a lot of torque to help move your robot.
The image shows a chassis I designed using Sketchup to house a LiPo battery cell and two modded mini tower pro servo motors.
The video shows a servo motor hack allowing you to convert a servo motor to provide speed control rather than angle control. Note this mod is a one way process as your essentially ripping the angular feedback parts out of the motor. This technique will change slightly depending on your specific motors. Simply do a Google search for your servo motor and include the terms "continuous rotation mod" or something along those lines. Please note this is not my video.
To drive the servo motor you would replace the PWM Flowcode components with a servo controller component and this component then allows you to drive up to 8 servo motors independently.
Stepper motors can also be a good option but can tend to be a bit expensive and power hungry to get a good mixture of torque and speed. Micro stepping drivers such as the EasyDriver seem to work very well to drive these at very precise resolutions. Again there is a Flowcode component available to drive a stepper using a dual H-bridge motor driver.
Step 11: Formula Flowcode
The Formula Flowcode robot was created 8-9 years ago. The schematic and board layout were done by a renowned Belgian teacher named Bart Huyskens. My role was to test and ensured everything was ok for an educational lab environment and mass production.
This robot works very well but has a number of key limitations.
- No display as standard so taking readings and being able to see what is going on can be a bit tricky. A display can be bolted on but this is an extra.
- No Wireless communications as standard. Again this can be bolted on as an extra.
- No feedback from the motors. This means that we have to rely on the sensors to tell us what to do next, everything else is dead reckoning.
- The chassis was a off the shelf part but getting hold of usable stock was becoming increasingly difficult.
Shown in the video is an example of the Formula Flowcode robot being used in an assault course. Behavioural control is used to drive the robot around the maze, make a noise and follow a line depending on the robot's current circumstances.
- No Line detected = Follow the wall
- Line detected & No right hand wall detected = Follow the line
- Line detected & right hand wall detected = Stop and play a tune
The various parts of the circuitry can be seen in the attached schematic image.
Bart has since created another robot named Proton shown colored red in the last picture.
Step 12: Formula Allcode
The Formula AllCode was designed and specified by me and then the components sourced by a team of Chinese engineers to ensure we were getting good value for money. It provides everything out of the box that was in the Formula Flowcode as well as a good range of new features the original was lacking.
Here is a list of the features that were added to the robot to try and make it as flexible and robust as possible.
- 16-bit 70-MIPs dsPIC33 microcontroller
- Wireless reprogramming Bluetooth communications
- USB rechargable lithium battery
- 4 line 40 character monochrome backlit LCD display
- Micro SD card socket
- 8 x user LEDs
- 2 x user switches and reset switch
- 8 x IR distance sensors
- 2 x Line following sensors
- Light sensor
- Digital 3-axis accelerometer and compass
- Speaker controlled using PWM
- 4 x servo motor outputs
Motors with integrated metal gearbox and high resolution encoder
- E-blocks expansion port - 8 x I/O + Ground
- 2 x Additional expansion headers
- Mounting holes for 3D printed custom skins and mechanical expansion
We have just started a kick starter campaign on the Formula AllCode robot so if you don't fancy designing your own two wheel robot or just want to see what we are up to then we would very much appreciate your support.
Many thanks for reading.