|
Page 1 of 1
|
[ 3 posts ] |
|
Angular drive system assistance.
Author |
Message |
Neoluminum
Rookie
Joined: Thu Jan 24, 2013 8:15 pm Posts: 2
|
 Angular drive system assistance.
 |  |  |  | Code: 01- #pragma config(Hubs, S1, HTMotor, HTMotor, HTServo, none) 02- #pragma config(Sensor, S1, , sensorI2CMuxController) 03- #pragma config(Motor, mtr_S1_C1_1, rightM, tmotorTetrix, openLoop) 04- #pragma config(Motor, mtr_S1_C1_2, leftM, tmotorTetrix, openLoop) 05- #pragma config(Motor, mtr_S1_C2_1, armM, tmotorTetrix, openLoop) 06- #pragma config(Motor, mtr_S1_C2_2, baseM, tmotorTetrix, openLoop) 07- #pragma config(Servo, srvo_S1_C3_1, servo1, tServoStandard) 08- #pragma config(Servo, srvo_S1_C3_2, servo2, tServoStandard) 09- #pragma config(Servo, srvo_S1_C3_3, servo3, tServoNone) 10- #pragma config(Servo, srvo_S1_C3_4, servo4, tServoNone) 11- #pragma config(Servo, srvo_S1_C3_5, servo5, tServoNone) 12- #pragma config(Servo, srvo_S1_C3_6, servo6, tServoNone) 13- #include "JoystickDriver.c" //brings information from the joystickdriver.c file 14- void InitializeRobot(){ 15- return; 16- } 17- task main(){ 18- InitializeRobot(); 19- int threshold = 5; //speed threshold 20- while (1 == 1){ //infinite loop 21- getJoystickSettings(joystick); //gets position of joysticks 22- int x = joystick.joy1_x1; //binding the joystick x and y values to variable 23- int y = joystick.joy1_y1; 24- int speed = sqrt((pow(x,2)) + (pow(y,2))); //Pythagorean theorem. 25- int angle = atan((abs(y) / abs(x))); //finds angle using absolute value of x and y 26- } 27- 28- if (speed > threshold){ 29- if (y > 0){ 30- motor(leftM) = (speed *(1 - (angle / 180))); //setting up the speeds multiplied 31- motor(rightM) = (speed *(angle / 180)); // by the percentage of degree to 32- }else{ //180 degrees (theta over 180) 33- if (y < 0){ 34- motor(leftM) = ((speed * (1 - (angle / 180))) * -1)); //making values reverse 35- motor(rightM) = ((speed * (anlgle / 180)) * -1); 36- } 37- } 38- if (x > -2) && (x < 2)){ // when neither one of the others are true 39- motor(rightM) = speed; //it falls back to this statement, where it runs both 40- motor(rightM) = speed; //of the motors equally if x is between -2 and 2 41- } 42- } 43- } |  |  |  |  |
--------------- these were the errors I received -------------------- File "Karren.c" compiled on Jan 24 2013 13:52:54 24- **Info***:'speed' is written but has no read references 25- **Info***:'angle' is written but has no read references 28- **Error**:Undefined variable 'speed'. 'short' assumed. 29- **Error**:Undefined variable 'y'. 'short' assumed. 30- **Error**:Undefined variable 'angle'. 'short' assumed. 34- **Error**:Missing ';' before ')' 34- **Error**:Unexpected ')' during parsing 35- **Error**:Undefined variable 'anlgle'. 'short' assumed. 38- **Error**:Undefined variable 'x'. 'short' assumed. 38- **Error**:Unexpected '&&' during parsing 38- **Error**:Missing ';' before ')' 38- **Error**:Unexpected ')' during parsing ------------------------------------------------------------------------ I am having a large amount of difficulty finding out how to fix this issue. My initial program had no errors but my decision was to move the motor values outside of my while loop. Unfortunately after doing so, it stopped recognizing variables. My primary goal is to have the "If's" from lines 28 through 30 working to run the two motors left and right of the robot, a general drive configuration. Any solutions would be very much appreciated  (any improvements are also nice)
|
Thu Jan 24, 2013 8:27 pm |
|
 |
amcerbu
Novice
Joined: Sun Oct 21, 2012 10:01 pm Posts: 76
|
 Re: Angular drive system assistance.
Your main problem was in line 26; you closed the forever loop, so code after line 26 could never be executed. Variables created within the loop go out of scope once the loop finishes, so lines 28 on don't recognize x, y, speed, or angle. There were a few other small things. Be careful about matching parentheses, that's an easy mistake to run into (and hard to track down). Personally, I prefer this indentation format: Some people like putting the { on the same line as the if, or the while, but I think it's harder to read that way. Try this:  |  |  |  | Code: #pragma config(Hubs, S1, HTMotor, HTMotor, HTServo, none) #pragma config(Sensor, S1, , sensorI2CMuxController) #pragma config(Motor, mtr_S1_C1_1, rightM, tmotorTetrix, openLoop) #pragma config(Motor, mtr_S1_C1_2, leftM, tmotorTetrix, openLoop) #pragma config(Motor, mtr_S1_C2_1, armM, tmotorTetrix, openLoop) #pragma config(Motor, mtr_S1_C2_2, baseM, tmotorTetrix, openLoop) #pragma config(Servo, srvo_S1_C3_1, servo1, tServoStandard) #pragma config(Servo, srvo_S1_C3_2, servo2, tServoStandard) #pragma config(Servo, srvo_S1_C3_3, servo3, tServoNone) #pragma config(Servo, srvo_S1_C3_4, servo4, tServoNone) #pragma config(Servo, srvo_S1_C3_5, servo5, tServoNone) #pragma config(Servo, srvo_S1_C3_6, servo6, tServoNone)
#include "JoystickDriver.c"
void InitializeRobot() { return; }
task main() { InitializeRobot(); int threshold = 5; while (true) { getJoystickSettings(joystick); //gets position of joysticks int x = joystick.joy1_x1; //binding the joystick x and y values to variable int y = joystick.joy1_y1; int speed = sqrt((pow(x,2)) + (pow(y,2))); //Pythagorean theorem. int angle = atan((abs(y) / abs(x))); //finds angle using absolute value of x and y
if (speed > threshold) { if (y > 0) { motor[leftM] = (speed *(1 - (angle / 180))); //setting up the speeds multiplied motor[rightM] = (speed *(angle / 180)); // by the percentage of degree to } else if (y < 0) { motor[leftM] = ((speed * (1 - (angle / 180))) * -1); //making values reverse motor[rightM] = ((speed * (angle / 180)) * -1); } if (abs(x) < 2) // when neither one of the others are true { motor[rightM] = speed; //it falls back to this statement, where it runs both motor[leftM] = speed; //of the motors equally if x is between -2 and 2 } } } }
|  |  |  |  |
Last edited by amcerbu on Fri Jan 25, 2013 4:55 am, edited 1 time in total.
|
Fri Jan 25, 2013 3:52 am |
|
 |
Neoluminum
Rookie
Joined: Thu Jan 24, 2013 8:15 pm Posts: 2
|
 Re: Angular drive system assistance.
That was very helpful. Thank you very much  <--- I give you this smiley emoticon in return for your services.
|
Fri Jan 25, 2013 4:28 am |
|
|
|
Page 1 of 1
|
[ 3 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 2 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|