Robot and controller code for a Wall-E replica robot. For more information about the robot, visit https://wired.chillibasket.com/3d-printed-wall-e/
Main program to control the motors and servos of the robot. Features include:
- An animation queue, keeping track of the next servo movements the robot needs to perform.
- A random movement generator, allowing the robot to autonomously move and appear animated.
- Velocity control of all servo motors, facilitating smooth accelerations and decelerations.
- Non-blocking serial parsing, allowing the movements of the robot to be remote controlled.
The web interface is programmed in Python and uses Flask to generate a server. The Raspberry Pi is connected via USB to the Arduino micro-controller. The main features are:
- A JavaScript joystick, with which the movement of the robot can easily be controller.
- A list of sounds which can be played.
- A list of movement animations which can be performed by the robot.
- Settings page, where motor parameters, sound volume, and video options can be modified.
- A simple login page to prevent everyone from having access to the controls (note: this is not a full access control system, please don't use this web interface on untrusted/public networks)
Image of the web interface and robot
- Ensure that the wiring of the electronics matches the diagram shown below.
- Download/clone the folder "wall-e" from the GitHub repository.
- Open wall-e.ino in the Arduino IDE; the files MotorController.hpp and Queue.hpp should automatically open on separate tabs of the IDE as well.
- Install the Adafruit_PWMServoDriver.h library
- Go to Sketch -> Include Library -> Manage Libraries...
- Search for Adafruit Servo.
- Install version 1.0.2 of the library; the newest version currently has a bug and doesn't work properly.
- Connect to the computer to the micro-controller with a USB cable. Ensure that the correct Board and Port are selected in the Tools menu.
- Upload the sketch to the micro-controller.
Diagram showing the wiring of the robot's electronic components
- Once the sketch has been uploaded to the Arduino, power on the 12V battery while the micro-controller is still connected to the computer.
- Open the Serial Monitor (button in top-right of Arduino IDE). Set the baud rate to 115200.
- To control the movement of the robot, send the characters 'w', 'a', 's' or 'd' to move forward, left, back or right respectively. Send 'q' to stop all movement.
- To move the head, send the characters 'j', 'l', 'i' or 'k' to tilt the head left or right and the eyes upwards or downwards.
- Only move on to using the Raspberry Pi if all these functions are working correctly!
- Download/clone the folder "wall-e_calibration" from the GitHub repository
- Open wall-e_calibration.ino in the Arduino IDE.
- Upload the sketch to the micro-controller, and open the serial monitor and set the baud rate to 115200.
- The sketch is used to calibrate the maximum and minimum PWM pulse lengths required to move each servo motor across its desired range of motion. The standard LOW and HIGH positions of each of the servos can be seen on diagrams on my website.
- When starting the sketch and opening the serial monitor, the a message should appear after 2-3 seconds, saying that it is ready to calibrate the LOW position of the first servo motor (the head rotation).
- Send the character 'a' and 'd' to move the motor backwards and forwards by -10 and +10. For finer control, use the characters 'z' and 'c' to move the motor by -1 and +1.
- Once the motor is position in the correct position, send the character 'n' to proceed to the calibration step. It will move on to the HIGH position of the same servo, after which the process will repeat for each of the 7 servos in the robot.
- When all joints are calibrated, the sketch will output an array containing the calibration values to the serial monitor.
- Copy the array, and paste it into lines 85 to 92 of the program wall-e.ino. The array should look similar to this:
int preset[][2] = {{398, 112}, // head rotation
{565, 188}, // neck top
{470, 100}, // neck bottom
{475, 230}, // eye right
{270, 440}, // eye left
{350, 185}, // arm left
{188, 360}}; // arm right
- Setup the Raspberry Pi to run the latest version of Raspbian/NOOBS. The setup instructions can be found on the Raspberry Pi website.
- Open the command line terminal on the Raspberry Pi.
- Ensure that the package list has been updated (this may take some time):
sudo apt-get update
- Install Flask - this is a Python framework used to create webservers:
- Ensure that pip is installed:
sudo apt-get install python-pip
- Install Flask and its dependencies:
sudo pip install flask
- Ensure that pip is installed:
- Clone repository into the home directory of the Raspberry Pi:
cd ~ git clone https://github.com/chillibasket/walle-replica.git
- Connect to the Arduino/micro-controller:
- Plug the Arduino/micro-controller into the USB port of the Raspberry Pi.
- Use the following command to list the connected USB devices. Record the name of the device you want to connect to:
result=$(python <<EOF import serial.tools.list_ports for p in serial.tools.list_ports.comports(): print(p) EOF ) echo $result
- Open app.py:
nano ~/walle-replica/web_interface/app.py
- Go to line 92 (you can do this with the keyboard command
CTRL + _
), and check whether the name of your micro-controller is already listed there. If not, add it where is says ARDUINO.
- Set the web server password:
- On line 180 of app.py where is says
put_password_here
, insert the password you want to use for the web interface. - Press
CTRL + O
to save andCTRL + X
to exit the nano editor.
- On line 180 of app.py where is says
- To determine the current IP address of the Raspberry Pi on your network, type the command:
hostname -I
- To start the server:
python3 ~/walle-replica/web_interface/app.py
- To access the web interface, open a browser on any computer/device on the same network and type in the IP address of the Raspberry Pi, follow by
:5000
. For example192.168.1.10:5000
- To stop the server press:
CTRL + C
- Install mjpg-streamer - this is used to stream the video to the webserver. A good description of the installation procedure is described here. Complete the Install & Setup steps, as well as creating the Auto Start Manager Script. Stop when you reach the Start on Boot section.
- Make sure that the manager script you created has the correct name and is in the correct directory:
/home/pi/mjpg-streamer.sh
Coming soon!
- By default the Raspberry should automatically select whether to output audio to the HDMI port or the headphone jack. However, you can ensure that it always uses the headphone jack with the following command:
amixer cset numid=3 1
- Make sure that all the sound files you want to use are of type
*.ogg
. Most music/sound editors should be able to convert the sound file to this format. - Change the file name so that it has the following format:
[file name]_[length in milliseconds].ogg
. For example:eva_1200.ogg
- Upload the sound file to Raspberry Pi in the following folder:
~/walle-replica/web_interface/static/sounds/
- All the files should appear in the web interface when you reload the page. If the files do not appear, you may need to change the privileges required to access the folder:
sudo chmod -R 755 ~/walle-replica/web_interface/static/sounds
- Fixed some bugs related to sound playback.
- Added 2 sample sound files, which ensures that the sound directory is included in the git files.
- Added wall-e_calibration.ino, with which the maximum and minimum pulse widths of the servo motors can be calibrated.
- Updated wall-e.ino to use relative coordinates rather than absolute servo pulse widths for the animation presets. This allows the servo calibration data to be used to ensure the movements are the same on all variants of the robot.