View Single Post
  #14   Spotlight this post!  
Unread 16-07-2008, 09:48
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,801
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: 2002 FRC Controller...

The short answer is you need to keep the original Serout command in exactly the order it was,

Another issue is some of the changes you've made to the initialization constants, e.g.,
Code:
c_p2_x CON 0
have to be reflected in a change to the Serin command. A different take on that whole position thing.
They have to be in the order shown in the Serin comment line, but you remove the variables in the middle that you've turned off, such as, p2_x.

------------
The long answer...
What Joe said.
You rearranged the Serout arguments, but the other side of the call treats every position in this exact order:
Code:
' Serout USERCPU, OUTBAUD, [255,255,(PWM1),relayA,(PWM2),relayB,(PWM3),(PWM4),(PWM5),(PWM6),(PWM7),(PWM8),(PWM9),(PWM10),(PWM11),(PWM12),(PWM13),(PWM14),(PWM15),(PWM16)]
The backside of Serout doesn't see the name "relayA" and realize you moved it around. It only receives the value of relayA, e.g., 100, and just assumes the fourth argument is what you want relayA to be. So you send:
Serout USERCPU, OUTBAUD, [255,255,p1_y,relayA,p2_y,relayB]
and what the RC receives might be:
[255,255,127,102,127,100]
There's no way for the computer to know if you've swapped any of the values around.

You're getting the same thing in reverse with the Serin call. You've told the computer that p2_x isn't wanted, so you have an argument in the Serin call that the computer isn't expecting. The RC sends you values in order for
[oi_swA,oi_swB,rc_swA,rc_swB,p1_x,...]
but you're stuffing them into
[oi_swA,oi_swB,rc_swA,rc_swB,p2_x,p1_x,...]
Nobody complains, but you won't get the values you want where you want them.

The only way Serout can be changed is you can leave some of those PWM arguments off the very end if you don't happen to be using them. Serout will recognize that it only has 10 arguments rather than the full 20.

------------
Another issue you'll have is the robot controller only has space for 26 variables and right now 26 are declared. You're not using all of them, so you can comment out some to free space for some new PWMx variables. Or you can reuse the variables already declared (p1_wheel), just like the default code does with p1_y, etc.

Here's an example to turn off your rear wheels while in high gear. It reuses the variables p2_y and p3_y to hold what you want for the pwm outputs, but you can replace these with other variables.
Code:
'---------- Rear wheels dont move while in High gear (relay2_fwd=0) ------
p2_y = p1_y
p3_y = p1_y
if relay2_fwd = 1 then next1:
   p2_y = 127
   p3_y = 127
next1:
 

Serout USERCPU, OUTBAUD, [255,255,p1_y,relayA,p2_y,relayB,p3_y,p4_y,p1_x,p2_x,p3_x,p4_x,p1_wheel,p2_wheel,p3_wheel,p4_wheel]
A clearer version is:
Code:
'Comment out the variables you aren't using (and change the Serin arguments to match, including the c_p1_wheel , etc. initializations)
'p1_wheel  VAR byte  'Port 1, Wheel on Joystick  n/a
'p2_wheel  VAR byte  'Port 2, Wheel on Joystick  n/a
'p3_wheel  VAR byte  'Port 3, Wheel on Joystick  n/a
'p4_wheel  VAR byte  'Port 4, Wheel on Joystick  n/a
'p1_aux    VAR byte  'Port 1, Aux on Joystick  n/a
'p2_aux    VAR byte  'Port 2, Aux on Joystick  n/a
'p3_aux    VAR byte  'Port 3, Aux on Joystick  n/a
'p4_aux    VAR byte  'Port 4, Aux on Joystick  n/a
 
' Add your new variables
PWM1    VAR Byte 
PWM2    VAR Byte 
PWM3    VAR Byte 
PWM4    VAR Byte 
PWM5    VAR Byte 
PWM6    VAR Byte 
PWM7    VAR Byte 
 
'---------- Rear wheels dont move while in High gear (relay2_fwd=0) ------
PWM2 = p1_y
PWM3 = p1_y
if relay2_fwd = 1 then next1:
   PWM2 = 127
   PWM3 = 127
next1:
 

Serout USERCPU, OUTBAUD, [255,255,PWM1,relayA,PWM2,relayB,PWM3,PWM4,PWM5,PWM6,PWM7]
 
P.S.
I un-commented all your code and it compiles with a couple of minor errors. I don't have an RC handy to test it though, but I can get one if necessary and you have trouble.
1) Comment out the variables you aren't using (p1_wheel, p2_x, etc.) that way an error will let you know if you forgot and left it in a Serin/Serout call.
2) Add new PWMx variables
3) Fix the Serin call
4) Change the Serout call to use PWM1, etc.
5) next 4: needs to be next4:
6) The check for emergency_stop should be "= 0" rather than 1
7) The emergency_stop example I originally gave you had a syntax error. It should have been:
Code:
IF p2_sw_aux1 = 0 THEN   next5:
    emergency_stop = 1
next5:
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 17-07-2008 at 08:01. Reason: Changed my answers around a bit to simplify