|
Page 1 of 1
|
[ 6 posts ] |
|
Possible programming glitch
| Author |
Message |
|
gonica
Rookie
Joined: Mon Oct 10, 2011 11:29 am Posts: 3
|
 Possible programming glitch
Hey I've been programing robotc for two years now and I'm having this problem with my robot. it is just a square base with two HiTechnic motor controllers and a battery I havn't actualy seen it happen, however my freinds claim that randomly the robot will start turning all by itself. I'm assuming it is a problem with a battery thing but just in case here is my code  |  |  |  | Code: #pragma config(Hubs, S1, HTMotor, HTMotor, none, none) #pragma config(Sensor, S2, magnet, sensorHiTechnicMagnetic) #pragma config(Motor, mtr_S1_C1_1, motorleft, tmotorNormal, openLoop) #pragma config(Motor, mtr_S1_C1_2, motorright, tmotorNormal, openLoop, reversed) #pragma config(Motor, mtr_S1_C2_1, motorfrontleft, tmotorNormal, openLoop) #pragma config(Motor, mtr_S1_C2_2, motorfrontright, tmotorNormal, openLoop, reversed) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
///////////////////////////////////////////////////////////////////////////////////////////////// #include "JoystickDriver.c" //Include file to "handle" the Bluetooth messages.
///////////////////////////////////////////////////////////////////////////////////////////////// void initializeRobot() { return; }
task main() { initializeRobot();
float power_mult1 = 0.5; //slow, button 1 float power_mult2 = 0.35; //slower, button 2 float power_mult3 = 0.25; //lowest, button 3 //bool lift_forward = false; //bool joke_hiss = false; //bool magnet = false;
waitForStart(); // wait for start of tele-op phase
while (true) { if (joy1Btn(7) == 1) { motor[motorleft] = (float)joystick.joy1_y1 * power_mult1; motor[motorright] = (float)joystick.joy1_y2 * power_mult1; motor[motorfrontleft] = (float)joystick.joy1_y1 * power_mult1; motor[motorfrontright] = (float)joystick.joy1_y2 * power_mult1; } else if (joy1Btn(5) == 1) { motor[motorleft] = (float)joystick.joy1_y1 * power_mult2; motor[motorright] = (float)joystick.joy1_y2 * power_mult2; motor[motorfrontleft] = (float)joystick.joy1_y1 * power_mult2; motor[motorfrontright] = (float)joystick.joy1_y2 * power_mult2;
} else if (joy1Btn(8) == 1) { motor[motorleft] = (float)joystick.joy1_y1 * power_mult3; motor[motorright] = (float)joystick.joy1_y2 * power_mult3; motor[motorfrontleft] = (float)joystick.joy1_y1 * power_mult3; motor[motorfrontright] = (float)joystick.joy1_y2 * power_mult3; } else { motor[motorleft] = (float)joystick.joy1_y1; motor[motorright] = (float)joystick.joy1_y2; motor[motorfrontleft] = (float)joystick.joy1_y1; motor[motorfrontright] = (float)joystick.joy1_y2; } } } |  |  |  |  |
|
| Mon Oct 10, 2011 11:45 am |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2864 Location: Rotterdam, The Netherlands
|
 Re: Possible programming glitch
I wrapped your code in some tags to make it more readable. The only way I can see this happening is if the joystick is sending noisy data to the robot from its stick. It's not impossible, though. The other explanation is that your robot is possessed and is preparing to kill you. - Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Mon Oct 10, 2011 12:28 pm |
|
 |
|
l0jec
Expert
Joined: Mon Oct 27, 2008 9:59 pm Posts: 137
|
 Re: Possible programming glitch
I agree with Xander. Most likely you need to program a deadzone for the analog sticks on your joystick. To verify this, open up the joystick debug window and flick the analog sticks to see if they reset to zero. Most of them do not and will return to a value which is +- 5 or so off. Some are much worse. Adding a deadzone (if the value is plus or minus a certain range, set it to zero) should exorcise the demons.
|
| Mon Oct 10, 2011 12:36 pm |
|
 |
|
gonica
Rookie
Joined: Mon Oct 10, 2011 11:29 am Posts: 3
|
 Re: Possible programming glitch
oh okay I'll try that
|
| Mon Oct 10, 2011 3:16 pm |
|
 |
|
gonica
Rookie
Joined: Mon Oct 10, 2011 11:29 am Posts: 3
|
 Re: Possible programming glitch
Oh wow there is like a +- 15 on the x and a +- 10 on the y thanks for the help I wouldn't have thought of that.
|
| Mon Oct 10, 2011 3:20 pm |
|
 |
|
mightor
Moderator
Joined: Wed Mar 05, 2008 8:14 am Posts: 2864 Location: Rotterdam, The Netherlands
|
 Re: Possible programming glitch
Make the dead zone +20 to -20 on both axes and you'll be fine  - Xander
_________________| Some people, when confronted with a problem, think, "I know, I'll use threads," | and then two they hav erpoblesms. (@nedbat)| My Blog: I'd Rather Be Building Robots| ROBOTC 3rd Party Driver Suite: [ Project Page]
|
| Mon Oct 10, 2011 3:23 pm |
|
|
|
Page 1 of 1
|
[ 6 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 3 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
|
|