View Single Post
  #7   Spotlight this post!  
Unread 11-02-2003, 11:52
Jnadke Jnadke is offline
Go Badgers!
#0093
Team Role: Alumni
 
Join Date: Jan 2002
Location: Appleton, WI
Posts: 775
Jnadke is on a distinguished road
Send a message via ICQ to Jnadke Send a message via AIM to Jnadke Send a message via Yahoo to Jnadke
Re: Yes This IS a Beginner's Question

Quote:
Originally posted by cammie825
I know that everyone is in deep with their programs at this point, but I'm having problems programming a dead zone into our joysticks. When we put the program in, it seemed to not respond all the time. Like it would go backwards, and then it would decide that it wouldn't go backwards anymore. I'm not really sure. Here's what we put in:
Thanks!

The problem is, you're not giving the stop_p3_y function a chance to execute. Also, PBASIC doesn't allow multiple comparisons (117<p1_y<137).

The easiest way is to check how far away it is from the middle (127) and compare it with a zone value. Usually around 6-10 is a good DEAD_ZONE value.

Here's an example of the drive code I used on TOBOR V last year. We had a tank-style drivetrain.

Code:
Drive:

left_motor:
	if (abs(p1_y - 127) > DEAD_ZONE) then right_motor
	p1_y = MOTOR_OFF

right_motor:
	if (abs(p3_y - 127) > DEAD_ZONE) then Drive_return
	p3_y = MOTOR_OFF

Drive_return:
__________________
The best moments of our lives fall in two categories: those that did happen and those that did not.