micho94
Published

ROBONOVA-1 with Arduino Mega

The objective of this project is to control the ROBONOVA-1 and make a few steps whith it.

IntermediateWork in progress3,328
ROBONOVA-1 with Arduino Mega

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×10

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Robonova-1

Arduino
The most important feature is the gestion function. This one need the positions of the XYZ1 (Left) and XYZ2 (Right) leg over a refernce sistem definet from the joint of each leg and the waist of the robot, where X goes below the robot, Z goes in front of the robot, and Y looks to the right of the robot. Then "acc" can be 0 (level the robot), 1 (balance over Left foot) or 2 (balance over Right foot). Bal is the back and forth angle wanted for the robot to balance (positive front). And "off" is in case we need to adjust balance over the leg.
//Project ROBONOVA-1
#include <VarSpeedServo.h> //Ddeclare to insert Servo.h library
VarSpeedServo servo[10]; // Create an array object of class servo
float q[6];//Declaration of global variables to work with through functions in radians
int l1=6,l2=5; //Leg lengths
int a[6]; //Angles to work with through equations in degrees
int posactual[10]; //Define actual position of Servos.
int oq[10]={93,68,15,93,117,170,135,93,47,93}; //Ofsets calibration definition for each joint.
const float Pi=3.1416;

void setup() {
  Serial.begin(9600); //Serial comunication with PC.
  //---Attaching SERVOS---//
    //LEFT Leg
     servo[0].attach(5);
     servo[1].attach(4);
     servo[2].attach(3);
    //LEFT Feet
     servo[6].attach(2);
     servo[7].attach(12);
    //RIGHT Leg
     servo[3].attach(9);
     servo[4].attach(8);
     servo[5].attach(7);
    //RIGHT Feet
     servo[8].attach(6);
     servo[9].attach(11);
  //Servos setting initial position
   for (int i = 0; i <= 9; i++)
   {
     Serial.print("Setup Joint :   ");
     Serial.println(i);
     posactual[i]=oq[i];
   }
}

///-------------------!!BUCLE PRINCIPAL!!-------------------///

void loop() {
  if (Serial.read() >= 0) {
      rightstep();
      leftstep();
  }
}

///-------------------!!FUNCIONES!!-------------------///
void rightstep() {
Serial.print("Right Step");
  delay(1000);
     gestion (8,8,   0, 0,   0,0,  0,0,0);       //Depart from leveled
     gestion (7,7,  -1, 0,   0,0,  1,0,0);      //Leveling over 1=LEFT
     gestion (7,9,  -2,-1,  -1,1,  1,0,0);    
     gestion (7,9,  -2,-2,  -1,1,  1,5,5);    
     gestion (7,8,  -3,-3,  -1,1,  1,2,10);   // Weight in one foot
     gestion (7,7,  -3,-3,  -1,3,  1,-3,10);  //Taking foot in the air to the front
     gestion (7,7,  -3,-3,  -1,4,  1,-3,10);  //
     gestion (7,9,  -3,-3,   0,4,  1,-3,10);  
     gestion (7,9,  -2,-2,   0,4,  1,0,10);   
     gestion (8,8,  -1,-1,   0,4,  0,5,0);   
     gestion (8,8,  -1,-1,   0,4,  2,5,5);    
     gestion (8,8,  -1,-1,   0,4,  2,10,10);     //Passing weight to leg moved
     gestion (6,8,   0, 0,   4,4,  2,10,10);     
     gestion (8,8,   0, 0,   4,4,  2,10,10); 
     gestion (8,8,   0, 0,   0,0,  0,5,0);       
  delay(1000);
}


