viper550
05-11-2006, 08:20 PM
Hi everyone.Im new to this forum and i need some help with a project i have.I have a robot that is equiped with basic stamp 2 and i have some problems programming it.I will try to explain what i want it to do with as much details as i can so i can help you understand my problem.
I want the robot to have 2 modes.The first mode will be manual control where i can control the robot with the keyboard.The second mode is automatic movement where the robot will be a ble to move by itself.I want to be able to switch between the 2 modes whenever i want.The code i give was written by me for this purpose but i have some problems.The program starts and it does nothing because it await me to press m for manual control or a for automatic movement.When i press m then i control the robot with the 2,4,6,8 buttons.Here comes my first problem.When i press a to switch to automatic control it doesn't do anything.I have to press it the second time in order to start.When it enters automatic mode it does what it should do but here is my second big problem.When i press m to go to manual mode again it doesn't do anything.No matter how many times i press the m button it still stays in automatic mode.I have tried everything i could think of.If anyone can help me i would be very thankful.
Here i give the code i use:
'{$STAMP BS2}
'{$PBASIC 2.5}
SERVO_SX CON 12
SERVO_DX CON 13
buffer1 VAR Byte
checkAM:
SERIN 16,84,10000,checkAM,[buffer1]
IF (buffer1=97) THEN Auto
IF (buffer1=109) THEN manual
GOTO checkAM
manual:
SERIN 16,84,10000,manual,[buffer1]
IF (buffer1=56) THEN Forward
IF (buffer1=50) THEN Backward
IF (buffer1=54) THEN Right
IF (buffer1=52) THEN Left
IF (buffer1=53) THEN stopm
GOTO checkAM
Auto:
BaffoSX VAR Bit
BaffoDX VAR Bit
BaffoSX=IN6
BaffoDX=IN4
IF (BaffoSX=1 AND BaffoDX=1) THEN Forward1
IF (BaffoSX=1 AND BaffoDX=0) THEN Right_contact
IF (BaffoSX=0 AND BaffoDX=1) THEN Left_contact
GOTO checkAM
Right_contact:
sx VAR Byte
sx=1000
PULSOUT SERVO_SX,750
PULSOUT SERVO_DX,750
PAUSE 1500
T1:
PULSOUT SERVO_SX,800
PULSOUT SERVO_DX,700
sx =sx-1
IF sx=0 THEN T2
GOTO T1
T2:
PULSOUT SERVO_SX,700
PULSOUT SERVO_DX,700
sx = sx-1
IF sx=0 THEN Forward1
GOTO T2
GOTO Auto
Left_contact:
dx VAR Byte
dx=1000
PULSOUT SERVO_SX,750
PULSOUT SERVO_DX,750
PAUSE 1500
T3:
PULSOUT SERVO_SX,800
PULSOUT SERVO_DX,700
dx =dx-1
IF dx=0 THEN T4
GOTO T3
T4:
PULSOUT SERVO_SX,800
PULSOUT SERVO_DX,800
dx = dx-1
IF dx=0 THEN Forward1
GOTO T4
GOTO Auto
Forward1:
PULSOUT SERVO_SX,700
PULSOUT SERVO_DX,800
GOTO Auto
Forward:
PULSOUT SERVO_SX,500
PULSOUT SERVO_DX,1000
GOTO manual
Backward:
PULSOUT SERVO_SX,1000
PULSOUT SERVO_DX,500
GOTO manual
Right:
PULSOUT SERVO_SX,1000
PULSOUT SERVO_DX,1000
GOTO manual
Left:
PULSOUT SERVO_SX,500
PULSOUT SERVO_DX,500
GOTO manual
stopm:
PULSOUT SERVO_SX,750
PULSOUT SERVO_DX,750
GOTO manual
I want the robot to have 2 modes.The first mode will be manual control where i can control the robot with the keyboard.The second mode is automatic movement where the robot will be a ble to move by itself.I want to be able to switch between the 2 modes whenever i want.The code i give was written by me for this purpose but i have some problems.The program starts and it does nothing because it await me to press m for manual control or a for automatic movement.When i press m then i control the robot with the 2,4,6,8 buttons.Here comes my first problem.When i press a to switch to automatic control it doesn't do anything.I have to press it the second time in order to start.When it enters automatic mode it does what it should do but here is my second big problem.When i press m to go to manual mode again it doesn't do anything.No matter how many times i press the m button it still stays in automatic mode.I have tried everything i could think of.If anyone can help me i would be very thankful.
Here i give the code i use:
'{$STAMP BS2}
'{$PBASIC 2.5}
SERVO_SX CON 12
SERVO_DX CON 13
buffer1 VAR Byte
checkAM:
SERIN 16,84,10000,checkAM,[buffer1]
IF (buffer1=97) THEN Auto
IF (buffer1=109) THEN manual
GOTO checkAM
manual:
SERIN 16,84,10000,manual,[buffer1]
IF (buffer1=56) THEN Forward
IF (buffer1=50) THEN Backward
IF (buffer1=54) THEN Right
IF (buffer1=52) THEN Left
IF (buffer1=53) THEN stopm
GOTO checkAM
Auto:
BaffoSX VAR Bit
BaffoDX VAR Bit
BaffoSX=IN6
BaffoDX=IN4
IF (BaffoSX=1 AND BaffoDX=1) THEN Forward1
IF (BaffoSX=1 AND BaffoDX=0) THEN Right_contact
IF (BaffoSX=0 AND BaffoDX=1) THEN Left_contact
GOTO checkAM
Right_contact:
sx VAR Byte
sx=1000
PULSOUT SERVO_SX,750
PULSOUT SERVO_DX,750
PAUSE 1500
T1:
PULSOUT SERVO_SX,800
PULSOUT SERVO_DX,700
sx =sx-1
IF sx=0 THEN T2
GOTO T1
T2:
PULSOUT SERVO_SX,700
PULSOUT SERVO_DX,700
sx = sx-1
IF sx=0 THEN Forward1
GOTO T2
GOTO Auto
Left_contact:
dx VAR Byte
dx=1000
PULSOUT SERVO_SX,750
PULSOUT SERVO_DX,750
PAUSE 1500
T3:
PULSOUT SERVO_SX,800
PULSOUT SERVO_DX,700
dx =dx-1
IF dx=0 THEN T4
GOTO T3
T4:
PULSOUT SERVO_SX,800
PULSOUT SERVO_DX,800
dx = dx-1
IF dx=0 THEN Forward1
GOTO T4
GOTO Auto
Forward1:
PULSOUT SERVO_SX,700
PULSOUT SERVO_DX,800
GOTO Auto
Forward:
PULSOUT SERVO_SX,500
PULSOUT SERVO_DX,1000
GOTO manual
Backward:
PULSOUT SERVO_SX,1000
PULSOUT SERVO_DX,500
GOTO manual
Right:
PULSOUT SERVO_SX,1000
PULSOUT SERVO_DX,1000
GOTO manual
Left:
PULSOUT SERVO_SX,500
PULSOUT SERVO_DX,500
GOTO manual
stopm:
PULSOUT SERVO_SX,750
PULSOUT SERVO_DX,750
GOTO manual