
Limited time resource download: Reply “Tutorial” to get the microcontroller e-book, reply “Simulation“ to get Proteus simulation materials, Baido cloud group sharing link update time: 2017-08-08, if it is invalid, please leave a message at the end of the article, do not leave a message in the background, you can also search for more resources you want in the background menu “Resource Search”!
Currently, many people are using Arduino and Raspberry Pi to build cars, drones, and robots. Here, we share a “hexapod walking robot” created by Roland Pelayo. This Raspberry Pi-powered robot can run autonomously, avoid obstacles automatically, and can also be controlled manually via a smartphone. Let’s take a closer look at the process.
Hexapod Walker Concept
This hexapod walker will follow the tripod gait used by most animals and insects. The tripod gait is shown in the figure below:
Image courtesy of NC State University
There are many ways to use this gait in a hexapod walker.
After balancing price and performance, I chose to build a version with three servos. Then I added another servo for mounting the robot’s “eyes”.
The robot will have three movements: forward, backward, right turn, and left turn. Any movement will involve the robot tilting to the right or left, then moving the legs that are lifted by the tilt. Here is a diagram of the movements (the gray on the legs means the robot’s weight is on that leg).The right turn movement is basically the opposite of the left turn movement.
To make the three servo motor design possible, the corresponding back legs need to be interconnected while the third servo motor tilts the walker.
This hexapod walker can operate in two modes:
In the first mode (autonomous), the walker can roam freely. If it detects an obstacle, it will back up two steps and then turn right. The second mode will allow the user to control the movements of the hexapod walker using any smartphone connected to the same network as the robot. According to my design requirements, I need a controller that can do
1) Control four servos simultaneously 2) Read input from the obstacle detection sensor 3) Connect to a network for wireless control.
Creating an Arduino hexapod walker is tempting and easier, but the cost of adding wireless connectivity led me to decide to use Raspberry Pi.
This is the frame I designed:
Required Materials
After deciding on the controller to use, the rest of the components need to be selected. 3 x Tower Pro SG-5010 servos (for legs and tilt) 1 x Tower Pro SG-90 micro servo (for head) 1 x Raspberry Pi 2 (with USB WiFi dongle) or Raspberry Pi 3 HC-SR04 ultrasonic sensor – this is the obstacle detection sensor. Acrylic board 1/2″ x 1/8″ aluminum rods screws and nuts battery. The servos should have a different power supply than the Raspberry Pi, my Raspberry Pi used a small power bank.
Let’s Start Our Tutorial
The hexapod robot consists mainly of three parts: the body (platform), walking legs, and head.
Building the Platform
This is an example layout that can be used to build the walker body. I used acrylic board as my platform. The details of the legs are as follows.
Attaching the Legs
This is a layout for the legs. I used 1/2″ x 1/8″ aluminum strips. The legs should be sturdy enough to support the weight of the hexapod walker. Please do not use plastic!
These are the tilted legs:
Installing the Raspberry Pi and Head
I drilled holes in the acrylic board and connected the Raspberry Pi with screws and nuts. The head consists of an ultrasonic sensor and a micro servo connected to the circuit board. I used hot glue to attach the micro servo to the sensor:
Look at the details of the leg movements:
Wiring
Here is my connection table:
tilt servo - > GPIO4
right leg -> GPIO21
left leg -> GPIO6
head -> GPIO26
HC-SR04 trigger - > GPIO23
HC-SR04 echo - > GPIO24
Because the GPIO of the Raspberry Pi cannot accept voltages greater than 3.3V, a voltage divider needs to be added for the echo connection of the Raspberry Pi.
I also added a circuit board with male and female connectors to make the wiring cleaner. This is the fully assembled hexapod walker:
Software
Pigpio for Servo Control
Pigpio is a Python library for controlling servos, install it by connecting to the Raspberry Pi via SSH.
12345 | wget http: //abyz .co.uk /rpi/pigpio/pigpio .zip unzip pigpio.zip cd PIGPIO make sudo make install |
Pigpio runs in the background, you need to run it before using Pigpio.
1 | pigpiod |
Set contrab:
1 | sudo crontab -e |
Add at the end
1 | @reboot /usr/local/bin/pigpiod |
Apache for Server
Install Apache for the Raspberry Pi for WiFi control:
1 | sudo apt-get install apache2 -y |
This will create a directory /var/www/html/ that contains the control page. You can connect to the Raspberry Pi using a browser. The RPi rover robot allows you to control the Raspberry Pi from your phone.
Python Program
Below is the robot control program.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 | #!/usr/bin/python import RPi.GPIO as GPIO import pigpio import time import sys import os import signal GPIO.setmode(GPIO.BCM) GPIO.setwarnings( False ) tilt = 4 br = 21 bl = 6 trig = 23 echo = 24 head = 26 GPIO.setup(trig, GPIO.OUT) GPIO.setup(echo, GPIO.IN) pi = pigpio.pi() def backward(): pi.set_servo_pulsewidth(tilt, 800 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(bl, 800 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(tilt, 2000 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(br, 1800 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(tilt, 1500 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(bl, 1500 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(br, 1500 ) time.sleep( 0.15 ) return ; def forward(): pi.set_servo_pulsewidth(tilt, 800 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(bl, 1800 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(tilt, 2000 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(br, 800 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(tilt, 1500 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(bl, 1500 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(br, 1500 ) time.sleep( 0.15 ) return ; def left(): pi.set_servo_pulsewidth(tilt, 800 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(bl, 1800 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(tilt, 2000 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(br, 1800 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(tilt, 1500 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(bl, 1500 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(br, 1500 ) time.sleep( 0.15 ) return ; def stop(): pi.set_servo_pulsewidth(tilt, 0 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(bl, 0 ) time.sleep( 0.15 ) pi.set_servo_pulsewidth(br, 0 ) time.sleep( 0.15 ) return def obstacleDetected(): backward() backward() backward() backward() backward() right() right() right() return def turnHead(): pi.set_servo_pulsewidth(head, 700 ) time.sleep( 0.5 ) pi.set_servo_pulsewidth(head, 2100 ) time.sleep( 0.5 ) pi.set_servo_pulsewidth(head, 1500 ) time.sleep( 0.5 ) return def autoMode(): print ( "Running in auto mode!" ) turnHead() time.sleep( 0.5 ) GPIO.output(trig, 0 ) time.sleep( 0.5 ) GPIO.output(trig, 1 ) time.sleep( 0.00001 ) GPIO.output(trig, 0 ) while GPIO. input (echo) = = 0 : pulse_start = time.time() while GPIO. input (echo) = = 1 : pulse_end = time.time() pulse_duration = pulse_end - pulse_start distance = pulse_duration * 17150 distance = round (distance, 2 ) if distance > 1 and distance < 35 : obstacleDetected() else : forward() forward() forward() pi.set_servo_pulsewidth(head, 2100 ) time.sleep( 0.5 ) return def manualMode(): move = str (sys.argv[ 2 ]) if move = = "F" or move = = "f" : print ( "Moving forward!" ) forward() elif move = = "B" or move = = "b" : print ( "Moving backward!" ) backward() elif move = = "L" or move = = "l" : print ( "Moving left!" ) left() elif move = = "R" or move = = "r" : print ( "Moving right!" ) right() else : print ( "Invalid argument!" ) return def main(): opt = str (sys.argv[ 1 ]) if opt = = "A" or opt = = "a" : autoMode() elif opt = = "M" or opt = = "m" : manualMode() return while True : main() GPIO.cleanup() pi.stop() |
You can test the robot control via terminal commands, for example, to make it walk forward you can use
1 | python hexapod.py m f |
Of course, formal use requires controlling it with a phone. I have deployed the program on Apache, visit my GitHub: https://github.com/kurimawxx00/raspberry-pi-hexapod-walker to get it. Below is a screenshot of the WebUI:
How to Operate
-
Find the IP address of the Raspberry Pi.
-
Use a mobile browser to access this IP, for example, 192.168.1.90/hexapod.
-
Control the robot using the WebUI
Enjoy!
This article originated from: http://shumeipai.nxez.com/2017/08/07/hexapod-walker-raspberry-pi.html Click to read the original text
Limited time resource download: Reply “Tutorial” to get the microcontroller e-book, reply “Simulation” to get Proteus simulation materials.
Recommended Popular Articles
Reply with the numbers below or click directly to get related articles:
001:《Must-read for Microcontroller Beginners》
002:《Words from Zhou Ligong to Young People Learning Microcontrollers》
003:《Expert Discussion: The Difficulty of Software and Hardware Entry and Mastery Time Span》
004:《Reflections on Learning 51 Microcontroller; Recommended Learning Materials; Essential Programs》
005:《Comparison of Several Microcontrollers Used》
006:《ARM+LINUX Learning Route (Learning Order, Knowledge Points, and Book Recommendations)》
007:《Differences and Connections between ARM/DSP/FPGA/CPLD/SOPC/SOC》
008:《Fun Electronic Production: Food Power Generation in the Hands of Artists – Electronic DIY》
009:《My Experience: From a Production Line Worker to a Microcontroller Engineer》
010:《A Friend Brought Back a Toolbox from Germany for 200,000》
Click the bottom left corner “Read Original“, to enterForum for Discussion!!!