Merge branch 'lars' of lbsadmin/HIPPIE into master
This commit is contained in:
commit
6f0d873c9c
612
Hippie.cpp
Normal file
612
Hippie.cpp
Normal file
@ -0,0 +1,612 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
#include "Hippie.h"
|
||||
#include <Oscillator.h>
|
||||
|
||||
|
||||
|
||||
void Hippie::init(int YL, int YR, int RL, int RR, int Buzzer) {
|
||||
|
||||
servo_pins[0] = YL;
|
||||
servo_pins[1] = YR;
|
||||
servo_pins[2] = RL;
|
||||
servo_pins[3] = RR;
|
||||
|
||||
attachServos();
|
||||
isHippieResting=false;
|
||||
|
||||
|
||||
for (int i = 0; i < 4; i++) servo_position[i] = 90;
|
||||
|
||||
|
||||
//Buzzer & noise sensor pins:
|
||||
pinBuzzer = Buzzer;
|
||||
|
||||
pinMode(Buzzer,OUTPUT);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
//-- ATTACH & DETACH FUNCTIONS ----------------------------------//
|
||||
///////////////////////////////////////////////////////////////////
|
||||
void Hippie::attachServos(){
|
||||
servo[0].attach(servo_pins[0]);
|
||||
servo[1].attach(servo_pins[1]);
|
||||
servo[2].attach(servo_pins[2]);
|
||||
servo[3].attach(servo_pins[3]);
|
||||
}
|
||||
|
||||
void Hippie::detachServos(){
|
||||
servo[0].detach();
|
||||
servo[1].detach();
|
||||
servo[2].detach();
|
||||
servo[3].detach();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
//-- BASIC MOTION FUNCTIONS -------------------------------------//
|
||||
///////////////////////////////////////////////////////////////////
|
||||
void Hippie::_moveServos(int time, int servo_target[]) {
|
||||
|
||||
attachServos();
|
||||
if(getRestState()==true){
|
||||
setRestState(false);
|
||||
}
|
||||
|
||||
if(time>10){
|
||||
for (int i = 0; i < 4; i++) increment[i] = ((servo_target[i]) - servo_position[i]) / (time / 10.0);
|
||||
final_time = millis() + time;
|
||||
|
||||
for (int iteration = 1; millis() < final_time; iteration++) {
|
||||
partial_time = millis() + 10;
|
||||
for (int i = 0; i < 4; i++) servo[i].SetPosition(servo_position[i] + (iteration * increment[i]));
|
||||
while (millis() < partial_time); //pause
|
||||
}
|
||||
}
|
||||
else{
|
||||
for (int i = 0; i < 4; i++) servo[i].SetPosition(servo_target[i]);
|
||||
}
|
||||
for (int i = 0; i < 4; i++) servo_position[i] = servo_target[i];
|
||||
}
|
||||
|
||||
|
||||
void Hippie::oscillateServos(int A[4], int O[4], int T, double phase_diff[4], float cycle=1){
|
||||
|
||||
for (int i=0; i<4; i++) {
|
||||
servo[i].SetO(O[i]);
|
||||
servo[i].SetA(A[i]);
|
||||
servo[i].SetT(T);
|
||||
servo[i].SetPh(phase_diff[i]);
|
||||
}
|
||||
double ref=millis();
|
||||
for (double x=ref; x<=T*cycle+ref; x=millis()){
|
||||
for (int i=0; i<4; i++){
|
||||
servo[i].refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Hippie::_execute(int A[4], int O[4], int T, double phase_diff[4], float steps = 1.0){
|
||||
|
||||
attachServos();
|
||||
if(getRestState()==true){
|
||||
setRestState(false);
|
||||
}
|
||||
|
||||
|
||||
int cycles=(int)steps;
|
||||
|
||||
//-- Execute complete cycles
|
||||
if (cycles >= 1)
|
||||
for(int i = 0; i < cycles; i++)
|
||||
oscillateServos(A,O, T, phase_diff);
|
||||
|
||||
//-- Execute the final not complete cycle
|
||||
oscillateServos(A,O, T, phase_diff,(float)steps-cycles);
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
//-- HOME = Hippie at rest position -------------------------------//
|
||||
///////////////////////////////////////////////////////////////////
|
||||
void Hippie::home(){
|
||||
|
||||
if(isHippieResting==false){ //Go to rest position only if necessary
|
||||
|
||||
int homes[4]={90, 90, 90, 90}; //All the servos at rest position
|
||||
_moveServos(500,homes); //Move the servos in half a second
|
||||
|
||||
detachServos();
|
||||
isHippieResting=true;
|
||||
}
|
||||
}
|
||||
|
||||
bool Hippie::getRestState(){
|
||||
|
||||
return isHippieResting;
|
||||
}
|
||||
|
||||
void Hippie::setRestState(bool state){
|
||||
|
||||
isHippieResting = state;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
//-- PREDETERMINED MOTION SEQUENCES -----------------------------//
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
//---------------------------------------------------------
|
||||
//-- Hippie movement: Jump
|
||||
//-- Parameters:
|
||||
//-- steps: Number of steps
|
||||
//-- T: Period
|
||||
//---------------------------------------------------------
|
||||
void Hippie::jump(float steps, int T){
|
||||
|
||||
int up[]={90,90,165,15};
|
||||
_moveServos(T,up);
|
||||
int down[]={90,90,90,90};
|
||||
_moveServos(T,down);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
//-- Hippie Test Positions (bring feets and hips in certain position)
|
||||
//---------------------------------------------------------
|
||||
void Hippie::test_pos(){
|
||||
|
||||
int left_feet_up[4]={90,0,90,30}; //watch from view of robot: [3] = left leg ... by + value: turn right
|
||||
_moveServos(1000,left_feet_up); // [4] = right leg ... by + value: right side up
|
||||
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
//-- Hippie gait: Walking (forward or backward)
|
||||
//-- Parameters:
|
||||
//-- * steps: Number of steps
|
||||
//-- * T : Period
|
||||
//-- * Dir: Direction: FORWARD / BACKWARD
|
||||
//---------------------------------------------------------
|
||||
void Hippie::walk(float steps, int T, int dir){
|
||||
|
||||
//-- Oscillator parameters for walking
|
||||
//-- Hip sevos are in phase
|
||||
//-- Feet servos are in phase
|
||||
//-- Hip and feet are 90 degrees out of phase
|
||||
//-- -90 : Walk forward
|
||||
//-- 90 : Walk backward
|
||||
//-- Feet servos also have the same offset (for tiptoe a little bit)
|
||||
int A[4]= {30, 30, 40, 40}; //20
|
||||
int O[4] = {0, 0, 4, 30}; //-4
|
||||
double phase_diff[4] = {0, 0, DEG2RAD(dir * -90), DEG2RAD(dir * -90)};
|
||||
|
||||
if ( dir == -1) { double phase_diff[4] = {0, 0, DEG2RAD(dir * 90), DEG2RAD(dir * 90)}; }
|
||||
|
||||
//-- Let's oscillate the servos!
|
||||
_execute(A, O, T, phase_diff, steps);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
//-- Hippie gait: Turning (left or right)
|
||||
//-- Parameters:
|
||||
//-- * Steps: Number of steps
|
||||
//-- * T: Period
|
||||
//-- * Dir: Direction: LEFT / RIGHT
|
||||
//---------------------------------------------------------
|
||||
void Hippie::turn(float steps, int T, int dir){
|
||||
|
||||
//-- Same coordination than for walking (see Hippie::walk)
|
||||
//-- The Amplitudes of the hip's oscillators are not igual
|
||||
//-- When the right hip servo amplitude is higher, the steps taken by
|
||||
//-- the right leg are bigger than the left. So, the robot describes an
|
||||
//-- left arc
|
||||
int A[4]= {30, 30, 20, 20};
|
||||
int O[4] = {0, 0, 4, 30};
|
||||
double phase_diff[4] = {0, 0, DEG2RAD(-90), DEG2RAD(-90)};
|
||||
|
||||
if (dir == LEFT) {
|
||||
A[0] = 50; //-- Left hip servo
|
||||
A[1] = 10; //-- Right hip servo
|
||||
}
|
||||
else {
|
||||
A[0] = 10;
|
||||
A[1] = 50;
|
||||
A[2] = 40;
|
||||
}
|
||||
|
||||
//-- Let's oscillate the servos!
|
||||
_execute(A, O, T, phase_diff, steps);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
//-- Hippie gait: Lateral bend
|
||||
//-- Parameters:
|
||||
//-- steps: Number of bends
|
||||
//-- T: Period of one bend
|
||||
//-- dir: RIGHT=Right bend LEFT=Left bend
|
||||
//---------------------------------------------------------
|
||||
void Hippie::bend (int steps, int T, int dir){
|
||||
|
||||
//Parameters of all the movements. Default: Left bend
|
||||
int bend1[4]={90, 90, 62, 35};
|
||||
int bend2[4]={90, 90, 62, 105+60};
|
||||
int homes[4]={90, 90, 90, 90};
|
||||
|
||||
//Time of one bend, constrained in order to avoid movements too fast.
|
||||
//T=max(T, 600);
|
||||
|
||||
//Changes in the parameters if right direction is chosen
|
||||
if(dir==-1)
|
||||
{
|
||||
bend1[2]=180-35;
|
||||
bend1[3]=180-60; //Not 65. Hippie is unbalanced
|
||||
bend2[2]=180-105;
|
||||
bend2[3]=180-60;
|
||||
}
|
||||
|
||||
//Time of the bend movement. Fixed parameter to avoid falls
|
||||
int T2=800;
|
||||
|
||||
//Bend movement
|
||||
for (int i=0;i<steps;i++)
|
||||
{
|
||||
_moveServos(T2/2,bend1);
|
||||
_moveServos(T2/2,bend2);
|
||||
delay(T*0.8);
|
||||
_moveServos(500,homes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------
|
||||
//-- New Walk Move
|
||||
//-- number of steps
|
||||
//-- T: Period of one steps
|
||||
//-- dir: direction of movement
|
||||
//--------------------------------------------------------
|
||||
void Hippie::new_walk(int dir, float steps, int T){
|
||||
if(dir==1){
|
||||
// Positions of walking
|
||||
int Pos_A[4] = {90,90,180, 90};
|
||||
int Pos_B[4] = {90,90,180, 180};
|
||||
int Pos_C[4] = {90,45,90, 180};
|
||||
int Pos_D[4] = {45,45,90,90};
|
||||
|
||||
int Pos_E[4] = {45,45,30,30};
|
||||
int Pos_F[4] = {150,150,30,90};
|
||||
int Pos_G[4] = {150,150,90,90};
|
||||
|
||||
// run movements
|
||||
for (int i=0;i<steps;i++)
|
||||
{
|
||||
_moveServos(T/2, Pos_A);
|
||||
_moveServos(T/3, Pos_B);
|
||||
//delay(T);
|
||||
_moveServos(T/2, Pos_C);
|
||||
_moveServos(T/2, Pos_D);
|
||||
//delay(T);
|
||||
_moveServos(T/2, Pos_E);
|
||||
_moveServos(T/2, Pos_F);
|
||||
_moveServos(T/2, Pos_G);
|
||||
|
||||
//delay(T*3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Backwards
|
||||
if (dir == 2){
|
||||
int Pos_1[4] = {90,90,180, 90};
|
||||
int Pos_2[4] = {90,90,180, 180};
|
||||
int Pos_3[4] = {90,145,90, 180};
|
||||
int Pos_4[4] = {145,145,90,90};
|
||||
|
||||
int Pos_5[4] = {145,145,30,30};
|
||||
int Pos_6[4] = {45,45,30,90};
|
||||
int Pos_7[4] = {45,45,90,90};
|
||||
|
||||
// run movements
|
||||
for (int i=0;i<steps;i++)
|
||||
{
|
||||
_moveServos(T/2, Pos_1);
|
||||
_moveServos(T/3, Pos_2);
|
||||
//delay(T);
|
||||
_moveServos(T/2, Pos_3);
|
||||
_moveServos(T/2, Pos_4);
|
||||
//delay(T);
|
||||
_moveServos(T/2, Pos_5);
|
||||
_moveServos(T/2, Pos_6);
|
||||
_moveServos(T/2, Pos_7);
|
||||
|
||||
//delay(T*3);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------
|
||||
//-- New Turn Move
|
||||
//-- number of steps
|
||||
//-- T: Period of one steps
|
||||
//-- dir: direction of movement
|
||||
//--------------------------------------------------------
|
||||
void Hippie::new_turn(int dir, float steps, int T){
|
||||
//LEFT
|
||||
if (dir==1) {
|
||||
// Positions of turning
|
||||
int Pos_A[4] = {90,90,90, 30};
|
||||
int Pos_B[4] = {90,90,30, 30};
|
||||
int Pos_C[4] = {0,90,30,90};
|
||||
int Pos_D[4] = {0,90,90,90};
|
||||
int Pos_E[4] = {90,90,90,90};
|
||||
|
||||
// run movements
|
||||
for (int i=0;i<steps;i++)
|
||||
{
|
||||
_moveServos(T/2, Pos_A);
|
||||
_moveServos(T/3, Pos_B);
|
||||
//delay(T);
|
||||
_moveServos(T/2, Pos_C);
|
||||
_moveServos(T/2, Pos_D);
|
||||
_moveServos(T/2, Pos_E);
|
||||
}
|
||||
}
|
||||
|
||||
//RIGHT
|
||||
if (dir==2) {
|
||||
// Positions of turning
|
||||
int Pos_1[4] = {90,90,180, 90};
|
||||
int Pos_2[4] = {90,90,180, 180};
|
||||
int Pos_3[4] = {90,180,90, 180};
|
||||
int Pos_4[4] = {90,180,90,90};
|
||||
int Pos_5[4] = {90,90,90,90};
|
||||
|
||||
// run movements
|
||||
for (int i=0;i<steps;i++)
|
||||
{
|
||||
_moveServos(T/2, Pos_1);
|
||||
_moveServos(T/3, Pos_2);
|
||||
//delay(T);
|
||||
_moveServos(T/2, Pos_3);
|
||||
_moveServos(T/2, Pos_4);
|
||||
_moveServos(T/2, Pos_5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
//-- Hippie gait: Shake a leg
|
||||
//-- Parameters:
|
||||
//-- steps: Number of shakes
|
||||
//-- T: Period of one shake
|
||||
//-- dir: RIGHT=Right leg LEFT=Left leg
|
||||
//---------------------------------------------------------
|
||||
void Hippie::shakeLeg (int steps,int T,int dir){
|
||||
|
||||
//This variable change the amount of shakes
|
||||
int numberLegMoves=4;
|
||||
|
||||
//Parameters of all the movements. Default: Right leg
|
||||
int shake_leg1[4]={90, 90, 58, 35-15};
|
||||
int shake_leg2[4]={90, 90, 58, 120+30};
|
||||
int shake_leg3[4]={90, 90, 58, 60-30};
|
||||
int homes[4]={90, 90, 90, 90};
|
||||
|
||||
//Changes in the parameters if left leg is chosen
|
||||
if(dir==-1)
|
||||
{
|
||||
shake_leg1[2]=180-35;
|
||||
shake_leg1[3]=180-58;
|
||||
shake_leg2[2]=180-120;
|
||||
shake_leg2[3]=180-58;
|
||||
shake_leg3[2]=180-60;
|
||||
shake_leg3[3]=180-58;
|
||||
}
|
||||
|
||||
//Time of the bend movement. Fixed parameter to avoid falls
|
||||
int T2=1000;
|
||||
//Time of one shake, constrained in order to avoid movements too fast.
|
||||
T=T-T2;
|
||||
T=max(T,200*numberLegMoves);
|
||||
|
||||
for (int j=0; j<steps;j++)
|
||||
{
|
||||
//Bend movement
|
||||
_moveServos(T2/2,shake_leg1);
|
||||
_moveServos(T2/2,shake_leg2);
|
||||
|
||||
//Shake movement
|
||||
for (int i=0;i<numberLegMoves;i++)
|
||||
{
|
||||
_moveServos(T/(2*numberLegMoves),shake_leg3);
|
||||
_moveServos(T/(2*numberLegMoves),shake_leg2);
|
||||
}
|
||||
_moveServos(500,homes); //Return to home position
|
||||
}
|
||||
|
||||
delay(T);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
//-- Hippie movement: up & down
|
||||
//-- Parameters:
|
||||
//-- * steps: Number of jumps
|
||||
//-- * T: Period
|
||||
//-- * h: Jump height: SMALL / MEDIUM / BIG
|
||||
//-- (or a number in degrees 0 - 90)
|
||||
//---------------------------------------------------------
|
||||
void Hippie::updown(float steps, int T, int h){
|
||||
|
||||
//-- Both feet are 180 degrees out of phase
|
||||
//-- Feet amplitude and offset are the same
|
||||
//-- Initial phase for the right foot is -90, so that it starts
|
||||
//-- in one extreme position (not in the middle)
|
||||
int A[4]= {0, 0, h, h};
|
||||
int O[4] = {0, 0, h, -h+50};
|
||||
double phase_diff[4] = {0, 0, DEG2RAD(-90), DEG2RAD(90)};
|
||||
|
||||
//-- Let's oscillate the servos!
|
||||
_execute(A, O, T, phase_diff, steps);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
//-- Hippie movement: swinging side to side
|
||||
//-- Parameters:
|
||||
//-- steps: Number of steps
|
||||
//-- T : Period
|
||||
//-- h : Amount of swing (from 0 to 50 aprox)
|
||||
//---------------------------------------------------------
|
||||
void Hippie::swing(float steps, int T, int h){
|
||||
|
||||
//-- Both feets are in phase. The offset is half the amplitude
|
||||
//-- It causes the robot to swing from side to side
|
||||
int A[4]= {0, 0, h, h};
|
||||
int O[4] = {0, 0, h/2-20, -h/2+50-20};
|
||||
double phase_diff[4] = {0, 0, DEG2RAD(0), DEG2RAD(0)};
|
||||
|
||||
//-- Let's oscillate the servos!
|
||||
_execute(A, O, T, phase_diff, steps);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
//-- Hippie movement: swinging side to side without touching the floor with the heel
|
||||
//-- Parameters:
|
||||
//-- steps: Number of steps
|
||||
//-- T : Period
|
||||
//-- h : Amount of swing (from 0 to 50 aprox)
|
||||
//---------------------------------------------------------
|
||||
void Hippie::tiptoeSwing(float steps, int T, int h){
|
||||
|
||||
//-- Both feets are in phase. The offset is not half the amplitude in order to tiptoe
|
||||
//-- It causes the robot to swing from side to side
|
||||
int A[4]= {0, 0, h, h};
|
||||
int O[4] = {0, 0, h-20, -h+50};
|
||||
double phase_diff[4] = {0, 0, 0, 0};
|
||||
|
||||
//-- Let's oscillate the servos!
|
||||
_execute(A, O, T, phase_diff, steps);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
//-- Hippie gait: Jitter
|
||||
//-- Parameters:
|
||||
//-- steps: Number of jitters
|
||||
//-- T: Period of one jitter
|
||||
//-- h: height (Values between 5 - 25)
|
||||
//---------------------------------------------------------
|
||||
void Hippie::jitter(float steps, int T, int h){
|
||||
|
||||
//-- Both feet are 180 degrees out of phase
|
||||
//-- Feet amplitude and offset are the same
|
||||
//-- Initial phase for the right foot is -90, so that it starts
|
||||
//-- in one extreme position (not in the middle)
|
||||
//-- h is constrained to avoid hit the feets
|
||||
h=min(25,h);
|
||||
int A[4]= {h, h, 0, 0};
|
||||
int O[4] = {0, 0, 0, 0};
|
||||
double phase_diff[4] = {DEG2RAD(-90), DEG2RAD(90), 0, 0};
|
||||
|
||||
//-- Let's oscillate the servos!
|
||||
_execute(A, O, T, phase_diff, steps);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
//-- Hippie gait: Ascending & turn (Jitter while up&down)
|
||||
//-- Parameters:
|
||||
//-- steps: Number of bends
|
||||
//-- T: Period of one bend
|
||||
//-- h: height (Values between 5 - 15)
|
||||
//---------------------------------------------------------
|
||||
void Hippie::ascendingTurn(float steps, int T, int h){
|
||||
|
||||
//-- Both feet and legs are 180 degrees out of phase
|
||||
//-- Initial phase for the right foot is -90, so that it starts
|
||||
//-- in one extreme position (not in the middle)
|
||||
//-- h is constrained to avoid hit the feets
|
||||
h=min(13,h);
|
||||
int A[4]= {h, h, h, h};
|
||||
int O[4] = {0, 0, h+4, -h+40};
|
||||
double phase_diff[4] = {DEG2RAD(-90), DEG2RAD(90), DEG2RAD(-90), DEG2RAD(90)};
|
||||
|
||||
//-- Let's oscillate the servos!
|
||||
_execute(A, O, T, phase_diff, steps);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
//-- Hippie gait: Moonwalker. Hippie moves like Michael Jackson
|
||||
//-- Parameters:
|
||||
//-- Steps: Number of steps
|
||||
//-- T: Period
|
||||
//-- h: Height. Typical valures between 15 and 40
|
||||
//-- dir: Direction: LEFT / RIGHT
|
||||
//---------------------------------------------------------
|
||||
void Hippie::moonwalker(float steps, int T, int h, int dir){
|
||||
|
||||
//-- This motion is similar to that of the caterpillar robots: A travelling
|
||||
//-- wave moving from one side to another
|
||||
//-- The two Hippie's feet are equivalent to a minimal configuration. It is known
|
||||
//-- that 2 servos can move like a worm if they are 120 degrees out of phase
|
||||
//-- In the example of Hippie, the two feet are mirrored so that we have:
|
||||
//-- 180 - 120 = 60 degrees. The actual phase difference given to the oscillators
|
||||
//-- is 60 degrees.
|
||||
//-- Both amplitudes are equal. The offset is half the amplitud plus a little bit of
|
||||
//- offset so that the robot tiptoe lightly
|
||||
|
||||
int A[4]= {0, 0, h, h};
|
||||
int O[4] = {0, 0, h/2+2, -h/2 -2+60};
|
||||
int phi = -dir * 90;
|
||||
double phase_diff[4] = {0, 0, DEG2RAD(phi), DEG2RAD(-60 * dir + phi)};
|
||||
|
||||
//-- Let's oscillate the servos!
|
||||
_execute(A, O, T, phase_diff, steps);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------
|
||||
//-- Hippie gait: Crusaito. A mixture between moonwalker and walk
|
||||
//-- Parameters:
|
||||
//-- steps: Number of steps
|
||||
//-- T: Period
|
||||
//-- h: height (Values between 20 - 50)
|
||||
//-- dir: Direction: LEFT / RIGHT
|
||||
//-----------------------------------------------------------
|
||||
void Hippie::crusaito(float steps, int T, int h, int dir){
|
||||
|
||||
int A[4]= {25, 25, h, h};
|
||||
int O[4] = {0, 0, h/2+ 4, -h/2 - 4+30};
|
||||
double phase_diff[4] = {90, 90, DEG2RAD(0), DEG2RAD(-60 * dir)};
|
||||
|
||||
//-- Let's oscillate the servos!
|
||||
_execute(A, O, T, phase_diff, steps);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
//-- Hippie gait: Flapping
|
||||
//-- Parameters:
|
||||
//-- steps: Number of steps
|
||||
//-- T: Period
|
||||
//-- h: height (Values between 10 - 30)
|
||||
//-- dir: direction: FOREWARD, BACKWARD
|
||||
//---------------------------------------------------------
|
||||
void Hippie::flapping(float steps, int T, int h, int dir){
|
||||
|
||||
int A[4]= {12+10, 12+10, h, h};
|
||||
int O[4] = {0, 0, h - 10, -h + 10+60};
|
||||
double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180), DEG2RAD(-90 * dir), DEG2RAD(90 * dir)};
|
||||
|
||||
//-- Let's oscillate the servos!
|
||||
_execute(A, O, T, phase_diff, steps);
|
||||
}
|
||||
|
93
Hippie.h
Normal file
93
Hippie.h
Normal file
@ -0,0 +1,93 @@
|
||||
#ifndef Hippie_h
|
||||
#define Hippie_h
|
||||
|
||||
#include <ESP32_Servo.h>
|
||||
#include <Oscillator.h>
|
||||
|
||||
#include "Hippie_mouths.h"
|
||||
#include "Hippie_sounds.h"
|
||||
#include "Hippie_gestures.h"
|
||||
|
||||
|
||||
//-- Constants
|
||||
#define FORWARD 1
|
||||
#define BACKWARD -1
|
||||
#define LEFT 1
|
||||
#define RIGHT -1
|
||||
#define SMALL 5
|
||||
#define MEDIUM 15
|
||||
#define BIG 30
|
||||
|
||||
#define PIN_Buzzer 10
|
||||
#define PIN_Trigger 8
|
||||
#define PIN_Echo 9
|
||||
#define PIN_NoiseSensor A6
|
||||
|
||||
|
||||
class Hippie
|
||||
{
|
||||
public:
|
||||
|
||||
//-- Hippie initialization
|
||||
void init(int YL, int YR, int RL, int RR, int Buzzer=PIN_Buzzer);
|
||||
|
||||
//-- Attach & detach functions
|
||||
void attachServos();
|
||||
void detachServos();
|
||||
|
||||
//-- Predetermined Motion Functions
|
||||
void _moveServos(int time, int servo_target[]);
|
||||
void oscillateServos(int A[4], int O[4], int T, double phase_diff[4], float cycle);
|
||||
|
||||
//-- HOME = Hippie at rest position
|
||||
void home();
|
||||
bool getRestState();
|
||||
void setRestState(bool state);
|
||||
|
||||
//-- Predetermined Motion Functions
|
||||
void jump(float steps=1, int T = 600);
|
||||
|
||||
void walk(float steps=4, int T=1000, int dir = FORWARD);
|
||||
void turn(float steps=4, int T=1000, int dir = LEFT);
|
||||
void bend (int steps=1, int T=1400, int dir=LEFT);
|
||||
void shakeLeg (int steps=1, int T = 2000, int dir=RIGHT);
|
||||
|
||||
void updown(float steps=1, int T=1000, int h = 40);
|
||||
void swing(float steps=1, int T=1000, int h=40);
|
||||
void tiptoeSwing(float steps=1, int T=900, int h=40);
|
||||
void jitter(float steps=1, int T=500, int h=50);
|
||||
void ascendingTurn(float steps=1, int T=900, int h=50);
|
||||
|
||||
void moonwalker(float steps=1, int T=900, int h=50, int dir=LEFT);
|
||||
void crusaito(float steps=1, int T=900, int h=20, int dir=FORWARD);
|
||||
void flapping(float steps=1, int T=1000, int h=50, int dir=FORWARD);
|
||||
|
||||
void test_pos();
|
||||
|
||||
void new_walk(int dir = FORWARD, float steps =4, int T=750);
|
||||
void new_turn(int dir = LEFT, float steps =2, int T=1000);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Oscillator servo[4];
|
||||
|
||||
int servo_pins[4];
|
||||
int servo_trim[4];
|
||||
int servo_position[4];
|
||||
|
||||
int pinBuzzer;
|
||||
|
||||
unsigned long final_time;
|
||||
unsigned long partial_time;
|
||||
float increment[4];
|
||||
|
||||
bool isHippieResting;
|
||||
|
||||
void _execute(int A[4], int O[4], int T, double phase_diff[4], float steps);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
70
Hippie_gestures.h
Normal file
70
Hippie_gestures.h
Normal file
@ -0,0 +1,70 @@
|
||||
#ifndef Zowi_gestures_h
|
||||
#define Zowi_gestures_h
|
||||
|
||||
//***********************************************************************************
|
||||
//*********************************GESTURE DEFINES***********************************
|
||||
//***********************************************************************************
|
||||
|
||||
#define ZowiHappy 0
|
||||
#define ZowiSuperHappy 1
|
||||
#define ZowiSad 2
|
||||
#define ZowiSleeping 3
|
||||
#define ZowiFart 4
|
||||
#define ZowiConfused 5
|
||||
#define ZowiLove 6
|
||||
#define ZowiAngry 7
|
||||
#define ZowiFretful 8
|
||||
#define ZowiMagic 9
|
||||
#define ZowiWave 10
|
||||
#define ZowiVictory 11
|
||||
#define ZowiFail 12
|
||||
|
||||
//*** MOUTH ANIMATIONS***
|
||||
#define littleUuh 0
|
||||
#define dreamMouth 1
|
||||
#define adivinawi 2
|
||||
#define wave 3
|
||||
|
||||
|
||||
// unsigned long int littleUuh_code[]={
|
||||
// 0b00000000000000001100001100000000,
|
||||
// 0b00000000000000000110000110000000,
|
||||
// 0b00000000000000000011000011000000,
|
||||
// 0b00000000000000000110000110000000,
|
||||
// 0b00000000000000001100001100000000,
|
||||
// 0b00000000000000011000011000000000,
|
||||
// 0b00000000000000110000110000000000,
|
||||
// 0b00000000000000011000011000000000
|
||||
// };
|
||||
|
||||
// unsigned long int dreamMouth_code[]={
|
||||
// 0b00000000000000000000110000110000,
|
||||
// 0b00000000000000010000101000010000,
|
||||
// 0b00000000011000100100100100011000,
|
||||
// 0b00000000000000010000101000010000
|
||||
// };
|
||||
|
||||
// unsigned long int adivinawi_code[]={
|
||||
// 0b00100001000000000000000000100001,
|
||||
// 0b00010010100001000000100001010010,
|
||||
// 0b00001100010010100001010010001100,
|
||||
// 0b00000000001100010010001100000000,
|
||||
// 0b00000000000000001100000000000000,
|
||||
// 0b00000000000000000000000000000000
|
||||
// };
|
||||
|
||||
// unsigned long int wave_code[]={
|
||||
// 0b00001100010010100001000000000000,
|
||||
// 0b00000110001001010000100000000000,
|
||||
// 0b00000011000100001000010000100000,
|
||||
// 0b00000001000010000100001000110000,
|
||||
// 0b00000000000001000010100100011000,
|
||||
// 0b00000000000000100001010010001100,
|
||||
// 0b00000000100000010000001001000110,
|
||||
// 0b00100000010000001000000100000011,
|
||||
// 0b00110000001000000100000010000001,
|
||||
// 0b00011000100100000010000001000000
|
||||
// };
|
||||
|
||||
|
||||
#endif
|
87
Hippie_mouths.h
Normal file
87
Hippie_mouths.h
Normal file
@ -0,0 +1,87 @@
|
||||
#ifndef Zowi_mouths_h
|
||||
#define Zowi_mouths_h
|
||||
|
||||
|
||||
//***********************************************************************************
|
||||
//*********************************MOUTHS DEFINES************************************
|
||||
//***********************************************************************************
|
||||
|
||||
#define zero_code 0b00001100010010010010010010001100
|
||||
#define one_code 0b00000100001100000100000100001110
|
||||
#define two_code 0b00001100010010000100001000011110
|
||||
#define three_code 0b00001100010010000100010010001100
|
||||
#define four_code 0b00010010010010011110000010000010
|
||||
#define five_code 0b00011110010000011100000010011100
|
||||
#define six_code 0b00000100001000011100010010001100
|
||||
#define seven_code 0b00011110000010000100001000010000
|
||||
#define eight_code 0b00001100010010001100010010001100
|
||||
#define nine_code 0b00001100010010001110000010001110
|
||||
|
||||
#define smile_code 0b00000000100001010010001100000000
|
||||
#define happyOpen_code 0b00000000111111010010001100000000
|
||||
#define happyClosed_code 0b00000000111111011110000000000000
|
||||
#define heart_code 0b00010010101101100001010010001100
|
||||
|
||||
#define bigSurprise_code 0b00001100010010100001010010001100
|
||||
#define smallSurprise_code 0b00000000000000001100001100000000
|
||||
|
||||
#define tongueOut_code 0b00111111001001001001000110000000
|
||||
#define vamp1_code 0b00111111101101101101010010000000
|
||||
#define vamp2_code 0b00111111101101010010000000000000
|
||||
#define lineMouth_code 0b00000000000000111111000000000000
|
||||
|
||||
#define confused_code 0b00000000001000010101100010000000
|
||||
#define diagonal_code 0b00100000010000001000000100000010
|
||||
|
||||
#define sad_code 0b00000000001100010010100001000000
|
||||
#define sadOpen_code 0b00000000001100010010111111000000
|
||||
#define sadClosed_code 0b00000000001100011110110011000000
|
||||
|
||||
#define okMouth_code 0b00000001000010010100001000000000
|
||||
#define xMouth_code 0b00100001010010001100010010100001
|
||||
#define interrogation_code 0b00001100010010000100000100000100
|
||||
|
||||
#define thunder_code 0b00000100001000011100001000010000
|
||||
#define culito_code 0b00000000100001101101010010000000
|
||||
|
||||
#define angry_code 0b00000000011110100001100001000000
|
||||
|
||||
|
||||
//Mouths sorted by numbers, and after, by happy to sad mouths
|
||||
#define zero 0
|
||||
#define one 1
|
||||
#define two 2
|
||||
#define three 3
|
||||
#define four 4
|
||||
#define five 5
|
||||
#define six 6
|
||||
#define seven 7
|
||||
#define eight 8
|
||||
#define nine 9
|
||||
#define smile 10
|
||||
#define happyOpen 11
|
||||
#define happyClosed 12
|
||||
#define heart 13
|
||||
#define bigSurprise 14
|
||||
#define smallSurprise 15
|
||||
#define tongueOut 16
|
||||
#define vamp1 17
|
||||
#define vamp2 18
|
||||
#define lineMouth 19
|
||||
#define confused 20
|
||||
#define diagonal 21
|
||||
#define sad 22
|
||||
#define sadOpen 23
|
||||
#define sadClosed 24
|
||||
#define okMouth 25
|
||||
#define xMouth 26
|
||||
#define interrogation 27
|
||||
#define thunder 28
|
||||
#define culito 29
|
||||
#define angry 30
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
133
Hippie_sounds.h
Normal file
133
Hippie_sounds.h
Normal file
@ -0,0 +1,133 @@
|
||||
#ifndef Zowi_sounds_h
|
||||
#define Zowi_sounds_h
|
||||
|
||||
//***********************************************************************************
|
||||
//*********************************SOUNDS DEFINES************************************
|
||||
//***********************************************************************************
|
||||
|
||||
|
||||
// Reference: This list was adapted from the table located here:
|
||||
// http://www.phy.mtu.edu/~suits/notefreqs.html
|
||||
#define note_C0 16.35 //C0
|
||||
#define note_Db0 17.32 //C#0/Db0
|
||||
#define note_D0 18.35 //D0
|
||||
#define note_Eb0 19.45 //D#0/Eb0
|
||||
#define note_E0 20.6 //E0
|
||||
#define note_F0 21.83 //F0
|
||||
#define note_Gb0 23.12 //F#0/Gb0
|
||||
#define note_G0 24.5 //G0
|
||||
#define note_Ab0 25.96 //G#0/Ab0
|
||||
#define note_A0 27.5 //A0
|
||||
#define note_Bb0 29.14 //A#0/Bb0
|
||||
#define note_B0 30.87 //B0
|
||||
#define note_C1 32.7 //C1
|
||||
#define note_Db1 34.65 //C#1/Db1
|
||||
#define note_D1 36.71 //D1
|
||||
#define note_Eb1 38.89 //D#1/Eb1
|
||||
#define note_E1 41.2 //E1
|
||||
#define note_F1 43.65 //F1
|
||||
#define note_Gb1 46.25 //F#1/Gb1
|
||||
#define note_G1 49 //G1
|
||||
#define note_Ab1 51.91 //G#1/Ab1
|
||||
#define note_A1 55 //A1
|
||||
#define note_Bb1 58.27 //A#1/Bb1
|
||||
#define note_B1 61.74 //B1
|
||||
#define note_C2 65.41 //C2 (Middle C)
|
||||
#define note_Db2 69.3 //C#2/Db2
|
||||
#define note_D2 73.42 //D2
|
||||
#define note_Eb2 77.78 //D#2/Eb2
|
||||
#define note_E2 82.41 //E2
|
||||
#define note_F2 87.31 //F2
|
||||
#define note_Gb2 92.5 //F#2/Gb2
|
||||
#define note_G2 98 //G2
|
||||
#define note_Ab2 103.83 //G#2/Ab2
|
||||
#define note_A2 110 //A2
|
||||
#define note_Bb2 116.54 //A#2/Bb2
|
||||
#define note_B2 123.47 //B2
|
||||
#define note_C3 130.81 //C3
|
||||
#define note_Db3 138.59 //C#3/Db3
|
||||
#define note_D3 146.83 //D3
|
||||
#define note_Eb3 155.56 //D#3/Eb3
|
||||
#define note_E3 164.81 //E3
|
||||
#define note_F3 174.61 //F3
|
||||
#define note_Gb3 185 //F#3/Gb3
|
||||
#define note_G3 196 //G3
|
||||
#define note_Ab3 207.65 //G#3/Ab3
|
||||
#define note_A3 220 //A3
|
||||
#define note_Bb3 233.08 //A#3/Bb3
|
||||
#define note_B3 246.94 //B3
|
||||
#define note_C4 261.63 //C4
|
||||
#define note_Db4 277.18 //C#4/Db4
|
||||
#define note_D4 293.66 //D4
|
||||
#define note_Eb4 311.13 //D#4/Eb4
|
||||
#define note_E4 329.63 //E4
|
||||
#define note_F4 349.23 //F4
|
||||
#define note_Gb4 369.99 //F#4/Gb4
|
||||
#define note_G4 392 //G4
|
||||
#define note_Ab4 415.3 //G#4/Ab4
|
||||
#define note_A4 440 //A4
|
||||
#define note_Bb4 466.16 //A#4/Bb4
|
||||
#define note_B4 493.88 //B4
|
||||
#define note_C5 523.25 //C5
|
||||
#define note_Db5 554.37 //C#5/Db5
|
||||
#define note_D5 587.33 //D5
|
||||
#define note_Eb5 622.25 //D#5/Eb5
|
||||
#define note_E5 659.26 //E5
|
||||
#define note_F5 698.46 //F5
|
||||
#define note_Gb5 739.99 //F#5/Gb5
|
||||
#define note_G5 783.99 //G5
|
||||
#define note_Ab5 830.61 //G#5/Ab5
|
||||
#define note_A5 880 //A5
|
||||
#define note_Bb5 932.33 //A#5/Bb5
|
||||
#define note_B5 987.77 //B5
|
||||
#define note_C6 1046.5 //C6
|
||||
#define note_Db6 1108.73 //C#6/Db6
|
||||
#define note_D6 1174.66 //D6
|
||||
#define note_Eb6 1244.51 //D#6/Eb6
|
||||
#define note_E6 1318.51 //E6
|
||||
#define note_F6 1396.91 //F6
|
||||
#define note_Gb6 1479.98 //F#6/Gb6
|
||||
#define note_G6 1567.98 //G6
|
||||
#define note_Ab6 1661.22 //G#6/Ab6
|
||||
#define note_A6 1760 //A6
|
||||
#define note_Bb6 1864.66 //A#6/Bb6
|
||||
#define note_B6 1975.53 //B6
|
||||
#define note_C7 2093 //C7
|
||||
#define note_Db7 2217.46 //C#7/Db7
|
||||
#define note_D7 2349.32 //D7
|
||||
#define note_Eb7 2489.02 //D#7/Eb7
|
||||
#define note_E7 2637.02 //E7
|
||||
#define note_F7 2793.83 //F7
|
||||
#define note_Gb7 2959.96 //F#7/Gb7
|
||||
#define note_G7 3135.96 //G7
|
||||
#define note_Ab7 3322.44 //G#7/Ab7
|
||||
#define note_A7 3520 //A7
|
||||
#define note_Bb7 3729.31 //A#7/Bb7
|
||||
#define note_B7 3951.07 //B7
|
||||
#define note_C8 4186.01 //C8
|
||||
#define note_Db8 4434.92 //C#8/Db8
|
||||
#define note_D8 4698.64 //D8
|
||||
#define note_Eb8 4978.03 //D#8/Eb8
|
||||
|
||||
|
||||
#define S_connection 0
|
||||
#define S_disconnection 1
|
||||
#define S_buttonPushed 2
|
||||
#define S_mode1 3
|
||||
#define S_mode2 4
|
||||
#define S_mode3 5
|
||||
#define S_surprise 6
|
||||
#define S_OhOoh 7
|
||||
#define S_OhOoh2 8
|
||||
#define S_cuddly 9
|
||||
#define S_sleeping 10
|
||||
#define S_happy 11
|
||||
#define S_superHappy 12
|
||||
#define S_happy_short 13
|
||||
#define S_sad 14
|
||||
#define S_confused 15
|
||||
#define S_fart1 16
|
||||
#define S_fart2 17
|
||||
#define S_fart3 18
|
||||
|
||||
#endif
|
116
Zowi.cpp
116
Zowi.cpp
@ -1,116 +0,0 @@
|
||||
#include "Zowi.h"
|
||||
#include <Oscillator.h>
|
||||
|
||||
void Zowi::init(int YL, int YR, int RL, int RR, bool load_calibration) {
|
||||
servo[0].attach(YL);
|
||||
servo[1].attach(YR);
|
||||
servo[2].attach(RL);
|
||||
servo[3].attach(RR);
|
||||
|
||||
if (load_calibration) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int servo_trim = EEPROM.read(i);
|
||||
if (servo_trim > 128) servo_trim -= 256;
|
||||
servo[i].SetTrim(servo_trim);
|
||||
}
|
||||
}
|
||||
Serial.begin(115200);
|
||||
Serial.println(" test");
|
||||
|
||||
for (int i = 0; i < 4; i++) servo_position[i] = 90;
|
||||
}
|
||||
|
||||
void Zowi::setTrims(int YL, int YR, int RL, int RR) {
|
||||
servo[0].SetTrim(YL);
|
||||
servo[1].SetTrim(YR);
|
||||
servo[2].SetTrim(RL);
|
||||
servo[3].SetTrim(RR);
|
||||
}
|
||||
|
||||
void Zowi::saveTrimsOnEEPROM() {
|
||||
for (int i = 0; i < 4; i++) EEPROM.write(i, servo[i].getTrim());
|
||||
}
|
||||
|
||||
void Zowi::moveServos(int time, int servo_target[]) {
|
||||
if(time>10){
|
||||
for (int i = 0; i < 4; i++) increment[i] = ((servo_target[i]) - servo_position[i]) / (time / 10.0);
|
||||
final_time = millis() + time;
|
||||
|
||||
for (int iteration = 1; millis() < final_time; iteration++) {
|
||||
partial_time = millis() + 10;
|
||||
for (int i = 0; i < 4; i++) servo[i].SetPosition(servo_position[i] + (iteration * increment[i]));
|
||||
while (millis() < partial_time); //pause
|
||||
}
|
||||
}
|
||||
else{
|
||||
for (int i = 0; i < 4; i++) servo[i].SetPosition(servo_target[i]);
|
||||
}
|
||||
for (int i = 0; i < 4; i++) servo_position[i] = servo_target[i];
|
||||
}
|
||||
|
||||
void Zowi::oscillateServos(int A[4], int O[4], int T, double phase_diff[4], float cycle=1){
|
||||
for (int i=0; i<4; i++) {
|
||||
servo[i].SetO(O[i]);
|
||||
servo[i].SetA(A[i]);
|
||||
servo[i].SetT(T);
|
||||
servo[i].SetPh(phase_diff[i]);
|
||||
}
|
||||
double ref=millis();
|
||||
for (double x=ref; x<T*cycle+ref; x=millis()){
|
||||
for (int i=0; i<4; i++){
|
||||
servo[i].refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Zowi::walk(float steps, int T){
|
||||
int A[4]= {30, 30, 20, 20};
|
||||
int O[4] = {0, 0, 0, 0};
|
||||
double phase_diff[4] = {DEG2RAD(180), DEG2RAD(180), DEG2RAD(90), DEG2RAD(90)};
|
||||
|
||||
int cycles=(int)steps;
|
||||
|
||||
if (cycles >= 1) for(int i=0;i<cycles;i++) oscillateServos(A,O, T, phase_diff);
|
||||
oscillateServos(A,O, T, phase_diff,(float)steps-cycles);
|
||||
}
|
||||
|
||||
void Zowi::backward(float steps, int T){
|
||||
int A[4]= {15, 15, 30, 30};
|
||||
int O[4] = {0, 0, 0, 0};
|
||||
double phase_diff[4] = {DEG2RAD(180), DEG2RAD(180), DEG2RAD(270), DEG2RAD(270)};
|
||||
|
||||
int cycles=(int)steps;
|
||||
|
||||
if (cycles >= 1) for(int i=0;i<cycles;i++) oscillateServos(A,O, T, phase_diff);
|
||||
oscillateServos(A,O, T, phase_diff,(float)steps-cycles);
|
||||
}
|
||||
|
||||
void Zowi::turnLeft(float steps, int T){
|
||||
int A[4]= {10, 10, 25, 25};
|
||||
int O[4] = {0, 0, 0, 0};
|
||||
double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180), DEG2RAD(90), DEG2RAD(90)};
|
||||
|
||||
int cycles=(int)steps;
|
||||
|
||||
if (cycles >= 1) for(int i=0;i<cycles;i++) oscillateServos(A,O, T, phase_diff);
|
||||
oscillateServos(A,O, T, phase_diff,(float)steps-cycles);
|
||||
}
|
||||
|
||||
void Zowi::turnRight(float steps, int T){
|
||||
int A[4]= {20, 20, 30, 10};
|
||||
int O[4] = {0, 0, 0, 0};
|
||||
double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)};
|
||||
|
||||
int cycles=(int)steps;
|
||||
|
||||
if (cycles >= 1) for(int i=0;i<cycles;i++) oscillateServos(A,O, T, phase_diff);
|
||||
oscillateServos(A,O, T, phase_diff,(float)steps-cycles);
|
||||
}
|
||||
|
||||
void Zowi::jump(float steps, int T){
|
||||
int up[]={90,90,150,30};
|
||||
moveServos(T,up);
|
||||
int down[]={90,90,90,90};
|
||||
moveServos(T,down);
|
||||
}
|
42
Zowi.h
42
Zowi.h
@ -1,42 +0,0 @@
|
||||
#ifndef Zowi_h
|
||||
#define Zowi_h
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <ESP32_Servo.h>
|
||||
#include <Oscillator.h>
|
||||
#include <EEPROM.h>
|
||||
|
||||
|
||||
|
||||
class Zowi
|
||||
{
|
||||
public:
|
||||
void init(int YL, int YR, int RL, int RR, bool load_calibration=0);
|
||||
void setTrims(int YL, int YR, int RL, int RR);
|
||||
void saveTrimsOnEEPROM();
|
||||
|
||||
void moveServos(int time, int servo_target[]);
|
||||
void oscillateServos(int A[4], int O[4], int T, double phase_diff[4], float cycle);
|
||||
|
||||
void walk(float steps=4, int T=1566);
|
||||
void turnLeft(float steps, int T);
|
||||
void turnRight(float steps, int T);
|
||||
void backward(float steps, int T);
|
||||
void jump(float steps=1, int T=1000);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Oscillator servo[4];
|
||||
int servo_trim[4];
|
||||
int servo_position[4];
|
||||
|
||||
unsigned long final_time;
|
||||
unsigned long partial_time;
|
||||
float increment[4];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
255
Zowi.ino
Normal file
255
Zowi.ino
Normal file
@ -0,0 +1,255 @@
|
||||
|
||||
|
||||
/**************************************************************************************
|
||||
* *
|
||||
* Programa de calibracion de Hippie *
|
||||
* Javier Isabel, 02/06/2015 *
|
||||
* *
|
||||
* En este programa se indica como calibrar a Hippie utilizando *
|
||||
* la librera diseñada especificamente para el, hippie.h *
|
||||
* *
|
||||
**************************************************************************************/
|
||||
|
||||
#include <Hippie.h> //Libreria Hippie, disponible en el repositorio de GitHub de Hippie
|
||||
#include <ESP32_Servo.h>
|
||||
#include <Oscillator.h> //Librera ArduSnake de Obijuan, en GitHub
|
||||
#include <EEPROM.h>
|
||||
#include <WiFi.h>
|
||||
#include <ESPUI.h>
|
||||
|
||||
const char* ssid = "Real_Hippie";
|
||||
|
||||
/**************************************************************************************
|
||||
* *
|
||||
* Empezamos por declarar un objeto de la clase Hippie. La clase Hippie *
|
||||
* contiene funciones para calibrar a Hippie y para crear y ejecutar *
|
||||
* diversos tipos de movimientos *
|
||||
* *
|
||||
**************************************************************************************/
|
||||
|
||||
Hippie hippie;
|
||||
int posiciones[] = {90, 90, 90, 90};
|
||||
|
||||
boolean walk_forward = false;
|
||||
boolean walk_backward = false;
|
||||
boolean jump = false;
|
||||
boolean turn_left = false;
|
||||
boolean turn_right = false;
|
||||
boolean shake = false;
|
||||
boolean swing = false;
|
||||
boolean tt_swing = false;
|
||||
boolean jitter = false;
|
||||
boolean bend = false;
|
||||
boolean flap = false;
|
||||
boolean moon = false;
|
||||
boolean moon_r = false;
|
||||
boolean cruise = false;
|
||||
boolean test_pos = false;
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
Serial.begin(115200);
|
||||
WiFi.mode(WIFI_AP);
|
||||
WiFi.setHostname(ssid);
|
||||
WiFi.softAP(ssid);
|
||||
//WiFi.softAP(ssid, password);
|
||||
Serial.println("");
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.softAPIP());
|
||||
|
||||
|
||||
ESPUI.pad("Hips dont Lie", true, &Padle, COLOR_CARROT);
|
||||
ESPUI.button("TT_Swing Button", &BeerButton,COLOR_PETERRIVER);
|
||||
ESPUI.button("Swing Button", &BeerButton2,COLOR_PETERRIVER);
|
||||
ESPUI.button("Angry Button", &BeerButton3,COLOR_PETERRIVER);
|
||||
ESPUI.button("Jitter Button", &BeerButton4,COLOR_PETERRIVER);
|
||||
ESPUI.button("Shake Button", &BeerButton5,COLOR_PETERRIVER);
|
||||
ESPUI.button("Bend Button", &BeerButton6,COLOR_PETERRIVER);
|
||||
ESPUI.button("Flap Button", &BeerButton7,COLOR_PETERRIVER);
|
||||
ESPUI.button("Moonwalk Left Button", &BeerButton8,COLOR_PETERRIVER);
|
||||
ESPUI.button("cruisato Button", &BeerButton9,COLOR_PETERRIVER);
|
||||
ESPUI.button("Moonwalk Right Button", &BeerButton10,COLOR_PETERRIVER);
|
||||
|
||||
ESPUI.switcher("Test", true, &test, COLOR_CARROT);
|
||||
|
||||
ESPUI.begin("Hippie Control");
|
||||
|
||||
/**************************************************************************************
|
||||
* *
|
||||
* La funcion init sirve para configurar a Hippie, y se le pasan cinco parametros: *
|
||||
* - (int) pin del servo superior izquierdo *
|
||||
* - (int) pin del servo superior derecho *
|
||||
* - (int) pin del servo inferior izquierdo *
|
||||
* - (int) pin del servo inferior derecho *
|
||||
* - (boolean) booleano que indica si quieren cargarse los valores de calibracion *
|
||||
* de la memoria EEPROM (1, true) o no (0, false). Este valor puede omitirse, por *
|
||||
* defecto sera 0 *
|
||||
* *
|
||||
**************************************************************************************/
|
||||
|
||||
hippie.init(25, 13, 26, 16, false);
|
||||
//hippie.moveServos(500, posiciones);
|
||||
}
|
||||
void test(Control c, int type) {
|
||||
}
|
||||
void BeerButton(Control c, int type) {
|
||||
if (type == B_DOWN) {
|
||||
tt_swing = true;
|
||||
}
|
||||
else {
|
||||
tt_swing = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BeerButton2(Control c, int type) {
|
||||
if (type == B_DOWN) {
|
||||
swing = true;
|
||||
}
|
||||
else {
|
||||
swing = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BeerButton3(Control c, int type) {
|
||||
if (type == B_DOWN) {
|
||||
jump = true;
|
||||
}
|
||||
else {
|
||||
jump = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BeerButton4(Control c, int type) {
|
||||
if (type == B_DOWN) {
|
||||
jitter = true;
|
||||
}
|
||||
else {
|
||||
jitter = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BeerButton5(Control c, int type) {
|
||||
if (type == B_DOWN) {
|
||||
shake = true;
|
||||
}
|
||||
else {
|
||||
shake = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BeerButton6(Control c, int type) {
|
||||
if (type == B_DOWN) {
|
||||
bend = true;
|
||||
}
|
||||
else {
|
||||
bend = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BeerButton7(Control c, int type) {
|
||||
if (type == B_DOWN) {
|
||||
flap = true;
|
||||
}
|
||||
else {
|
||||
flap = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BeerButton8(Control c, int type) {
|
||||
if (type == B_DOWN) {
|
||||
moon = true;
|
||||
}
|
||||
else {
|
||||
moon = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BeerButton9(Control c, int type) {
|
||||
if (type == B_DOWN) {
|
||||
cruise = true;
|
||||
}
|
||||
else {
|
||||
cruise = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BeerButton10(Control c, int type) {
|
||||
if (type == B_DOWN) {
|
||||
moon_r = true;
|
||||
}
|
||||
else {
|
||||
moon_r = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Padle (Control c, int value) {
|
||||
switch (value) {
|
||||
case P_LEFT_DOWN:
|
||||
turn_left = true;
|
||||
break;
|
||||
case P_LEFT_UP:
|
||||
turn_left = false;
|
||||
break;
|
||||
case P_RIGHT_DOWN:
|
||||
turn_right = true;
|
||||
break;
|
||||
case P_RIGHT_UP:
|
||||
turn_right = false;
|
||||
break;
|
||||
case P_FOR_DOWN:
|
||||
walk_forward = true;
|
||||
break;
|
||||
case P_FOR_UP:
|
||||
walk_forward = false;
|
||||
break;
|
||||
case P_BACK_DOWN:
|
||||
walk_backward = true;
|
||||
break;
|
||||
case P_BACK_UP:
|
||||
walk_backward = false;
|
||||
break;
|
||||
case P_CENTER_DOWN:
|
||||
test_pos = true;
|
||||
break;
|
||||
case P_CENTER_UP:
|
||||
test_pos = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
||||
/**************************************************************************************
|
||||
* *
|
||||
* Durante las pruebas utilizaremos la funcion moveServos para poner todos los servos *
|
||||
* a 90º y comparar su posicion real con la posicion buscada *
|
||||
* *
|
||||
**************************************************************************************/
|
||||
|
||||
//hippie.walk(4,1800);
|
||||
|
||||
if (walk_forward) hippie.new_walk();
|
||||
else if (walk_backward) hippie.new_walk(2,4,750);
|
||||
else if (turn_left) hippie.new_turn();
|
||||
else if (turn_right) hippie.new_turn(2);
|
||||
else if (shake) hippie.shakeLeg();
|
||||
else if (jump) hippie.jump();
|
||||
else if (swing) hippie.swing();
|
||||
else if (tt_swing) hippie.tiptoeSwing();
|
||||
else if (jitter) hippie.jitter();
|
||||
else if (bend) hippie.bend();
|
||||
else if (flap) hippie.flapping();
|
||||
else if (moon) hippie.moonwalker();
|
||||
else if (moon_r) hippie.moonwalker(1,900,50,-1);
|
||||
else if (cruise) hippie.crusaito();
|
||||
else if (test_pos) hippie.test_pos();
|
||||
else hippie.home();
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user