Go Down

Topic: [HELP NEEDED] Controlling 3-wheel omniwheel robot (Read 805 times) previous topic - next topic

newbie1

Jan 31, 2013, 04:00 pm Last Edit: Jan 31, 2013, 04:18 pm by newbie1 Reason: 1
Hi, I am making a 3-wheels Omniwheel robot to move in a certain pattern.

Below is my code for controlling the robot:

Code: [Select]

#define motor1A 3
#define motor1C 5
#define motor2A 6
#define motor2C 9
#define motor3A 10
#define motor3C 11
#define clkwise 0
#define anticlkwise 1
#define M1
#define M2
#define M3

int halt = 0; // how bright the LED is
int incAmount = 5; // how many points to fade the LED by
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
void setup() {
pinMode(motor1A, OUTPUT);
pinMode(motor1C, OUTPUT);
pinMode(motor2A, OUTPUT);
pinMode(motor2C, OUTPUT);
pinMode(motor3A, OUTPUT);
pinMode(motor3C, OUTPUT);

Serial.begin(9600);
// reserve 200 bytes for the inputString:
inputString.reserve(20);
}

void loop() {
forward(200, 1000);
}


Below is the code for controlling the individual motor speed and direction:
Code: [Select]


#define cos60 0.5
#define sin60 0.866
float a1_sp;
float a2_sp;
float a3_sp;
char a1_speed;
char a2_speed;
char a3_speed;

void control(char robospeed, float roboangle, char roborotate )  {
  // assign the correct output pin for motor_num
 
  a1_sp= cos60*robospeed*cos(roboangle)- sin60*robospeed*sin(roboangle);
  a2_sp= 1*robospeed*cos(roboangle);
  a3_sp= cos60*robospeed*cos(roboangle)+ sin60*robospeed*sin(roboangle);
 
#ifdef M1
if (a1_sp > 0) {
    a1_speed = a1_sp+roborotate;
    motor(1, a1_speed, anticlkwise);
    }
    else {
    a1_sp *=-1;
    a1_speed = a1_sp+roborotate;
    motor(1, a1_speed, clkwise);
  }
 
#endif

#ifdef M2
if (a2_sp > 0) {
    a2_speed = a2_sp+roborotate;
    motor(2, a2_speed, anticlkwise);
    }
    else {
    a2_sp *=-1;
    a2_speed = a2_sp+roborotate;
    motor(2, a2_speed, clkwise);
  }

#endif

#ifdef M3
  if (a3_sp > 0) {
    a3_speed = a3_sp+roborotate;
    motor(3, a3_speed, anticlkwise);
    }
    else {
    a3_sp *=-1;
    a3_speed = a3_sp+roborotate;
    motor(3, a3_speed, clkwise);
  } 
#endif

}


Below is the code for setting the speed and direct control of a specific motor
Code: [Select]


void motor(char motor_num, char speed_val, boolean direct )  {
  char motorLA;
  char motorLC;
  // assign the correct output pin for motor_num
 
  switch(motor_num) {
    case 1:
      motorLA = motor1A;
      motorLC = motor1C;
      break;
     
   case 2:
      motorLA = motor2A;
      motorLC = motor2C;
      break;
     
   case 3:
      motorLA = motor3A;
      motorLC = motor3C;
      break;
  }

  if (direct) { // direct = 0:clockwise  direct = 1:anti-clockwise
    analogWrite(motorLA, 0);   
    analogWrite(motorLC, speed_val);   
  }
  else {
     analogWrite(motorLC, 0);   
     analogWrite(motorLA, speed_val);   
  }

                           
}


Below is the code for moving the robot forward:

Code: [Select]

void forward(int speedval, int time)
{
  control (speedval, 3.141*0.5, 0);
  delay(time);
}



So, the above codes will be run together and allows the robot to move forward. But how do I move the robot to move in triangular waveform for 10 seconds?

Thank you.

PaulS

Quote
But how do I move the robot to move in triangular waveform for 10 seconds?

Program it properly.

ash901226


Quote
But how do I move the robot to move in triangular waveform for 10 seconds?

Program it properly.


lol

AWOL

Do you mean it has to follow a sawtooth-like path, or it has to describe the perimeter of a triangle?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

newbie1


Do you mean it has to follow a sawtooth-like path, or it has to describe the perimeter of a triangle?


A sawtooth-like pattern. Example like this:

Go Up