building computer controlled car and need help with some code
Hey everyone again [noparse]:)[/noparse] I have been working with a VB program that communicates with the SX chip through a serial connection and I have run into a stump. I have been able to get the drive motor to go forward and backwards with the arrow keys, but now I am working on the servo to steer it. I am using a digital Futaba servo FP-S148 indirect drive.
The problem I am having is that now that I have added the code to center the servo when no activity is being sent, the drive motor will sometimes continue to move even though I do not have a button pressed. I was thinking about using an interrupt, but I am not sure about the timing on the chip and using the pulsout command.
Here is the code so far :
Thanks for any help in advance!
The problem I am having is that now that I have added the code to center the servo when no activity is being sent, the drive motor will sometimes continue to move even though I do not have a button pressed. I was thinking about using an interrupt, but I am not sure about the timing on the chip and using the pulsout command.
Here is the code so far :
' ========================================================================= ' ' Original Author.... Jon Williams, EFX-TEK ' ' ========================================================================= ID "srobot" DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX, BOR42 FREQ 4_000_000 ' ------------------------------------------------------------------------- ' I/O Pins ' ------------------------------------------------------------------------- Drive1 PIN RC.7 OUTPUT Drive2 PIN RC.6 OUTPUT Turn PIN RC.5 OUTPUT RX PIN RA.0 INPUT ' via MAX232 Sout PIN RA.1 OUTPUT ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- IsOn CON 1 IsOff CON 0 Baud CON "N9600" SYNC CON $80 ' start of packet marker MTR_X CON $01 MTR_Y CON $00 MTR_Z CON $7F ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- tmpW1 VAR Word cmd VAR Byte idx VAR Byte in VAR Byte (3) ' move per motor DriveMotor VAR Byte SteerMotor VAR Byte ExtraMotor1 VAR Byte f var Byte DELAY_MS SUB 1, 2 ' shell for PAUSE RX_BYTE FUNC 1, 0 ' shell for SERIN ' ========================================================================= PROGRAM Start ' ========================================================================= Start: PLP_A = %0000_0001 ' set pull-ups PLP_B = %0000_0000 PLP_C = %1111_0000 Main: for f = 1 to 136 PULSOUT Turn, 150 'DELAY_MS 20 cmd = RX_BYTE Next IF cmd <> SYNC THEN Main Get_Moves: FOR idx = 0 TO 2 cmd = RX_BYTE IF cmd = SYNC THEN Get_Moves ' fix busted packet in(idx) = cmd NEXT MoveMotor: DriveMotor = in(0) SteerMotor = in(1) ExtraMotor1 = in(2) IF DriveMotor = "1" THEN Drive2 = IsOff Drive1 = IsOn ELSEIF DriveMotor = "3" THEN Drive1 = IsOff Drive2 = IsOn ELSE Drive2 = IsOff Drive1 = IsOff ENDIF 'SEROUT Sout, Baud, DriveMotor GOTO Main SUB DELAY_MS IF __PARAMCNT = 1 THEN tmpW1 = __PARAM1 ELSE tmpW1 = __WPARAM12 ENDIF pause tmpW1 ENDSUB ' ------------------------------------------------------------------------- FUNC RX_BYTE SERIN RX, Baud, __PARAM1 ENDFUNC
Thanks for any help in advance!
Comments
Nick