programming gear switing

I am trying to program the code for gear shifting. I can get it to shift the gears with the servos but I can’t get it to jog the drill motors forward to make sure that they go in to gear. Could someone please help? I am attaching a copy of my teams program to this message.

2002codev4.txt (18.5 KB)


2002codev4.txt (18.5 KB)

Below is the code the TechnoKats used last year to change gears. We used the joystick wheel as the input with a large deadband in the middle of the wheel. The code takes control of the drivetrain, stops the robot, changes gears, moves a little bit to let the gears lock in place, then returns control to the driver.

Make sure the serout command is inside the loop. Even though you’re just sending the same thing over and over it keeps the robot controller from thinking it’s lost the connection and resetting. Be sure to set the servo_gear_old default value at the top of the code to whichever gear you plan to start the match in. In this code, servo_gear actually contains the PWM value to send to the servo for the desired gear. Just conserving variables.

Hope this helps.
Jeff Burch
TechnoKats #45
[email protected]

'---------- Gear Change --------------------------------------------------------

if (p1_wheel > 57) then not_low_gear
servo_gear = LowGear 'p1_wheel button setup for lo_gear

not_low_gear:

if (p1_wheel <= 200) then not_hi_gear
servo_gear = HighGear 'p1_wheel button setup for hi_gear
not_hi_gear:

if (servo_gear_old = servo_gear) then no_change:

for k = 1 to 20 'Stops main drive base
Serout USERCPU, OUTBAUD, [255, 255, 127, relayA, 127, relayB, 127, 127, 127, 127, 127, 127, servo_gear_old, servo_gear_old+GearOff, 127, 127, BSRollPWM, 127, BSArmPWM, 127]
next

for k = 1 to 50 'Changes gear with the servo drive
Serout USERCPU, OUTBAUD, [255, 255, 127, relayA, 127, relayB, 127, 127, 127, 127, 127, 127, servo_gear, servo_gear+GearOff, 127, 127, BSRollPWM, 127, BSArmPWM, 127]
next

for k = 0 to 128 'Ramp Speed up
Serout USERCPU, OUTBAUD, [255, 255, 127+(k/8), relayA, 127, relayB, 127+(k/8), 127, 127, 127, 127, 127, servo_gear, servo_gear+GearOff, 127, 127, BSRollPWM, 127, BSArmPWM, 127]
next

for k = 0 to 10 'Stop again
Serout USERCPU, OUTBAUD, [255, 255, 127, relayA, 127, relayB, 127, 127, 127, 127, 127, 127, servo_gear, servo_gear+GearOff, 127, 127, BSRollPWM, 127, BSArmPWM, 127]
next

servo_gear_old = servo_gear

no_change:

ok I think I got that code modified to fit my teams robot but when I check the syntax I get the error “out of variable space” Please help I need to get the gear shifting up by tomarrow or my team might ditch it. I will attach the code. I am pretty new to programming the robot.

gearshift2.txt (20 KB)


gearshift2.txt (20 KB)

If you’re out of variable space, then you’re pretty much out of choices to make. Unless you can get rid of some other variables, you really can’t do much. I believe the robot controller only has about 16 K of memory, although I could be wrong on that. My team currently has about no memory left, but we’re lucky, cause we don’t need to add anymore varables, I think… :smiley:

*Originally posted by Ian W. *
If you’re out of variable space, then you’re pretty much out of choices to make.

Not exactly true.

We have run out of variable space several times, and have continued adding variables!

There are a couple of strategies we use when such a situation arises: Firstly, you may have some variables which are only used for intermediate values in calculations. For these, you may use “scratch” variables which can be reused similarly in other sections of the code.

You can also swap data to and from scratchpad RAM. For instance, you are filtering your joystick inputs, and you need to keep a “previous filtered value” from one loop iteration to the next, but that value is only needed in one small section of the code. Here’s how you can use scratchpad RAM for this data:


' =====================
'ScratchPad RAM memory map:

PREV_FILTERED_X con 0
PREV_FILTERED_Y con 1

...


' =====================
'Filter the joystick inputs

get PREV_FILTERED_X, scratch1 ' Reads prev value into scratch1

... ' Calculate new filtered value

put PREV_FILTERED_X, newFilteredX

...

thanks for the help