jueves, 8 de agosto de 2013

Pololu Servo Controller + Arduino (2/3)

This is the key to make your micro maestro understand the arduino orders:

Command used: "Set Target" with Pololu protocol http://www.pololu.com/docs/0J40/5.e
Pololu protocol: 0xAA, device number, 0x04, channel number, target low bits, target high bits

Each underlined is a byte that you must send, so in this case you send 6 bytes (6 packages of 1 byte), let's see how it works

Arduino Code, Pololu protocol: "put" is a method that do all the work

void put(unsigned char servo, unsigned int target)
{
   //servo is the servo number ( 0-11 [12 Maestro servo version] )
   //target = wanted position

 // Mandatory paraphernalia, converts the decimal angle("target") you entered into a 2 bytes (first 7 and last 7 bits), just copy and  paste blue, it's used by the last two serial.write lines
  unsigned int temp; 
  unsigned char pos_hi,pos_low;
  temp=target&0x1f80;
  pos_hi=temp>>7;           // First 7 bits

  pos_low=target & 0x7f;   // Last 7 bits

  //Sending Pololu Protocol command
  Serial.write(0xAA); //start byte -> Mandatory
  Serial.write(0x0C); //device id or number (seen in part 1/3)
  Serial.write(0x04); //command number  -> Mandatory, it depens on command you use
  Serial.write(servo); //channel number -> number of the servo, depends wich pololu you have (6,12,18, ..)
  Serial.write(pos_hi);   //data1, Sending the firsts 7 bits
  Serial.write(pos_low);    //data2, Sending the lasts 7 bits
}

void loop()
{
   put(1, 1550);        // Move servo in position 1 to angle 1550
   delay(1000);         // Wait 1000 miliseconds (1 sec)
   put(1, 2000);        // Move servo in position 1 to angle 2000
   delay(1000);         // Wait 1000 miliseconds (1 sec)
}

Video Sample:

Imgur album

Go to part 1/3                                                                                                                       Go to part 3/3

,

No hay comentarios:

Publicar un comentario