visited my friend's lab few days back. found a lot robot bodies in junk.

it has been sometime since i last build a robot. i think it is a good time for me to pick it up again, since there are ready made robot bodies for me to work on.

found a robot structure in good condition. but almost everything is dismantled from the robot.

Missing screws, nuts, connectors. These are minor problems, I can get it easily from hardware shop.

 

going to make it as RC robot. RC robot is a good start point.

program is not as complicated as automatic robot. circuitry is relatively simple. one remote control, a 2-channel motor driver. no sensor at all.

list of components:

structure x 1

motor x 4, in fact only 2 are needed. i am using 4 here because it is designed in this way.+_+

wheels x 4.

WiFi UNO based ESP32 board x 1

Monster Motor Shield VNH2SP30 x 1

battery x 1

ps3 remote control x 1

some screws and standoffs.

 

this is also the reason i starting my last blog post,Interfacing PS3 with ESP32

i wanted to use ps3 as remote control, and the robot has no space for USB host shield.

 

 

time lapse video of robot assembly process

 

 

uploading program to arduino

 

Yay!, the robot is moving.

 

source code

#include <Ps3Controller.h>
#include <BLEDevice.h>


#define LED_PWM_CHANNEL0 0
#define LED_PWM_CHANNEL1 1
#define FREQUENCY 5000
#define RESOLUTION 8


#define BRAKE 0
#define CW    1
#define CCW   2


//MOTOR 1
#define MOTOR_CW1_PIN 14
#define MOTOR_CCW1_PIN 12


//MOTOR 2
#define MOTOR_CW2_PIN 17
#define MOTOR_CCW2_PIN 13


#define PWM_MOTOR_1 16
#define PWM_MOTOR_2 27


#define EN_PIN_1 2
#define EN_PIN_2 4


#define MOTOR_1 0
#define MOTOR_2 1


void setup()
{
  // setup motor driver
  pinMode(MOTOR_CW1_PIN, OUTPUT);
  pinMode(MOTOR_CCW1_PIN, OUTPUT);
  
  pinMode(MOTOR_CW2_PIN, OUTPUT);
  pinMode(MOTOR_CCW2_PIN, OUTPUT);
  
  pinMode(PWM_MOTOR_1, OUTPUT);
  pinMode(PWM_MOTOR_2, OUTPUT); 
  
  pinMode(EN_PIN_1, OUTPUT);
  pinMode(EN_PIN_2, OUTPUT);


  ledcSetup(LED_PWM_CHANNEL0, FREQUENCY, RESOLUTION);
  ledcSetup(LED_PWM_CHANNEL1, FREQUENCY, RESOLUTION);
  ledcAttachPin(PWM_MOTOR_1, LED_PWM_CHANNEL0);
  ledcAttachPin(PWM_MOTOR_2, LED_PWM_CHANNEL1);


  // setup ps3
  Serial.begin(115200);
  Ps3.begin("11:22:33:44:55:66");
  Serial.println("Ready.");
  BLEDevice::setPower(ESP_PWR_LVL_P9);
}


void loop()
{
  if (Ps3.isConnected()){
    digitalWrite(EN_PIN_1, HIGH);
    digitalWrite(EN_PIN_2, HIGH);
    if( Ps3.data.button.cross ){
      Serial.println("Backward");
      Reverse();
    }   
    else if( Ps3.data.button.square ){
      Serial.println("Left");
      Left();
    }
    else if( Ps3.data.button.triangle ){
      Serial.println("Forward");
      Forward();
    }
    else if( Ps3.data.button.circle ){
      Serial.println("Right");
      Right();
    }
    else
      Stop();
  }
}


void Stop()
{
  motorGo(MOTOR_1, BRAKE, 0);
  motorGo(MOTOR_2, BRAKE, 0);
}


void Forward()
{
  motorGo(MOTOR_1, CW, 128);
  motorGo(MOTOR_2, CW, 128);
}


void Reverse()
{
  motorGo(MOTOR_1, CCW, 128);
  motorGo(MOTOR_2, CCW, 128);
}


void Left()
{
  motorGo(MOTOR_1, CCW, 128);
  motorGo(MOTOR_2, CW, 128);
}


void Right()
{
  motorGo(MOTOR_1, CW, 128);
  motorGo(MOTOR_2, CCW, 128);
}


void motorGo(uint8_t motor, uint8_t dir, uint8_t pwm)         //Function that controls the variables: motor(0 ou 1), direction (cw ou ccw) e pwm (entra 0 e 255);
{
  if(motor == MOTOR_1)
  {
    if(dir == CW)
    {
      digitalWrite(MOTOR_CW1_PIN, LOW); 
      digitalWrite(MOTOR_CCW1_PIN, HIGH);
    }
    else if(dir == CCW)
    {
      digitalWrite(MOTOR_CW1_PIN, HIGH);
      digitalWrite(MOTOR_CCW1_PIN, LOW);      
    }
    else
    {
      digitalWrite(MOTOR_CW1_PIN, LOW);
      digitalWrite(MOTOR_CCW1_PIN, LOW);            
    }
    ledcWrite(LED_PWM_CHANNEL0, pwm);
  }
  else if(motor == MOTOR_2)
  {
    if(dir == CW)
    {
      digitalWrite(MOTOR_CW2_PIN, LOW);
      digitalWrite(MOTOR_CCW2_PIN, HIGH);
    }
    else if(dir == CCW)
    {
      digitalWrite(MOTOR_CW2_PIN, HIGH);
      digitalWrite(MOTOR_CCW2_PIN, LOW);      
    }
    else
    {
      digitalWrite(MOTOR_CW2_PIN, LOW);
      digitalWrite(MOTOR_CCW2_PIN, LOW);            
    }
    ledcWrite(LED_PWM_CHANNEL1, pwm);
  }
}

 

will definitely visit my friend again, see what he has got in his lab!