View unanswered posts | View active topics It is currently Thu Dec 18, 2014 9:09 am






Reply to topic  [ 4 posts ] 
Motors Won't Stop When Joystick is Let Go 
Author Message
Rookie

Joined: Wed Feb 22, 2012 4:23 am
Posts: 10
Post 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);
}
}


Attachments:
File comment: The library for "Move" and "Turn"
OmniDriverControlsTimeLibrary360.c [7.61 KiB]
Downloaded 213 times
File comment: The library for "JoystickDegrees" and "JoystickPower"
JoystickDriverExtension.c [4.34 KiB]
Downloaded 210 times
Mon Nov 26, 2012 10:08 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 619
Post 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:

Code:
if(joystick.joy1_y1 == deadzone || joystick.joy1_x1 == deadzone || joystick.joy1_y1 == -deadzone || joystick.joy1_x1 == -deadzone)


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:

Code:
if ((joystick.joy1_y1 <= deadzone && joystick.joy1_y1 >= -deadzone)  && (joystick.joy1_x1 <= deadzone && joystick.joy1_x1 >= -deadzone))


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 Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Tue Nov 27, 2012 12:41 pm
Profile
Novice

Joined: Sun Oct 21, 2012 10:01 pm
Posts: 76
Post Re: Motors Won't Stop When Joystick is Let Go
JohnWatson wrote:
You may want to go with something more like this:

Code:
if ((joystick.joy1_y1 <= deadzone && joystick.joy1_y1 >= -deadzone)  && (joystick.joy1_x1 <= deadzone && joystick.joy1_x1 >= -deadzone))


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.

Or, even more simply...
Code:
if (abs(joystick.joy1_y1) <= deadzone && abs(joystick.joy1_x1) <= deadzone))
{
}


Tue Nov 27, 2012 1:44 pm
Profile
Rookie

Joined: Wed Feb 22, 2012 4:23 am
Posts: 10
Post Re: Motors Won't Stop When Joystick is Let Go
Thank you both for the help, I figured it out now.


Fri Nov 30, 2012 9:53 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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

Search for:
Jump to:  
cron



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.