BS2sx control of radio controlled aircraft
I want to feed the output of an r/c receiver to a basic stamp and then to a servo controller or directly to the servos, whatever is necessary. The basic stamp will act as a missing pulse detector and upon loss of the incoming servo signal the stamp will run a subroutine and will control the servos until the radio signal is reacquired. I only have to feed two channels of the receiver to the stamp and am presently using an r/c truck as a test bed. The two channels control the ESC (electronic speed control) and the steering servo. The plane is flying and has a video camera and transmitter. I have flown it out of visual range unintentionally and will eventually interface a gps so it will return to it's point of departure if something goes wrong but one step at a time. I would appreciate any help I could get and after reading the posts on the forum I am amazed at the knowledge the members have.
Thank You
Rick
Thank You
Rick
Comments
I am trying to do something similar in an SX-28. Look at the 3rd Prize winner in the 2005 SX Contest.
The missing pulse detector is something tha Jen Altenberg used in his Semi-Autonomous flight controller. He mixes the two inputs and actually detects horizon and control for a landing approach. You might also be able to automate a forced landing and beacon where your plane is with the GPS info.
If you want to move up to an SX-28, you might more easily add the GPS interface. I haven't finished, but I have been looking at moving Jen's code over from ByteCraft C to SASM.
These guys amaze me too -- a lot of fun loving experts.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
Kramer is right, it is doable, plus will be a really neat project!
The catamaran project I did last year has many of the same features you'll be using. I used a BS2 to listen to a 5 + 1 r/c receiver to control speed of two motors, direction, plus two winches and a sampler. To detect loss of signal, I kept checking to see what the PULSIN value was. If it was less than the radio's minimun pulse width, or larger than the the maximum, it triggered a recovery loop. A second BS2sx did all the data logging and sent data back to the land-based laptop via a data radio.
I really like the idea of the plane being able to find its way home. It would be reasonably straight forward, as long as you remembered to give the stamp the "home" coordinates before taking off!
Tom
Thanks again,
Rick Ouellette
1- Is there a more efficient way to write this code?
2- Any ideas why the program with the reverse counter crashes?
3- Would a parallax servo controller simplify things---- for example I wouldn't have to write a pause routine by pulsing the servos . in the neutral position. ( I have the servo controller but I haven't tried it yet.)
4- Is there a way to remember the position the steering servo was in when the signal is lost ? If the truck was in a turn when the . . signal was lost I could set the wheels to that position so the truck would retrace it's path.
I noticed if the servos weren't being pulsed for example during a long pause, there were a lot of glitches with the servos jumping all over the place. I tried pulling the output pins low with resistors tied to vss but that didn't work.
Will someone please give me some ideas?
Rick Ouellette
' {$STAMP BS2sx}
' {$PBASIC 2.5}
' This program uses a STAMP BS2sx to take control of an R/C truck upon loss
' of R/C signal and back the truck up two times to reacquire the signal. If the
' signal is not reacquired after the second reverse, the truck is shut down.
ch1 VAR Word ' electronic speed control channel
ch2 VAR Word ' steering channel
cycle VAR Word ' reverse counter
delay VAR Word ' delay counter
event VAR Nib ' "back" routine counter
main:
PULSIN 12, 1, ch1 ' input speed control pulse from receiver
PULSOUT 14, ch1 ' output speed control pulse to electronic speed control
PULSIN 13, 1, ch2 ' input steering pulse from receiver
PULSOUT 15, ch2 ' output steering pulse to steering servo
IF ch1 < 1000 THEN ' check for loss of signal
GOSUB back ' if no signal goto "go backwards" routine
ENDIF
GOTO main ' no loss of signal, start over
back: ' "go backwards routine"
'event = event + 1 ' count the number of reverses
'IF event > 2 THEN ' if the number of reverses is
'END ' greater than two, shut truck down
'ENDIF
FOR cycle = 1 TO 80
PULSOUT 14,(1840 - cycle) ' ramp up speed control in reverse direction
PAUSE 20 ' wait 20 milliseconds
PULSOUT 15, 1853 ' keep wheels centered
PAUSE 20 ' wait 20 milliseconds
NEXT ' loop
PULSIN 12, 1, ch1 ' check for signal acquisition
FOR delay = 1 TO 90 ' hold servo positions 5 seconds
PULSOUT 14, 1853 ' neutral speed control
PAUSE 20 ' wait 20 milliseconds
PULSOUT 15, 1853 ' steering straight ahead
PAUSE 20 ' wait 20 milliseconds
NEXT ' loop
PULSIN 12, 1, ch1 ' check to see if signal is reacquired
IF ch1 < 1000 THEN back ' no signal, back up again
RETURN ' signal reacquired return R/C control
See what the following does. Most of the name changes were just to help me keep track of the channel functions. I switched over to using the PIN function only because I think it's so sweet. WARNING: This was written PRE-coffee!
Regards,
Bruce Bates
' {$STAMP BS2sx}
' {$PBASIC 2.5}
' This program uses a STAMP BS2sx to take control of an R/C truck upon loss
' of R/C signal and back the truck up two times to reacquire the signal. If the
' signal is not reacquired after the second reverse, the truck is shut down.
'Define Variables and Constants
ESC_ch1 VAR Word······ ' electronic speed control channel
STEER_ch2 VAR Word······ ' steering channel
cycle VAR Word···· ' reverse counter
delay VAR Word···· ' delay counter
event VAR Nib····· ' "back" routine counter
'Define I/O Pin Ports
ESCin··· PIN 12
ESCout·· PIN 14
STEERin· PIN 13
STEERout PIN 15
event = 0· 'Initialize event counter
main:
'Read ESC input and send to ESC
PULSIN· ESCin, 1, ESC_ch1·· ' input speed control pulse from receiver
PULSOUT ESCout, ESC_ch1···· ' output speed control pulse to ESC
'Read STEERing input and send to STEERing servo
PULSIN· STEERin, 1, STEER_ch2· ' input steering pulse from receiver
PULSOUT STEERout, STEER_ch2·· ' output steering pulse to steering servo
'Check for loss of input signal
IF ESC_ch1 < 1000 THEN·· ' check for loss of signal
GOSUB back·············· ' if no signal goto "go backwards" routine
ENDIF
GOTO main··············· ' no loss of signal, or signal restored, start over
back:··················· ' "go backwards routine"
'event = event + 1······ ' count the number of reverses
'IF event > 2 THEN······ ' if the number of reverses is
'GOTO quit·············· ' greater than two, shut truck down
'ENDIF
GOSUB Backup
RETURN
'Exit if unsuccesssful
quit:
DEBUG "NO JOY!"········· 'Show no success
END····················· 'End program
'Attempt to manually drive in reverse to find signal
Backup:
FOR cycle = 1 TO 80
PULSOUT ESCout,(1840 - cycle)· ' ramp up speed control in reverse direction
'PAUSE 20····················· ' wait 20 milliseconds
PULSOUT STEERout, 1853········ ' keep wheels centered
PAUSE 20······················ ' wait 20 milliseconds
NEXT·························· ' loop
PULSIN ESCin, 1, ESC_ch1······ ' check for signal acquisition
FOR delay = 1 TO 90··········· ' hold servo positions 5 seconds
PULSOUT ESCout, 1853·········· ' neutral speed control
'PAUSE 20····················· ' wait 20 milliseconds
PULSOUT STEERout, 1853········ ' steering straight ahead
PAUSE 20······················ ' wait 20 milliseconds
NEXT·························· ' loop
PULSIN ESCin, 1, ESC_ch1······ ' check to see if signal is re-acquired
IF ESC_ch1 < 1000 THEN Backup2 ' If no signal, check whether to back up again
RETURN························ ' signal reacquired return R/C control
'Have we gone through twice? (even though we KNOW we have above)
Backup2:
event = event +· 1
IF event > 2 THEN············· ' if the number of reverses is
GOTO quit····················· ' greater than two, shut truck down
ENDIF
GOTO Backup······················ 'One more time
END
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
Thanks for the help. Both programs function the same.......including crashing at random times. The truck can be rolling back and forth controlled by the transmitter and it will just stop or sometimes I shut the transmitter off to simulate loss of signal and the stamp takes over and backs the truck up and then everything stops after the first backup. One thing I noticed is after I load the program, either yours or mine, shut the power off to disconnect the truck from my laptop and turn the truck back on again is that the truck starts in the backup mode as soon as the power comes on. (The transmitter is turned on before I turn the truck on.) The only assumption I can make is that the stamp starts running it's program before the R/C receiver can output a pulse. If the program running the truck crashes I can reset it with no harm done but if the stamp is in the airplane, it's intended purpose, and the program crashes so will the airplane with the video gear and this is not acceptable. I have to resolve this problem. Any more ideas??? I tried putting the end command in a subroutine at the very end of the program but it didn't matter.
Rick Ouellette
ps. When I submitted the code to the forum it was nice and neat with all the annotations lined up and now everything is crowded together . Why is that?