In [1]:
%matplotlib inline
In [7]:
from __future__ import print_function
from __future__ import division
import matplotlib.pyplot as plt
import numpy as np
import sys
sys.path.insert(0, '../..')
from math import pi, sqrt
from Quadruped import Quadruped
from Gait import DiscreteRippleGait, ContinousRippleGait
In [3]:
data = {
# 'serialPort': '/dev/tty.usbserial-A5004Flb',
'legLengths': {
'coxaLength': 45,
'femurLength': 55,
'tibiaLength': 104
},
'legAngleLimits': [[-90, 90], [-90, 90], [-180, 0]],
'legOffset': [150, 150, 150+90]
}
robot = Quadruped(data)
leg = robot.legs[0].foot0
Now create a gait and a command to execute for one complete duty cycle. This will produce both the foot positions (x,y,z) and the servo angles ($\theta_1$,$\theta_2$,$\theta_3$) for each step sequence.
In [13]:
# Edit this command for linear [mm] or angular [rads] movements.
# cmd = {'linear': [0,0], 'angle': pi/4}
cmd = {'linear': [50,50], 'angle': 0}
height = 25 # height the foot is lifted during movement in mm
# gait = ContinousRippleGait(height, leg)
gait = DiscreteRippleGait(height, leg)
alpha = 1.0
pos = []
for i in range(0,12):
p = gait.eachLeg(i,cmd)
pos.append(p)
print('pos: {:.2f} {:.2f} {:.2f}'.format(*p))
In [14]:
angle = []
for p in pos:
# print('pos: {:.2f} {:.2f} {:.2f}'.format(*p))
a = robot.legs[0].move(*p)
print('angle: {:.2f} {:.2f} {:.2f}'.format(*a))
if a:
angle.append(a)
In [15]:
px = []
py = []
pz = []
for p in pos:
px.append(p[0])
py.append(p[1])
pz.append(p[2])
# pz.append(sqrt(p[0]**2+p[1]**2))
plt.subplot(2,2,1);
plt.plot(px);
plt.ylabel('x');
plt.subplot(2,2,2);
plt.plot(py);
plt.ylabel('y');
plt.subplot(2,2,3);
plt.plot(pz);
plt.ylabel('z');
plt.subplot(2,2,4);
plt.plot(px,py);
plt.ylabel('y');
plt.xlabel('x');
In [8]:
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot(px, py, pz);
In [9]:
t1 = []
t2 = []
t3 = []
for a in angle:
t1.append(a[0])
t2.append(a[1])
t3.append(a[2])
plt.subplot(2,2,1);
plt.plot(t1)
plt.ylabel('$\\theta_1$')
plt.subplot(2,2,2)
plt.plot(t2)
plt.ylabel('$\\theta_2$')
plt.subplot(2,2,3);
plt.plot(t3)
plt.ylabel('$\\theta_3$');
# plt.subplot(2,2,4);
# plt.plot(px,py)
# plt.ylabel('y')
# plt.xlabel('x')
In [10]:
print('Number of points: {}'.format(len(angle)))
print('-----------------------')
for a in angle:
print('{:.2f} {:.2f} {:.2f}'.format(*a))
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.