code problem with accelerometer
joy1
Posts: 32
i'm working on a project for our robot to self-level on it's x-axis only. The robot has two front wheel drive wheels and there will be one motor on each side to raise/lower the appropriate wheel to keep the base level as one wheel goes over a 3/4 inch piece of plywood. I can make it work with one side such that it raises and lowers as the robot goes over the plywood. Problem is, I don't know how to create the code for the second side so that it also will raise/lower when the other wheel is on the plywood.
Any help would be much appreciated...
Here is my code
'
[ Title ]
' X-axis two motors.bs2
' Robot has two linear actuators..one for left drive one for right drive.
'self leveling attempt when driving on 3/4 plywood
'{$STAMP BS2}
'{$PBASIC 2.5}
'
[ Variables ]
x VAR Word ' Left/right tilt
pulseLeft VAR Word ' left pulse value
pulseRight VAR Word ' right pulse value
'
[ Initialization ]
pulseLeft = 750 ' Start with all pulses centered
pulseRight = 750
DEBUG "Beep!!!" ' Test piezospeaker
FREQOUT 4, 2000, 3000
DEBUG CLS, " x ", CR ' Axis headings
'
[ Main Routine ]
DO ' Begin main routine.
PULSIN 6, 1, x ' Get tilt pulses.
x = (x MIN 1875 MAX 3125) - 2500 ' -625 to 625 with 0 = no tilt
DEBUG CRSRX, 0, "(", SDEC3 x, ")", CLREOL
' Navigation decisions
IF ABS(x) > 100 THEN ' x > 40...right wheel on plywood then left motor
'moves up UNTIL ~0(level)
pulseLeft = 750 - x
' IF the robot moves with the left wheel of the robot ON the plywood this
'has to occur in reverse...I do not have any code for it
ELSE ' Stay still
pulseLeft = 750
pulseRight = 750
ENDIF
pulseLeft = pulseLeft MIN 650 MAX 850 ' Keep 650 <= durations <= 850
pulseRight = pulseRight MIN 650 MAX 850
PAUSE 20
PULSOUT 13, pulseLeft ' Send control pulses to servos
PULSOUT 12, pulseRight
LOOP ' Repeat main routine.
Any help would be much appreciated...
Here is my code
'
[ Title ]
' X-axis two motors.bs2
' Robot has two linear actuators..one for left drive one for right drive.
'self leveling attempt when driving on 3/4 plywood
'{$STAMP BS2}
'{$PBASIC 2.5}
'
[ Variables ]
x VAR Word ' Left/right tilt
pulseLeft VAR Word ' left pulse value
pulseRight VAR Word ' right pulse value
'
[ Initialization ]
pulseLeft = 750 ' Start with all pulses centered
pulseRight = 750
DEBUG "Beep!!!" ' Test piezospeaker
FREQOUT 4, 2000, 3000
DEBUG CLS, " x ", CR ' Axis headings
'
[ Main Routine ]
DO ' Begin main routine.
PULSIN 6, 1, x ' Get tilt pulses.
x = (x MIN 1875 MAX 3125) - 2500 ' -625 to 625 with 0 = no tilt
DEBUG CRSRX, 0, "(", SDEC3 x, ")", CLREOL
' Navigation decisions
IF ABS(x) > 100 THEN ' x > 40...right wheel on plywood then left motor
'moves up UNTIL ~0(level)
pulseLeft = 750 - x
' IF the robot moves with the left wheel of the robot ON the plywood this
'has to occur in reverse...I do not have any code for it
ELSE ' Stay still
pulseLeft = 750
pulseRight = 750
ENDIF
pulseLeft = pulseLeft MIN 650 MAX 850 ' Keep 650 <= durations <= 850
pulseRight = pulseRight MIN 650 MAX 850
PAUSE 20
PULSOUT 13, pulseLeft ' Send control pulses to servos
PULSOUT 12, pulseRight
LOOP ' Repeat main routine.
Comments
ps: this seams very similar to what might happen for the FTC "Ring it Up" challenge... http://www.usfirst.org/roboticsprograms/ftc/game
pps: please also use the [ code ] [ /code ] tags (without the spaces) when posting code.
On another note, I think I've seen that USfirst stuff before...is that what you do?
Maybe you're saying that at one point, the left motor goes on the plywood while the right motor is not. You want the robot to level itself. Then it drives forward, and now both motors are on the plywood. You want the robot to level itself again. Is this correct?
If that is the case, you can do this with a simple loop (no need to remember past robot state). Just fill in the else case with the motors in even position.
thanks
You need to get rid of the absolute value function as SLRM suggested. If x if positive you know it's tilting one way, if x is negative you're tilting the other direction.
You might not be able to use SLRM's exact code but he showed you the general idea. You say "I have tried that solution but it doesn't work". Then post what your tried and tell us what you expected it to do and also tell us what it did do. I'm sure someone around here can help you figure this out.
By using the absolute value of x your losing the ability to sense one of the directions of tilt.