|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
One more thing to note
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. |
|
#3
|
||||
|
||||
|
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)
Code:
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 |
|
#4
|
|||
|
|||
|
tried that
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! |
|
#5
|
|||
|
|||
|
bitwise AND operator
Quote:
Code:
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 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> Last edited by seanwitte : 11-02-2003 at 12:14. |
|
#6
|
||||||
|
||||||
|
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. |
|
#7
|
||||
|
||||
|
Re: Yes This IS a Beginner's Question
Quote:
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: |
|
#8
|
|||
|
|||
|
Thanks You Guys!
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 |
|
#9
|
|||||
|
|||||
|
here is the easiest way to do this in 2.0:
Code:
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: -Kesich |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| question on launching boxes | 2PI4Julia | Rules/Strategy | 4 | 18-01-2003 10:17 |
| my idea of a question forum... | Ken Leung | General Forum | 12 | 30-11-2002 12:17 |
| MnM EASY Question of the Day Winners! | Mike Bonham | General Forum | 22 | 03-05-2002 21:21 |
| Chief Delphi Site Question | Mike Bonham | General Forum | 1 | 16-02-2002 22:18 |
| Rookie Programmer has question about the default code | DanL | Programming | 3 | 26-01-2002 19:59 |