Go Down

Topic: [HELP NEEDED] Controlling 3-wheel omniwheel robot (Read 836 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:

UKHeliBob

Questions :
Have you made the robot move forward for a fixed time at a fixed speed then stop ?
Have you made the robot turn 90 degrees right or left then stop ?

If you have then you know how to move it in the pattern that you describe
Code: [Select]
move forward
stop
spin right
stop
move forward
stop
spin left
stop
go back and do it over again

If not, then start by getting it to move forward a fixed amount and stop.  Write the code to do it, try it out and if it does not work post it here for help.

HINT - the forward(), control() and motor() functions need to be in your script.  They are not there in the script you posted although you did post them separately.



Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

PaulS

Quote
If not, then start by getting it to move forward a fixed amount and stop.

Keep in mind that just running the motor(s) for some amount of time does not equate to moving a fixed distance. If you don't have feedback for the distance moved, you will just be guessing as to the distance.

UKHeliBob

"Close enough for Jazz"
Worth bearing in mind, certainly, but refinements can come later.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up