|
Page 1 of 1
|
[ 10 posts ] |
|
Author |
Message |
10nisman94
Novice
Joined: Mon Oct 13, 2008 6:29 pm Posts: 75 Location: Florida, USA
|
 Dead Zone
could someone post code on creating a joystick dead zone, thanks in adv.
_________________ PHUHS Robotics Team 516 FTW
Daytona Robofest Winning Alliance Captain Daytona Robofest Inspire Award
|
Sun Oct 26, 2008 3:25 pm |
|
 |
Jeff McBride
Professor
Joined: Fri Sep 19, 2008 1:22 am Posts: 200
|
 Re: Dead Zone
Take a look at the TankArcade.c example in the thread: http://www.robotc.net/forums/viewtopic.php?f=33&t=826.
_________________ Jeff McBride Benson Robotics Club
|
Sun Oct 26, 2008 4:42 pm |
|
 |
Aswin
Expert
Joined: Mon Oct 06, 2008 6:30 pm Posts: 176 Location: Netherlands
|
 Re: Dead Zone
_________________My most recent blog: A grain of sugar
|
Sun Oct 26, 2008 6:01 pm |
|
 |
Atlantisbase
Expert
Joined: Tue Oct 14, 2008 7:16 pm Posts: 171 Location: Investigating an unidentified ship sighted in Sector 31428
|
 Re: Dead Zone
You could also do it this way
_________________Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
|
Sun Oct 26, 2008 8:34 pm |
|
 |
EastBots
Rookie
Joined: Thu Oct 02, 2008 12:35 pm Posts: 12
|
 Re: Dead Zone
Hey I have made a Program for the dead zone, but every time I run it, it just never works correctly, because the robot will never move. Here is the program:  |  |  |  | Code: #pragma config(Hubs, S1, HTMotor, HTMotor, none, none) #pragma config(Motor, mtr_S1_C1_1, motorD, tmotorNormal, openLoop, reversed) #pragma config(Motor, mtr_S1_C1_2, motorE, tmotorNormal, openLoop) #pragma config(Motor, mtr_S1_C2_1, , tmotorNone, openLoop) #pragma config(Motor, mtr_S1_C2_2, , tmotorNone, openLoop) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
#include "JoystickDriver.c"
task main() { while(true) { if ((joystick.joy1_y1 <= 30 || joystick.joy1_y1 >= -30)) { motor[motorD] = 0; } else if ((joystick.joy1_y1 >= 30 || joystick.joy1_y1 <= -30)) { getJoystickSettings(joystick); motor[motorD] = joystick.joy1_y1; } if ((joystick.joy1_y2 <= 30) || (joystick.joy1_y2 >= -30)) { motor[motorE] = 0; } else if ((joystick.joy1_y2 >= 20) || (joystick.joy1_y2 <= -20)) { getJoystickSettings(joystick); motor[motorE] = joystick.joy1_y2; } } }
|  |  |  |  |
If you can help, we would appreciate it very much. 
_________________ Gracious Professionalism. Their standard, our standard.
|
Mon Nov 10, 2008 6:13 pm |
|
 |
Aswin
Expert
Joined: Mon Oct 06, 2008 6:30 pm Posts: 176 Location: Netherlands
|
 Re: Dead Zone
Your program uses joystick.joy1_y2 to tell your motor how fast to rotate. Things like joystick.joy1_y2 are variables and need to be inialized before they can be used. In this case you do this with the getJoystickSettings(joystick) function. If you don't initilize it you'll get a zero value (if you are lucky). Also, everytime before you use the variable you have to make sure it is updated (if you want to). Again, you do this with the getJoystickSettings(joystick) function. You do use this function, but it is at the end of the while loop in a conditional branche. But it might never be executed. Moving this statement to the top of your while loop will solve your problem.
_________________My most recent blog: A grain of sugar
|
Mon Nov 10, 2008 7:37 pm |
|
 |
tfriez
Site Admin
Joined: Wed Jan 24, 2007 10:42 am Posts: 620
|
 Re: Dead Zone
you should move the "GetJoystickValues" function to right after the "while(true)" loop is started. Example (snippet):
_________________Timothy Friez ROBOTC Developer - SW Engineer tfriez@robotc.net
|
Wed Nov 12, 2008 1:49 pm |
|
 |
mannie
Rookie
Joined: Wed Mar 05, 2008 11:37 am Posts: 3
|
 Re: Dead Zone
Everyone is correct so far as far as getting the values from the joystick. However the real problem is with the logic in your first if statement. It reads:
if ((joystick.joy1_y1 <= 30 || joystick.joy1_y1 >= -30)) { motor[motorD] = 0; }
The issue is that every single value for joystick.joy1_y1 will be <= 30 OR >= -30. So this if statement always evaluates to true and motorD will never move.
What you want to do is change it to use && (AND) instead of || (OR).
|
Fri Nov 14, 2008 1:22 am |
|
 |
Atlantisbase
Expert
Joined: Tue Oct 14, 2008 7:16 pm Posts: 171 Location: Investigating an unidentified ship sighted in Sector 31428
|
 Re: Dead Zone
Please note that it should be >= 30 and <= -30 other wise your motors will only work for a very small range of the joystick, thusly, While you could use an else if to explictly test for values within the dead zone it becomes redundant because if it isn't outside the dead zone it's inside it so just an else is necessary.
_________________Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
|
Sat Nov 15, 2008 8:57 pm |
|
 |
Aswin
Expert
Joined: Mon Oct 06, 2008 6:30 pm Posts: 176 Location: Netherlands
|
 Re: Dead Zone
[quote="Atlantisbase"] The if statement of this code is correct. However, You cannot simple pass the joystick value to the motor. The range of the joystick goes from -128 to 128. The motor has a valid range of -100 to 100. Therefore you'll have to devide the joystick range by 1.28 (resulting in a value between -100 and 100) before assigning it to the motor. Also, please note that using this code the minimum speed of the motor =30 or -30. I do not know if this is what you want. But suppose you want both a deadzone and the possiblility to have a minimum speed below 30 then you'll have to correct for this as well.
_________________My most recent blog: A grain of sugar
|
Sun Nov 16, 2008 5:49 am |
|
|
|
Page 1 of 1
|
[ 10 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
|
|