Arduino clone controlled robot chassis

We’ve been pretty busy around here doing contract work, so there’s not been much time for just doing fun things.  As part of the design effort going into an Arduino clone that control servos and motors independent of the Arduino Atmel part we put together an experimental robot chassis.  The chassis was designed in Sketchup and the parts were fabricated from Plexiglas by Ponoko.

This week I finally had a chance to hobble together some of the parts and try some simple movements using the robot chassis.  The video above shows the results.  I’m using three Hitec HS-645MG, and one Futaba S3003.  They “kind of” work, but I think we’ll want to employ some stronger servos.   Once the batteries, sensors, and additional body parts go on  the servos we’re using will not have enough oomph.  Eventually, I’ll use all the same servos and calibrate them for identical movement.  For now I just plugged in some pulse width values to create the movements approximating what I wanted.  The Arduino code below was used to command the chassis to flip over (the second segment of the video).

Mechanically things are a little loosy-goosy, and not really to my liking.  However, the effort did allow me to test the controller design, work with Sketchup, and use Ponoko to fabricate some parts.  These are all things I wanted to try out.  And if you don’t include the time spent screwing pieces together the code just took about an hour to write and test.

/*
  Firstbot Dual Motor Quad Servo Controller Communication example

 The circuit: 
 * RX is digital pin 2 (connect to TX of other device)
 * TX is digital pin 3 (connect to RX of other device)

 */
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // Receive data on 2, send data on 3
byte SerialTXBuffer[10];
byte SerialRXBuffer[10];

byte frontleft;
byte rearleft;
byte frontright;
byte rearright;

/* WriteRegister:
Writes a single byte, "Value",  to the register pointed at by "Index".  
Returns the response 

*/
byte WriteRegister(byte Index, byte Value)
{
byte i = 0;
byte checksum = 0;
byte ack = 0;

SerialTXBuffer[0] = 210;
SerialTXBuffer[1] = 1;
SerialTXBuffer[2] = 3;
SerialTXBuffer[3] = Index;
SerialTXBuffer[4] = Value;

for (i=0;i<6;i++)
  {
  if (i!=5)
    {
    mySerial.write(SerialTXBuffer[i]);
    checksum += SerialTXBuffer[i];    
    }
  else
    mySerial.write(checksum);     
  }
  delay(5);

  if (mySerial.available())
    ack = mySerial.read();

  return ack;
} 

byte ReadRegister(byte Index)
{
byte i = 0;
byte checksum = 0;
byte response;

SerialTXBuffer[0] = 209;
SerialTXBuffer[1] = 1;
SerialTXBuffer[2] = 2;
SerialTXBuffer[3] = Index;
SerialTXBuffer[4] = 1;

for (i=0;i<6;i++)
  {
  if (i!=5)
    {
    mySerial.write(SerialTXBuffer[i]);
    checksum += SerialTXBuffer[i];    
    }
  else
    mySerial.write(checksum);     
  }
  for (i=0;i<4;i++)
    {
    do{
    }while(!mySerial.available());
    SerialRXBuffer[i] = mySerial.read();
    }

  response = SerialRXBuffer[2];  
  return response;
}

void SetServoOutput()
{
  // Set each servo out register to 1.25mS pulse width
  WriteRegister(11,frontleft); // front left
  delay(10);
  WriteRegister(12,rearleft); // rear left
  delay(10);
  WriteRegister(13,frontright); // front right
  delay(10);
  WriteRegister(14,rearright); // rear right
  delay(10);
}

void SetServoPace(byte Pace)
{ 
  WriteRegister(15,Pace); // pace servo 1
  delay(10);
  WriteRegister(16,Pace); // pace servo 2
  delay(10);
  WriteRegister(17,Pace); // pace servo 3
  delay(10);
  WriteRegister(18,Pace); // pace servo 4
  delay(10);
  delay(10);
}

void setup()  
{
 // Open serial communications and wait for port to open:
  Serial.begin(2400);
  mySerial.begin(9600);
  SetServoPace(1);
}

void loop() // run over and over
{
  byte i = 0;
  // Set motor1 to +50% and motor2 to -50% duty cycle
  WriteRegister(9,225);
  delay(10);
  WriteRegister(10,67);
  delay(10);

  frontleft = 180;    // higher raises chassis
  rearleft = 175;    //  higher raises chassis
  frontright = 185;  //higher raises chassis
  rearright = 125;   // higher lowers chassis
  SetServoOutput();
  delay(10000);

  frontleft = 180;    // higher raises chassis
  rearleft = 225;    //  higher raises chassis
  frontright = 185;  //higher raises chassis
  rearright = 75;   // higher lowers chassis
  SetServoOutput();
  delay(4000);

  frontleft = 50;    // higher raises chassis
  rearleft = 225;    //  higher raises chassis
  frontright = 50;  //higher raises chassis
  rearright = 75;   // higher lowers chassis
  SetServoOutput();
  delay(4000);

  SetServoPace(10);

  frontleft = 50;    // higher raises chassis
  rearleft = 175;    //  higher raises chassis
  frontright = 50;  //higher raises chassis
  rearright = 125;   // higher lowers chassis
  SetServoOutput();
  delay(4000);

  SetServoPace(1);

  frontleft = 60;    // higher raises chassis
  rearleft = 50;    //  higher raises chassis
  frontright = 70;  //higher raises chassis
  rearright = 250;   // higher lowers chassis
  SetServoOutput();
  delay(4000);

  while(1);

}

Comments

  1. MHectorGato says:

    I like the design very much. I’m working on a bot and am just starting to look into ways to raise and lower the height.

Speak Your Mind

*