Pages: [1]   Go Down
Author Topic: [HELP NEEDED] Controlling 3-wheel omniwheel robot  (Read 473 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I am making a 3-wheels Omniwheel robot to move in a certain pattern.

Below is my code for controlling the robot:

Code:
#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:

#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:

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:
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.
« Last Edit: January 31, 2013, 10:18:21 am by newbie1 » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 548
Posts: 46029
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But how do I move the robot to move in triangular waveform for 10 seconds?
Program it properly.
Logged

Malaysia
Offline Offline
Sr. Member
****
Karma: 7
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

lol
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24321
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Logged

East Anglia (UK)
Online Online
Faraday Member
**
Karma: 89
Posts: 3458
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.



Logged

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

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 548
Posts: 46029
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

East Anglia (UK)
Online Online
Faraday Member
**
Karma: 89
Posts: 3458
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"Close enough for Jazz"
Worth bearing in mind, certainly, but refinements can come later.
Logged

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

Pages: [1]   Go Up
Jump to: