# Yes This IS a Beginner's Question

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:

If 117<p1_y<137 THEN stop_p1_y
If 117<p3_y<137 THEN stop_p3_y
goto end_zero

stop_p1_y:
p1_y = 127
goto end_zero

stop_p3_y:
p3_y = 127
goto end_zero

end_zero:

If you could help, that would be great.
Thanks!

What it actually seemed like it was doing, was that the port 3 joystick was going UP to 137, or down to 117, and THEN cutting off. Which is odd, but that’s what it felt like it was doing.

Thanks Again.

rbayer is really the authority on this one, but this is my thought. (I havn’t used pbasic much and cannot test this threory from where I’m at)

``````
If 117 < p1_y & p1_y < 137 THEN stop_p1_y
If 117 < p3_y & p1_y < 137 THEN stop_p3_y
goto end_zero

``````

Having the checking seperated may be your problem.

I just reworked the code, the way you suggested, and it’s still doing the same thing. Going UNTIL it gets to 117 or 137, then cutting itself off.
Thanks though!

``````
If 117 < p1_y & p1_y < 137 THEN stop_p1_y
If 117 < p3_y & p1_y < 137 THEN stop_p3_y
goto end_zero
``````

Ampersand (&) is the bitwise logical AND operator. You’d have to use the word AND instead.

``````
IF (117 < p1_y) AND (p1_y < 137) THEN p1_y = 127
IF (117 < p3_y) AND (p3_y < 137) THEN p3_y = 127

or, if you're using a symmetric deadband:

cDeadband CON 10

IF ABS(p1_y - 127) < cDeadband THEN p1_y = 127
IF ABS(p3_y - 127) < cDeadband THEN p3_y = 127

``````

<edited>
Sorry, figured most teams would be using the new compiler. We haven’t had any problems and it really is a lot more productive than the old version. (knocking on wood heard in background)
</edited>

Besides the errors in your syntax (which have already been pointed out), there is an error in your logic.

Lets assume that p1_y is 136 and p3_y is 118. If you follow your code through, you will set p1_y to 127 and then goto end_zero. p3_y will never be set. You need to rearrange your statements.

This is assuming that you are using the pbasic 2.0 syntax, which I assume becasue you used it in your first post. If you don’t mind using the pbasic 2.5 syntax, then what seanwitte posted would work and is a lot simpler.

*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.

``````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:

``````

Thank you all, EVER so much for help me out.

I really haven’t been allowed to program too much this year, and now it’s all coming at me at one. The robot is now running properly… Thanks!!!

and, just so ya know, I’ll probably have questions of this same nature later on… So, go ahead and be ready! j/k

here is the easiest way to do this in 2.0:

`````` If p1_y >= 137 or p1_y <= 117 then skipleftneu:
left_drive = 127
skipleftneu:
If p2_y >= 137 or p2_y <= 117 then skiprightneu:
right_drive = 127
skiprightneu:
``````

it works very well because you dont have to worry about order and goto statements, because those just get confusing. I’m using this and it works just great.

-Kesich