void leftstep() {
  Serial.print("Left step");
  delay(1000);
     gestion (8,8,   0, 0,   0, 0,   0,0,0);       //Depart from leveled
     gestion (7,7,   0, 0,   0, 0,   2,0,5);      //Leveling over 2=RIGHT
     gestion (9,7,   1, 1,   1, 0,   2,0,5);    
     gestion (9,7,   3, 3,   1,-1,   2,5,10);    
     gestion (8,7,   3, 3,   1,-1,   2,2,10);   // Weight in one foot
     gestion (7,7,   2, 3,   3,-1,   2,-3,10);  //Taking foot in the air to the front
     gestion (7,7,   3, 3,   4,-1,   2,-3,10);  
     gestion (9,7,   3, 3,   4,-1,   2,-3,10);  
     gestion (9,7,   2, 2,   4,-1,   2,0,10);   
     gestion (7,8,   2, 0,   4, 0,   1,5,5);   
     gestion (8,8,   0, 0,   4, 0,   1,5,5);    
     gestion (7,8,   0, 0,   4, 0,   1,10,10);  //Passing weight to leg moved
     gestion (8,6,   0, 0,   4, 4,   1,10,10); 
     gestion (8,8,   0, 0,   4, 4,   1,10,10); 
     gestion (8,8,   0, 0,   0, 0,   0,0,0);       
  delay(1000);
}
void gestion(double x1,double x2,double y1,double y2,double z1,double z2,int acc,int bal,int off){ //Variables 1 are for the left feet and 2 for the right one.
  piernaIzq(x1,y1,z1);
  piernaDer(x2,y2,z2);
  switch (acc) {
    case 0:   //For leveling the feets
      Serial.print("Leveling");
      //Left Foot
       postogo[6]=-a[2]+a[1]+oq[6]-bal;
       postogo[7]=a[0]+oq[7];
      //Right Foot 
       postogo[8]=a[5]-a[4]+oq[8]+bal;
       postogo[9]=a[3]+oq[9];
    break;
    case 1: //Balance over the LEFT leg
      Serial.print("Balance LEFT");
      //Position to go Left Foot
       postogo[6]=-a[2]+a[1]+oq[6]-bal;
       postogo[7]=oq[7]+off;
      //Positioning Right Foot 
       postogo[8]=a[5]-a[4]+oq[8]+bal;
       postogo[9]=oq[9];
    break;
    case 2:  //Balance over RIGHT leg
      Serial.print("Balance RIGHT");
      //Position to go Left Foot
       postogo[6]=-a[2]+a[1]+oq[6]-bal;
       postogo[7]=oq[7];
      //Positioning Right Foot 
       postogo[8]=a[5]-a[4]+oq[8]+bal;
       postogo[9]=oq[9]-off;
    break;
  }
  servosend();
  delay(1000);
}

void servosend(){
  for (int i = 0; i <= 9; i++)  //Until 9 inclusive
    {servo[i].write(postogo[i],4,false); //We can set the speed of the movement.
    Serial.print("Poisitioning :   ");
    Serial.println(i);
    delay(15);
  }
}

void piernaIzq(double x, double y, double z){ //,int veloc, bool wait){ Para cuando utilicemos las variables de VarSpeedServo
  //Solving angles
  Serial.println("Calculo Pierna pierna izquierda");
  q[0]=atan(y/x);
  q[2]=acos((x*x+y*y+z*z-l1*l1-l2*l2)/(2*l1*l2));
  q[1]=atan((l2*sin(q[2]))/(l1+l2*cos(q[2])))+atan(z/sqrt(x*x+y*y));
  a[0]=(int)(q[0]*180/Pi);
  a[1]=(int)(q[1]*180/Pi);
  a[2]=(int)(q[2]*180/Pi);
  //Position to go leg servos 
      postogo[0]=a[0]+oq[0];
      postogo[1]=a[1]+oq[1];
      postogo[2]=a[2]+oq[2];
}

void piernaDer(double x, double y, double z){
  Serial.println("Calculate right leg");
  //Solving angles
  q[3]=atan(y/x);
  q[5]=acos((x*x+y*y+z*z-l1*l1-l2*l2)/(2*l1*l2));
  q[4]=atan((l2*sin(q[5]))/(l1+l2*cos(q[5])))+atan(z/sqrt(x*x+y*y));
  a[3]=(int)(q[3]*180/Pi);
  a[4]=(int)(q[4]*180/Pi);
  a[5]=(int)(q[5]*180/Pi);
  //Position to go  leg servos
      postogo[3]=a[3]+oq[3];
      postogo[4]=-a[4]+oq[4];
      postogo[5]=-a[5]+oq[5];
}

Credits

micho94

micho94

0 projects • 2 followers

Comments