tabrokit sumobot programming
Drewdawg
Posts: 12
i'm trying to get my bot to go forward for an allotted amount of time and can't seem to get it to work, can anyone help me out?
Comments
The total 'forward' time is:
· 'forward'·command to 505
+· pause 180
~ 180 m sec
*··10 loop iterations (number of times this loop is performed).
~ 1800 m sec
I have attached some code with comments which may be interesting.
DO ' Do the loop 10 times
RobotData = RobotForward ' Move forward
GOSUB RobotSend
PAUSE PauseTime ' Wait msecs between RobotSend commands
LOOP ' Repeat Again
It should have been:
FOR sendCmd = 0 TO 9 ' Do the loop 10 times
RobotData = RobotForward ' Move forward
GOSUB RobotSend
PAUSE PauseTime ' Wait msecs between RobotSend commands
NEXT
Don't forget to declare variable 'sendCmd'.
My son has some of his TAB SUMOBOT code posted on our WEB page. Please have a look at it.
I encourage you to read through the·CD that came with the robot. It will take you through·several code writing execises.·The manual on the CD·is not as well written as the Parallax material but it is the only way for you to learn how your TAB SUMOBOT works.
In case you weren't aware of it, there is a Yahoo Group which deals exclusively with the Tab Robot Kit. Here is a link to that Yahoo Group:
http://groups.yahoo.com/group/tabrobotkit/
Regards,
Bruce Bates
'
' { $STAMP BS2 }
'|||||||||||||||||| Variables ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PauseTime VAR WORD ' Create a 16 Bit Variable
CountMoves VAR NIB ' Create a 4 Bit Variable
RobotData VAR BYTE ' Data Byte to Send to/Receive from Robot
'||||||||||||||||||| Constants ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RobotStop CON 0 'Stop the Robot
RobotForward CON 5 ' Move Forward for 200 msecs
RobotReverse CON 6 ' Move Reverse for 200 msecs
RobotLeft CON 7 ' Turn Left for 200 msecs
RobotRight CON 8 ' Turn Right for 200 msecs
RobotPWM0 CON 11 ' PWM = 0% Duty Cycle
RobotPWM1 CON 12 ' PWM = 1st "Notch"
RobotPWM2 CON 13 ' PWM = 2nd "Notch"
RobotPWM3 CON 14 ' PWM = 3rd "Notch"
RobotPWM4 CON 15 ' PWM = 100% Duty Cycle
LED CON 11 ' LED, Negative Active On
SC CON 14 ' Define the Serial communications Clock Pin
SD CON 15 ' Define the Serial communications Data Pin
'|||||||||||||||||||| Main Code |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
debug "forward"
HIGH SC ' Set the I/O Bits As O/P - Required by the 505
HIGH SD ' and High - Required by the 505
HIGH LED ' Turn off the LED
PauseTime = 80 ' msecs between commands
PAUSE 100 ' Time for the electronic circuits to startup
RobotData = RobotPWM0 ' Set the speed to 0 of 4 since Behavior 1 will probably start.
GOSUB RobotSend
RobotData = RobotPWM4 ' Set the speed to 0 of 4 since Behavior 1 will probably start.
GOSUB RobotSend
FOR CountMoves = 0 TO 1 ' Do the loop # times
RobotData = RobotForward ' Move forward
GOSUB RobotSend
PAUSE PauseTime ' Wait msecs between RobotSend commands
RobotData = RobotStop ' Stop the Robot
GOSUB RobotSend
RobotSend: ' Send the Byte in "RobotData"
LOW SC ' Hold Low for 1 msec before
PAUSE 1 ' Shifting in Data
SHIFTOUT SD, SC, LSBFIRST, [noparse][[/noparse]RobotData]
HIGH SC
return
I didn't look through your coding all that thoroughly, but there is definitely a NEXT statment missing after your FOR statement. Additionally, I don't see anywhere that the variable CountMoves is incremented or decremented or even referenced anywhere in your coding except in tha FOR statement mentioned above. Lastly, you are probably going to drop right into the RobotSend coding. The RobotSend coding is a sub-routine, and it should only be accessed by a GOSUB statement.
I'd clean up at least that much before you try toactually troubleshoot it any further.
Regards,
Bruce Bates
I'll invite the guys who designed the robot into this discussion.
Ken Gracey
Parallax, Inc.
I modified·the code to·make·it·stop after the forward commands. I also tested it on my TAB SUMOBOT.·The·sub-routine had been a part of the main program logic. When the context came to the 'Return' statement it caused the program to start over again. I choose to use an endless loop before the subroutine but you could just as easily use a 'goto' to skip over it and have more code.
The·code is attached.