mingdooley
Rookie
Joined: Wed Feb 22, 2012 4:23 am Posts: 10
|
 Motors Won't Stop When Joystick is Let Go
When I tested this code I held the joystick down, which made the wheels move, but when I let go the motors would keep moving. Any help is appreciated. I used two custom libraries which are attached to this message. (This was tested using ROBOTC 3.54.)
Here is my code:
#pragma config(Hubs, S1, HTMotor, HTMotor, HTServo, HTMotor) #pragma config(Sensor, S1, , sensorI2CMuxController) #pragma config(Motor, mtr_S1_C1_1, motorD, tmotorTetrix, openLoop) #pragma config(Motor, mtr_S1_C1_2, motorE, tmotorTetrix, openLoop) #pragma config(Motor, mtr_S1_C2_1, motorF, tmotorTetrix, openLoop, reversed) #pragma config(Motor, mtr_S1_C2_2, motorG, tmotorTetrix, openLoop, reversed) #include "OmniDriverControlsTimeLibrary360.c" #include "JoystickDriverExtension.c"
const int deadzone = 10; task main(){ while(true){ getJoystickSettings(joystick); float degrees = JoystickDegrees(1, 1); //This finds the value for the degrees of the first joystick and assigns it to a float. float power = JoystickPower(1, 1); //This finds the value for how far the joystick is away from the center and assings it to a float. float power2 = JoystickPower(1, 2); //This does the same thing as line 15 but for the second joystick on controller one. degrees = -degrees + 90; //This fixes the degrees power = power / 1.27; //This and line 19 reduces the joystick values down to 100. power2 = power2 / 1.27 && -power2 + 90;
if(joystick.joy1_y1 > deadzone || joystick.joy1_x1 > deadzone || joystick.joy1_y1 < -deadzone || joystick.joy1_x1 < -deadzone){ Move(degrees, power, 0); //This sets up the first joystick on controller 1. } if(joystick.joy1_x2 <= -deadzone){ Turn(-1, power2, 0); //This sets up counterclockwise. } if(joystick.joy1_x2 >= deadzone){ Turn(1, power2, 0); //This sets up clockwise. } if(joystick.joy1_y1 == deadzone || joystick.joy1_x1 == deadzone || joystick.joy1_y1 == -deadzone || joystick.joy1_x1 == -deadzone){ Move(0, 0, 0); //This means that if the joystick is not held down, then the robot does not move. } wait1Msec(10); } }
|
JohnWatson
Site Admin
Joined: Thu May 24, 2012 12:15 pm Posts: 722
|
 Re: Motors Won't Stop When Joystick is Let Go
Without looking too much into the code, I may have found the culprit. The IF condition used to stop the movement entirely: What does this do? More specifically, what happens if the joystick value is -9 to +9? This 'stop' condition only becomes true if one of the joysticks is exactly at a 10 value; otherwise, the condition is false, the motors are not stopped, and the last movement condition is held. You may want to go with something more like this: This should check to see if the y1 value is less than +10 AND greater than -10 AND if the x1 value is less than +10 AND greater than -10 (basically, if the joystick is within a +-10 deadzone), then the move function will be send values of 0.
_________________Check out our Blog! And our Facebook page! Need help? Take a look at our updated help documentation and the ROBOTC Forums.
|