4WD Robotic Car with 15 Kilo Load Test

Finally I put together my 4WD Robotic car. Thanks to Hercules Motor controller it’s doing what I am expecting of it. My self challenge was to make it carry 5 gallon water bottle. Few attempts failed as the motor was starting and stoping fast and the bottle was jumping out of the car. So I had to increase and reduce the speed slowly.

Parts used in this test

Source code used for this experiment 😉

// pin ctrl
#define PINCS           6           // all mos cs
#define PINM1F          4
#define PINM1R          5
#define PINM2F          7
#define PINM2R          8
#define PINPWMA         9           // PWM channel A (motor A speed)
#define PINPWMB         10          // PWM channel B (motor B speed)

int motorSpeed=0;

void setup()
{
    Serial.begin(19200);
    Serial.println("HERCULES 4WD TEST");
    pinMode(PINCS, OUTPUT);
    pinMode(PINM1F, OUTPUT);
    pinMode(PINM1R, OUTPUT);
    pinMode(PINM2F, OUTPUT);
    pinMode(PINM2R, OUTPUT);
    motorStop(100);
}

void loop()
{
  for (int i=0;i<=255;i=i+5){
    motorSetSpeed(i);
    motorForward(20); 
  }
  motorSetSpeed(255);
  motorForward(1000); 
  for (int i=255;i>=0;i=i-5){
    motorSetSpeed(i);
    motorForward(20); 
  }
  motorStop(2000);
  for (int i=0;i<=255;i=i+5){
    motorSetSpeed(i);
    motorReverse(20); 
  }
  motorSetSpeed(255);
  motorReverse(1000);
  for (int i=255;i>=0;i=i-5){
    motorSetSpeed(i);
    motorReverse(20); 
  }
  motorStop(2000); 
}

void motorSetSpeed(int power)
{
  motorSpeed=power;
  analogWrite(PINPWMA,motorSpeed);
  analogWrite(PINPWMB,motorSpeed);
}

void motorStop(int duration)
{
  digitalWrite(PINCS,LOW);
  digitalWrite(PINM1F,LOW);
  digitalWrite(PINM1R,LOW);
  digitalWrite(PINM2F,LOW);
  digitalWrite(PINM2R,LOW);
  delay(duration);
}

void motorForward(int duration)
{
   digitalWrite(PINM1F,LOW);
   digitalWrite(PINM1R,HIGH);
   digitalWrite(PINM2F,LOW);
   digitalWrite(PINM2R,HIGH);
   digitalWrite(PINCS,HIGH);
   delay(duration);
}

void motorReverse(int duration)
{
   digitalWrite(PINM1F,HIGH);
   digitalWrite(PINM1R,LOW);
   digitalWrite(PINM2F,HIGH);
   digitalWrite(PINM2R,LOW);
   digitalWrite(PINCS,HIGH);
   delay(duration);
}

Watch out for next update with remote control 😀

Published
Categorized as Personal

By Imthiaz

Programmer, SAAS, CMS & CRM framework designer, Love Linux & Apple products, Currently addicted to mobile development & working @bluebeetle