# Introduction

A distinguishing feature of legged robots is their ability to move in a variety of ways. While wheeled or treaded robots or typically limited to simple "forwards-backwards-turning" movement, legged robots have infinitely many ways they can configure their joints in an effort to produce controlled motion. It is this feature that allows biologically inspired legged robots to climb, swim, and run into places many other robots cannot.

This experiment is originally devised by Dr. G. Clark Heynes for summer interns in Kodlab. Students are introduced to the basic principle that lets the platforms in RHex family operate over a rich and diverse set of terrains: The Buehler Clock [1]. In this experiment, students, first, investigate various parameters that shape the clock. Then, they use Dynamism interface to tune a walking gait that uses alternating tripods.

**Lab Task:** Implement and tune a Buehler clock based alternating tripod gate.

# Prelab

RHex’s gait is produced by alternating phases, a slow stance phase followed by a fast recirculation phase, which together comprise the Buehler Clock. When appropriately phased amongst the robot’s six legs, these motions create an “alternating tripod” gait that produces stable locomotion.

^{The Buehler clock, plotted on the torus.
The horizontal axis corresponds to phase (like time, but cyclic)
while the vertical axis is leg motor angle.} |
---|

**Answer the following questions:**

- Figure 1 shows a plot of the Buehler clock for a single leg, noting several gait parameters,$\phi_{0}$,$\phi_{s}$ and $\delta$. What do these various parameters control?
- Write down the mathematical function $\phi = f(\theta)$ which produces a Buehler clock. $\phi$ is the motor angle output, while $\theta$ is
*the input phase*, similar to time. - Let $\theta = s\,t\ (mod\ 2\pi )$ where $t$ is time. What does the parameter $s$ control?
- What is $\frac{d}{dt}\,f(\theta)$? Assume that $\theta$ is defined based upon time, $t$, in the above question.
- Let $f_1 (\theta)$ be the Buehler clock for one set of the legs. How would one create $f_2 (\theta)$, the clock function for the other set of legs where the two sets of legs are perfectly out of phase? To which legs do you apply functions $f_1$ and $f_2$ ?

# Robot Control via Dynamism

In the setup for this problem, you will launch a Dynamism “server” which runs on the robot. You will write a computer program (in either Python or Matlab) that runs on your laptop and communicates with the server to have the robot move.

^{Labeling of the legs on RHex architecture} |
---|

## Task 1:

Shown below are two simple Dynamism programs. Please adapt either the Python or Matlab script as instructed to have the robot calibrate, stand, and sit. For more information on Dynamism, you can visit Dynamism wiki page. After instructing the robot to do each command, you must pause your control program to allow the robot to finish its task. Two or three seconds should be sufficient. Alternatively, you can use user prompts to switch between successive the states of operation.

**Python**

import dy import math import time import sys # connect to the robot, whose name may be given as a parameter, at port 8650 hostname = 'localhost' host = None if len(sys.argv) >= 2: hostname = sys.argv[1] host = dy.network.connect(hostname,8650) ds = dy.data.path(hostname) # ... write code to have the robot calibrate itself, stand up, # and sit down, with pauses in between each. # Hint: time.sleep(x) will pause for x seconds. # Hint: raw_input('Prompt message') will pause till the user hits ENTER

**Matlab**

```
addpath([getenv('DY_DIRECTORY') '/src/dy-matlab'])
% connect to robot named 'junior1' at port 8650
dy_network_connect('junior1',8650)
% ... write code to have the robot calibrate itself, stand up,
% and sit down, with pauses in between each.
% Hint: pause(x) will pause for x seconds.
```

## Task 2:

Take your functions, $f_1(\theta)$ and $f_2 (\theta)$, and write them as either a Python or MatLab function that you can query. Have this function also output the velocity of each function as well. Note that `phi_dot` is equivalent to $\frac{d}{dt}\, f(\theta)$.

**Python**

def buehler_clock_1(theta): # compute phi, phi_dot return [phi,phi_dot] def buehler_clock_2(theta): # compute phi, phi_dot return [phi,phi_dot]

**Matlab**

```
function [phi,phi_dot] = buehler_clock_1(theta)
% compute phi, phi_dot
function [phi,phi_dot] = buehler_clock_2(theta)
% compute phi, phi_dot
```

## Task 3:

Take your first program which made the robot stand and sit. Now, using your programmed Buehler clock functions, make the robot stand, run the gait for several seconds, properly stop in a standing posture, and then sit. This program should be added to the program above, right after the robot finishes standing.

Below is a simple example of making the robot's legs spin for several seconds. Note that, in order to finish the locomotion in a standing posture, you will need a simple function that stops the buehler clock in zero phase and waits for the other buehler clock to reach the zero phase before terminating your buehler clock implementation.

**Python**

# create database elements for leg desired position and velocity dyposd = dy.data.create_array_at(ds,dy.DY_FLOAT, 1, [6], 'leg.pos_d'); dyveld = dy.data.create_array_at(ds,dy.DY_FLOAT, 1, [6], 'leg.vel_d'); for i in range(500): curtime = i*0.01; pos = 2*math.pi*curtime; vel = 2*math.pi; for j in range(6): # set the position and velocity dy.data.set_float(dyposd,pos,j) dy.data.set_float(dyveld,vel,j) dy.network.push_to(host, '%s.leg.pos_d' % hostname) dy.network.push_to(host, '%s.leg.vel_d' % hostname) time.sleep(0.01)

**Matlab**

```
% create database elements for leg desired position and velocity
dy_data_create('DY_FLOAT',1,[6],'junior1.leg.pos_d');
dy_data_create('DY_FLOAT',1,[6],'junior1.leg.vel_d');
for i=1:500
curtime = i*0.01;
pos = 2*pi*curtime;
vel = 2*pi;
dy_data_set('junior1.leg.pos_d', ones(6,1)*pos);
dy_data_set('junior1.leg.vel_d', ones(6,1)*vel);
dy_network_push('junior1.leg.pos_d')
dy_network_push('junior1.leg.vel_d')
pause(0.01)
end
```

## Task 4:

Play around with the parameters $s$, $\phi_0$, $\phi_s$, and $\delta$. Can you find a specific set that produces good walking?

# Deliverables

## Prelab

To be completed and posted to the Blackboard by class on Thursday, 1/27.

## Demonstration

- Show the instructor that your group can use your script to run Junior without hitting its body on the ground.

## Competition

- There will be a competition among the groups where robots are supposed to run straight for ten feet as fast as they can. The fastest group will get a bonus point.
- You can ask TA for extra robot time to get prepared for the competition.

## Report

After completing Tasks 1 through 4, write a report summarizing your procedure and results. The goal of your report is to inform the reader of what you did and convince them of any conclusions you have made. In this report, be sure to:

- Write an introduction to bring the reader into the report.
- Briefly explain your implementation for the RHex gait. You are encouraged to go through the blocks of your code and explain the idea behind.
- Discuss your procedure on tuning a running gait.
- Discuss your conclusions:
- In this experiment, we tuned an alternating tripod gait for RHex using the Buehler clock. How does each of the four parameters affect the performance?
- What are the advantages and disadvantages of Buehler clock?
- Can you come up with any other method/idea for getting a similar behavior from the robot?
- Can you explain when and why the robot tends to stray?

- Write a conclusion to wrap up your ideas and present your results one last time.