Although the main purpose of the rover is that the user views everything from the on-board camera, I have decided that it would make it visually more appealing if it could be seen in its terrain environment afterwards and if it could resemble an actual Martian rover.
Having to use the RC car chassis however does limit what I am able to achieve, although it does provide a solid base from which to start.
ABS Plastic construction.
ABS Plastic construction struts and sheet material.
- Easy to drill, saw and sand
- Easy to glue with poly cement
- Widely available
- Easy to cut
- Easy to glue and paint
I decided that my initial design should be in cardboard due to the availability and economic benefits, and then could be more easily measured up for creation in balsa wood, plastic or foamboard.
Final Prototype Design
The Electronic Speed Controller (ESC) can be controlled in the same way as the servo using the Raspberry Pi’s GPIO pins. The biggest difference is that the pulse widths to control it are different.
To find out what pulses made it do what I decided that it would be easier to set the duty cycle to 10o and then to change the pulse widths based on this. I discovered that then at a pulse width of 15 the ESC made the motor go forwards, and after much trial and error, that a pulse width of 13 made it go backwards.
Control via PHP
PHP runs python scripts on page load, so I needed to have the control buttons link to a page with the python script called on it. I could do this in a similar way to how I did with the servo control and have several different pages that look the same but with different scripts called when they load, however this would leave me with over 10 different pages, and this seems like a lot.
window.setTimeout(‘history.back();’, 1000); // waits a specified number of seconds before going back
This simple bit of script went into the <head> of my document. By changing the value ‘1000’ to another number you can change the time period that the page waits before going back. I then decided to add a simple message to the page that told the user that their previous command was currently in progress. I decided a .gif would make the page more interesting.
After many unsuccessful attempts at working the stepper motor I came across other projects using the Raspberry Pi that connected it to the servo and speed controller of a radio controlled car. Although in total more expensive and less customisable, it would save me plenty of time and effort to create the rover itself this way.
The biggest drawback would be the battery life. The rechargeable battery pack for the Pi lasts about 6 hours but the battery for the car is supposed to last only 15 minutes. I guessed it would last longer however because I would only be using it in short bursts of less than a second at a time, and the ESC would be drawing power from the Pi rather than that battery.
I chose a 1/18th scale model because it is smaller and therefore will have more room to move around.
After purchase the first thing I did was connect the servo in the same way as the one I was planning on using to move the camera with. This worked fine, however, the wheels obviously do not turn 180 degrees in each direction so I had to adjust the pwm time so that it would turn the wheels up to a maximum of 45 degrees in each direction. I also upgraded to a metal geared servo to stop the gears from shredding so easily if it was trying to turn too far in one direction or the other.
Using the script that I had created in Python which allows the servo to turn to both extremes (left and right) and the neutral position, I thought about possible ways of the user selecting the direction that they want the rover to travel in and how I would create a Python script to do this.
- Allow the user to specify the exact angle that they wish the wheels to turn to (from 180 degrees as full right, to -180 degrees full left). This is the most preferable option as it gives the user maximum control of the vehicle and is probably closest to how Martian Rovers actually operate since the drivers would need a high level of precision to navigate tricky terrain. I therefore calculated the following formula(a/170)+1.5/20.00*100.00Where a is the angle that you wish to turn to. However, when using this in Python it did not seem to want to calculate it correctly. This would also require me to have Python edit the script based upon what the user inputted on the webpage.
- Have 3 options for wheel turn angle – Left, Centre and Right. This would allow me to use the values that I already know, and I could very easily create a script where only 1 value would need to be changed in order for this to work. I could do this with one script that takes feedback from the web, or I could do it with multiple scripts that activate when necessary.
Setting Up The Web Server
Using this Instructables tutorial, I managed to install Apache and php5 as well as clients to allow me to upload files to the Pi remotely. Once I figured out
the /www/ folder
that the Raspberry Pi’s web server path /home/pi/www/ worked the same as any other web directory it was easy for me to create folders and pages within it that could easily be referenced through the HTML. I decided that all my images would go in /images and all my python scripts in /python.
Creating a Basic Control Interface
I discovered that in order to run python scripts from the web you need to call .php pages to open which have “<?php exec(‘sudo python /full/directory/here/scriptname.py’);?>” in their body. Therefore I figured out that I could link from the index.php page to a similar or identical page except that it calls the Python script on opening. This would cause the script to run and the servo to move.
I therefore created some basic images that said left, centre and right on them and put in some basic text that told the user what direction the wheels would now be facing and created two similar .php files – one with and one without the ‘exec’ function.
<?php exec(‘sudo python /home/pi/www/python/servoleft.py’);?>
<a href= left.php><img src=”images/left.png” alt=”Turn Left”></a>
<a href= centre.php><img src=”images/centre.png” alt=”Centre Wheels”></a>
<a href= right.php><img src=”images/right.png” alt=”Turn Right”></a>
Current Wheel Direction: Left
Once I was sure that this worked, I then duplicated and edited the Python scripts appropriately, putting them in the /python folder and created the missing .php files using the above template, before ensuring everything linked up correctly.
This allowed me to remotely change the direction of the servos.
According to this article, the Mars rover drivers plan out a course using a combination of data, which they then run a simulation on and adjust. Once the course is ready, the driver gives the signal and the rover follows the pre-assigned instructions. It makes sense that the rover is not under manual control since there is about a 4 minute delay sending signals to the red planet.
In order to make it interesting and not too complicated however I have decided not to simulate this entirely. I do however think that the user should have to input instructions and then execute them which will provide more of an interesting and simulative experience than if they were just driving the rover around like it were an RC car.
In its simplest form, this would involve the user inputting a direction and angle of rotation and a distance or amount of degrees and then sending the command. The tilt for the camera could probably be activated as soon as the button is pressed.
On the website homofaciens.de (home of the RoboSpatium as mentioned in a previous post), the control system for the robots is fairly simple and easy to use. Additionally, he has provided the source code and instructions on how to set up Apache2 on the Pi to be able to communicate with another computer and send and receive instructions.
I decided to use a stepper motor to control the wheels of the rover. A stepper motor unlike a regular DC motor can be told to move in specific increments and stop at various angles. I thought that this would be useful so that the operator could tell the rover to move its wheels forward a certain number of steps and then stop.
I researched and purchased a driver board and motor that I had found instructions for the usage of together.
The motor had two screw fixings on it so that it would also be easy to mount upon the body of the rover too.
I soldered pins onto the driver board and connected it up to the Pi, power supply and motor, and it showed me via an LED that it was receiving power.
I then sent ‘on’ and ‘off’ signals to the appropriate GPIO pin on the raspberry pi, but this failed to activate the motor at all.
Meanwhile I decided to see if I could work the servo that would tilt the camera. Whereas the motor requires a separate driver board, the pi can directly drive servos from its GPIO pins.
My research found that the different lengths of pulses sent to the GPIO tell the server what position to move to:
By default, the Pi sends a pulse that lasts 20ms, so using Python, a code needed to be written that changed the pulse length, and that means setting the pin to use PWM (Pulse Width Modulation). Doing this, you can change the duty cycle (or the length of each pulse) to what it needs to be to direct the servo to move to a specific angle.
This gives me several options in letting the user control the camera tilt:
Give them 3 positions to be able to move to – up, down and central
- Calculate some in between values and let them select from a wider range of angles
- Create a script that when they choose any angle themselves, it calculates the correct duty cycle and activates it.
Here is a video of a script that moves the servo to each of the 3 extremes of positions. (Note that the servo only actually moves to 160 degrees)
After ordering in the parts that I need for the electronics to control the rover, I measured their dimensions and used this to plan the size of the Rover. Aside from fitting all the components, I need to be able to access the Pi and the battery pack to recharge and reboot the rover.
I intend to use plastics for the casing, and have identified 2mm thick PVC as being a good option, as it has a high mechanical and tensile strength for the price. The structure will likely be held together with 3mm threaded steel rods that have nuts supporting the plastic platforms.
The structure will be then hidden underneath the ‘solar’ panels, which are for aesthetic purposes only.