Spring 2016 Velociraptor: Walking Code #1

By Ashlee Chang (E&C)

Table of Contents

Fulfilling Requirements

Level 1 requirements #4 is stated as follows:

The Velociraptor shall be able to statically walk on all surfaces of the course.

The Arduino software, which uses much of C++ programming language, will be used to construct and upload the code onto the Arduino microcontroller.

Coding Summary

This blog will focus on the main walking code for the velociraptor. In the future, a collection of codes must be integrated into the final code in order to meet all the level one requirements. Below is a complete list of the main walking code and all future codes with a short description:

  1. Main walking code: This is for static walking (i.e. upon telling the velociraptor to stop, the velociraptor will be able to balance in its current state).
  2. Walking fast: The main walking code will be modified to have shorter delay times. In addition, the head and tail will not swing in full motion, as the velociraptors momentum will be used for balance.
  3. Sensing – objects: Upon close object detection using the ultrasonic sensor, the velociraptor will halt.
  4. Turning: The user will be able to tell the velociraptor to turn, whether it be because the velociraptor halted in front of an object or at any given time.
  5. Sensing – incline: Upon sensing an incline using an accelerometer, the velociraptor will adapt with a new walking code with its body closer to the floor and smaller steps for balance.

Calibration

callibration

Respective servo degrees of freedom

Servos are limited to movement from 0* to 180*, unable to make a full rotation. Thus, the servos had to be calibrated in order to move in the desired directions. In order to calibrate the servos, they were first connected to the Arduino microcontroller and written to 90*. This way, it is certain that any movements 45* in either direction from this initial calibration will be possible. After calibration, the velociraptor legs were fastened on.

Flaws of the MicroBiPed

Below are visualizations of the Japanese velociraptor Titrus III (our team’s goal), the MicroBiPed of last semester, and the preliminary walking code for the velociraptor.

ezgif.com-video-to-gif (1)

Titrus III walking (https://www.youtube.com/watch?v=GxVv4WNlXMA)

ezgif.com-video-to-gif (2)

MicroBiPed walking (https://www.youtube.com/watch?v=3sMzl35wO98)

ezgif.com-video-to-gif

Velociraptor walking (preliminary code)

Observe the Titrus III. As the back leg is taking a step, the front leg is stationary. However, even though the front leg is stationary, the servos are still moving! As noted in the MicroBiPed and the preliminary velociraptor walking code above, the non-walking-leg servos are not moving. What does this in turn cause? As one foot is taking a step forward, the other foot gets dragged behind, hindering the robot from effectively moving forward. This is the biggest flaw of the MicroBiPed in terms of coding. The purpose of the moving servos of the stationary leg is to propel the velociraptor’s body forward, as opposed to a stationary leg without moving servos dragging the velociraptor behind. Although this causes great complexity in the coding for walking as all four servos are moving simultaneously (and seeing that codes are read line by line), implementing this improvement will no doubt result in an actual walking velociraptor.

Approach

approach

Process for coding the walking

Above shows a block diagram used in the process of compiling the walking code. The velociraptor servos are initialized at [110* 70* 70* 110*] for [front-left back-left front-right back-right]. It is equally important to keep the velociraptor tall enough as to take larger steps and short enough as to ensure the velociraptor keeps balance. From this initial position, a succession of degrees were written for the velociraptor to take a step. The front servo ensures the foot will rise in the air, and the back servo ensures the foot will push out for a large step. After a simple stepping code, a code had to be made for moving the servos of the other leg while the first leg was taking its step. With such complex math due to the different leg sizes and multiple moving pieces, this part was carried out by trial and error. The front and back servos had to complement each other as to keep the foot completely parallel to the floor. Implementing both the step and the perpendicular leg movement in one leg was quite simple, but integrating this motion in both legs at the same time proved to be quite difficult. Thus, a timing diagram was made. Observing that the Titrus III takes about 3.2 seconds for one full walking loop, the velociraptor’s walking loop was set to be close at 3.6 seconds. Initially, the walking code loop conditions were based on a certain servo’s angle. However, as the looping became more complex with multiple servos moving at once, the looping condition variable was changed to one that kept track of time (i.e. the delays), thus utilizing the timing diagram. Lastly, each servo within a loop had to move at a different pace, whether it be double, triple, or even 1.5 times the rate of another servo in its loop. Thus, loops had to be nested within each other, or some servos had to increase or decrease by more than just +1 or -1 degree at a time, in order to achieve the desired degree changes per section of time.

Timing Diagram

timing

Timing diagram

Because all four leg servos will be moving simultaneously, a timing diagram was made as to allow a timing variable be the looping condition in the velociraptor code. A full looping cycle was set to be 3600 ms, broken into 9 segments of 400 ms (meaning there are 9 total main loops in the walking code). The diagram lists the total time elapsed for a full walking loop (which is used as the timing variable in the code), delay in between each segment of code, the degrees of each servo at a certain time, and the change in degrees of each servo over the period of 400 ms. The yellow and blue font colored numbers indicate when that leg is taking a step (when the foot is on the floor, when the foot is in the air, and when the foot is on the floor again). Note there is 400*3=1200 ms in between the stepping of one foot and the other, which will be saved later for the movement of the head and tail responsible for relocating the center of mass on the stationary foot.

Debugging

Although the servos have the capability to rotate from 0* to 180*, the velociraptor leg joints are connected in such a way that limits the servos degree of freedom even more-so. Any slight error in the coding that moves the servo to an angle that the leg joints aren’t meant to handle can cause damage to the servo gears, or if the torque is powerful enough, could potentially snap the legs of the velociraptor. That is why debugging the program on the Arduino without physically connecting power to the servos is important. Serial.print( ) was frequently used to test the program and ensure all variables were as expected.

debugging

Debugging the program and checking the serial monitor

Code Structure

The first section of the code includes the servo library and creates (currently) four servo objects to control each servo. The second section of the code (void setup) initializes variables, attaches the servos to the Arduino pins, writes the initialized angles tot he servo, and includes a Serial.begin(57600) for debugging purposes. Also, the first segment of the walking code is placed here. This is because the velociraptor will initially be in a stance where it is balanced on two feet with the head and tail both facing forward. It is coded so the right foot will take a step first while the front-left and back-left servos are kept at 110* and 70*. Finally when the front-right and back-right servos reach 85* and 140* (at total time = 0), the loop will begin. In the third section of the code (void loop), the left foot will take a step while the right foot re-initializes while keeping perpendicular to the floor. Then, the right foot will take a step while the left foot re-initializes while keeping perpendicular to the floor. This segment of the code repeats.

Walking Code NotePad File

Results

Compare the preliminary walking code versus the improved walking code (see first GIF of the velociraptor). The first prototype has some joint dimensions that are slightly off, and some imperfections on connections and drill hole sizes, thus the velociraptor appears to walk lopsided. Rest assured, the angle movements on each leg mirror each other exactly in the code, which will reflect on the next prototype and/or final product. The prototype must be held as the walking takes place, as there is a head and tail installed for balance. Examine how the stationary foot’s moving servos push the velociraptor forward.

ezgif.com-video-to-gif

Improved walking algorithm