Can someone help

danielwi11iams

New Member
Sorry for a long Thread...

I have some code, but would like to add one more part to the program, but I running out of chip space.

I'm using it to control three servos, and slow them down on a model RC helicopter. I need the servo for the front doors to reverse after the wheels have come down and visa versa when they go up. But when I add it to the code/program it makes it to long to fit in the chip memory. I'm new to this and have a very small knowledge of PIC programming. is their a way of making the program smaller.

i.e. trying to make it do what I want it to do but maybe using different commands.

Any help would be appreciated.

Here is my code: there maybe some mistakes, but I can correct them if there is away of making it smaller...




'*** Memory Lables ***
Symbol Delay=B1 'Name the Delay Factor
Symbol Skip=B2 'Name the Counter For Skipping "Delay" Times
Symbol Pulsein=B3 'Name the Input Pulse Width
Symbol PulseB4=B4 'Name the Width Of the prior Input Pulse Width
Symbol FrtDoor=B5 'Name the Output Pulse Width for Front Doors
Symbol BothDoor=B6 'Name the Output Pulse Width for Back Doors
Symbol PulWheel=B7 'Name the Output Pulse Width for Wheels
Symbol ErrFrtDrs=B8 'Name the Difference between Input and Output Pulse Width
Symbol ErrBckDrs=B9 'Name the Difference between Input and Output Pulse Width
Symbol ErrWheels=B10 'Name the Difference between Input and Output Pulse Width

Init:
Servo 0,135 'Front Door Servo
Servo 1,135 'Back Door Servo
Pause 1000
Servo 2,135 'Wheels Servo
Main:
Skip=0
Low 0,1,2 'Stop the Servo command if valid input detected
Readadc 4,Delay 'Read the voltage from the delay potentiometer
Pause 1000
Pulsin 3,1,Pulsein 'Measure the input pulse width initially
If Pulsein<75 or Pulsein>225 then Main 'Go back if no valid input detected
PulseB4=Pulsein 'Initially set the prior pulse width to current pulse width
If Delay<5 then StraightThru 'If delay pot set near zero skip slowdown routines
Delay=Delay/21 'Set delay to 0 (1.5s stop-to-stop) to 12 (20s stop-to-stop)
FrtDoor=Pulsein 'Set output pulse to input pulse initially
PulseWheel=Pulsein
Submain: 'Routine
PulseB4=Pulsein 'Reset the prior pulse width
Pulsin 3,1,Pulsein 'Measure the input pulse
If Pulsein<75 or Pulsein>225 then Main 'Go back if no valid input detected


MoveUp1: 'Routine = To Open the Doors to allow the wheel to go up into the body
ErrFrtDrs=Pulsein-FrtDoor
If ErrFrtDrs=0 or ErrFrtDrs>254 then StayPut
If FrtDoor>Pulsein then FrtDrsOpen
MoveUp2: 'Routine = To allow Wheels to go into the body
ErrWheels=Pulsein-PulseWheel
If ErrWheels=0 or ErrWheels>254 then StayPut
If PulseWheel<Pulsein then WheelsUp
MoveUp3: 'Routine = To close both Doors after the Wheels have gone into the body
ErrDoors=Pulsein-BothDoor
If ErrDoors=0 or ErrDoors>254 then StayPut
If BothDoor<Pulsein then DoorUp

MoveDown1: 'Routine = To Open both Doors before the Wheels come out of the body
ErrDoors=BothDoor-Pulsein
If ErrDoors=0 or ErrDoors>254 then StayPut
If BothDoor>Pulsein then DoorsOpen
MoveDown2: 'Routine = To allow Wheels to come out of the body
ErrWheels=PulseWheel-Pulsein
If ErrWheels=0 or ErrWheels>254 then StayPut
If PulseWheel>Pulsein then WheelDown
MoveDown3: 'Routine = To Close the Doors after the wheels have came out of the body
ErrFrtDrs=ErrFrtDrs-Pulsein
If ErrFrtDrs=0 or ErrFrtDrs>254 then StayPut
If FrtDoor<Pulsein then FrtDrsClose


'***Servo Change For Wheels To Come Up ***


FrtDrsOpen: 'Routine = To Open the Doors to allow the wheel to go up into the body
ErrFrtDrs=Pulsein-FrtDoor
If Skip>=Delay then FrtDrsOpen1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto FrtDrsOpen2
FrtDrsOpen1:
Skip=0
FrtDoor=FrtDoor+1
FrtDrsOpen2:
Pulsout 2,FrtDoor 'Send the output pulse to the servo
If PulseWheel=Pulsein then DoorUp1
Goto MoveUp1

WheelsUp: 'Routine = To allow Wheels to go into the body
ErrWheels=Pulsein-PulseWheel
If Skip>=Delay then WheelUp1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto WheelUp2
WheelUp1:
Skip=0
PulseWheel=PulseWheel+1
WheelUp2:
Pulsout 2,PulseWheel 'Send the output pulse to the servo
If PulseWheel=Pulsein then DoorUp1
Goto MoveUp2

DoorUp: 'Routine = To close both Doors after the Wheels have gone into the body
ErrDoors=Pulsein-BothDoor
If Skip>=Delay then DoorUp1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto DoorUp2
DoorUp1:
Skip=0
BothDoor=BothDoor+1
DoorUp2:
Pulsout 0,BothDoor 'Send the output pulse to the servo
Pulsout 1,BothDoor 'Send the output pulse to the servo
Goto MoveUp3 'Return to re-measure the input pulse


'***Servo Change For Wheels To Come Down ***

DoorsOpen: 'Routine = To Open both Doors before the Wheels come out of the body
ErrDoors=BothDoor-Pulsein
If Skip>=Delay then DoorsOpen1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto DoorsOpen2
DoorsOpen1:
Skip=0
BothDoor=BothDoor-1
DoorsOpen2:
Pulsout 0,BothDoor 'Send the output pulse to the servo
Pulsout 1,BothDoor 'Send the output pulse to the servo
If BothDoor=Pulsein then WheelDown1
Goto MoveDown1

WheelDown: 'Routine = To allow Wheels to come out of the body
ErrWheels=PulseWheel-Pulsein
If Skip>=Delay then WheelDown1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto WheelDown2
WheelDown1:
Skip=0
PulseWheel=PulseWheel-1
WheelDown2:
Pulsout 2,PulseWheel 'Send the output pulse to the servo
Goto MoveDown2 'Return to re-measure the input pulse

FrtDrsClose: 'Routine = To Close the Doors after the wheels have came out of the body
ErrWheels=FrtDoor-Pulsein
If Skip>=Delay then FrtDrsClose1 'Loop to delay change to Delay x 20ms input periods
Skip=Skip+1
Goto FrtDrsClose2
FrtDrsClose1:
Skip=0
FrtDoor=FrtDoor-1
FrtDrsClose2:
Pulsout 2,FrtDoor 'Send the output pulse to the servo
Goto MoveDown2 'Return to re-measure the input pulse


StayPut: 'Routine = To send the same output pulse
Pulsout 0,FrtDoor
Pulsout 1,BothDoor
Pulsout 2,PulseWheel
Goto Submain 'Return to re-measure the input pulse
StraightThru:
Pulsin 3,1,Pulsein
If Pulsein<75 or Pulsein>225 then Main 'Go back if no valid input detected
Goto StraightThru
 

goom

Senior Member
Hey, I recognise some of your code. Satisfying to see that some of my humble efforts have been of some use.
I have not studied your code in great detail, but my first thought is that you repeat a bunch of very similar code for the doors and wheels. Why not put the "MoveUp" and "MoveDown" code into subroutines. I think that you can use a variable such as "pulsout 2,b11", so you can set the variable appropriately depending upon which servo you are moving.
You may want to use a word variable for storing the input pusle width. An invalid pulse of >255 will be incorrectly stored to a byte variable, and may seem like a valid pulse.
Just a suggestion, but why keep measuring the input pulse width? I assume that you want to complete the full retract or wheels down sequence once started. Could you simply trigger the sequence on receipt of , say, a >170ms or <130ms pulse respectively. You may then be able to use a simple switched transmitter channel rather than waste a propotional one.
I'm not sure what happens to the servos not being moved. I think that they need a continuous refresh of pulses, or they get upset. If they just freezee at the last position, then this is not a concern.
A helicopter is, electrically, a very noisy environment. I built a simple device for switching nav. and landing lights, and the noise made them rather "unpredictable". I solved this by waiting for 4 valid and identical pulses to be detected before taking any action. I can post code if useful.
 

danielwi11iams

New Member
Any help with any code would be a big help. What do you mean about sub routines? do you mean "GOSUB" if you do, I tried this and it came up with a error after so many time of return back to it.

The reason it keeps checking for the pulse wide is so that it has a value to calculate the error movement fo the Door/Wheels.

I'm interest in what you mentioned about >170ms or <130ms pulse how would I but that in to my code, due to being new to this.

I'm using a channel on my transmitter that is a switch, not a stick, if that is any help.

Thanks
 

westaust55

Moderator
Kevin (goom),
back in thread http://www.picaxeforum.co.uk/showthread.php?p=77360#post77360 your code was acknowledged by Daniel.


Daniel,
While I had a quick look I found it difficult to follow your program.

If I can make a couple of suggestions:

1. use the [code'] and [/code'] (without the ' symbol) around your code so it appears in a sub window. This is what all forumites as asked to do in the sticky posts at the top of the active forum.
Please have a read at this:
http://www.picaxeforum.co.uk/showthread.php?t=7679

2. If you use some white space and format your program it is far easier for others to read and they are more likely to be able to understand the program flow and then give you some help.

I have done 1 and 2 below for you as a starting point.
Also note that you have a couple of alias variable names in your code that did not have SYMBOL statements. Added a couple of lines so the program syntax can be checked and size determined.


Code:
; *** Memory Labels ***
Symbol Delay     = B1  'Name the Delay Factor
Symbol Skip      = B2  'Name the Counter For Skipping "Delay" Times
Symbol Pulsein   = B3  'Name the Input Pulse Width
Symbol PulseB4   = B4  'Name the Width Of the prior Input Pulse Width
Symbol FrtDoor   = B5  'Name the Output Pulse Width for Front Doors
Symbol BothDoor  = B6  'Name the Output Pulse Width for Back Doors
Symbol PulWheel  = B7  'Name the Output Pulse Width for Wheels
Symbol ErrFrtDrs = B8  'Name the Difference between Input and Output Pulse Width
Symbol ErrBckDrs = B9  'Name the Difference between Input and Output Pulse Width
Symbol ErrWheels = B10 'Name the Difference between Input and Output Pulse Width

; these variables exist in the program but not declared in supplied code
Symbol PulseWheel = b11
Symbol ErrDoors = b12


Init:
          Servo 0,135  'Front Door Servo
          Servo 1,135  'Back Door Servo
          Pause 1000
          Servo 2,135  'Wheels Servo

Main:
          Skip=0
          Low 0,1,2          'Stop the Servo command if valid input detected
          Readadc 4,Delay    'Read the voltage from the delay potentiometer
          Pause 1000
          Pulsin 3,1,Pulsein 'Measure the input pulse width initially
          If Pulsein<75 or Pulsein>225 then Main 'Go back if no valid input detected

          PulseB4=Pulsein    'Initially set the prior pulse width to current pulse width
          If Delay<5 then StraightThru 'If delay pot set near zero skip slowdown routines
          Delay=Delay/21     'Set delay to 0 (1.5s stop-to-stop) to 12 (20s stop-to-stop)
          FrtDoor=Pulsein    'Set output pulse to input pulse initially
          PulseWheel=Pulsein

Submain: 'Routine
          PulseB4=Pulsein    'Reset the prior pulse width
          Pulsin 3,1,Pulsein 'Measure the input pulse
          If Pulsein<75 or Pulsein>225 then Main 'Go back if no valid input detected

MoveUp1: 'Routine = To Open the Doors to allow the wheel to go up into the body
          ErrFrtDrs=Pulsein-FrtDoor
          If ErrFrtDrs=0 or ErrFrtDrs>254 then StayPut
          If FrtDoor>Pulsein then FrtDrsOpen

MoveUp2: 'Routine = To allow Wheels to go into the body
          ErrWheels=Pulsein-PulseWheel
          If ErrWheels=0 or ErrWheels>254 then StayPut
          If PulseWheel<Pulsein then WheelsUp

MoveUp3: 'Routine = To close both Doors after the Wheels have gone into the body
          ErrDoors=Pulsein-BothDoor
          If ErrDoors=0 or ErrDoors>254 then StayPut
          If BothDoor<Pulsein then DoorUp

MoveDown1: 'Routine = To Open both Doors before the Wheels come out of the body
          ErrDoors=BothDoor-Pulsein
          If ErrDoors=0 or ErrDoors>254 then StayPut
          If BothDoor>Pulsein then DoorsOpen

MoveDown2: 'Routine = To allow Wheels to come out of the body
          ErrWheels=PulseWheel-Pulsein
          If ErrWheels=0 or ErrWheels>254 then StayPut
          If PulseWheel>Pulsein then WheelDown

MoveDown3: 'Routine = To Close the Doors after the wheels have came out of the body
          ErrFrtDrs=ErrFrtDrs-Pulsein
          If ErrFrtDrs=0 or ErrFrtDrs>254 then StayPut
          If FrtDoor<Pulsein then FrtDrsClose


'***Servo Change For Wheels To Come Up ***


FrtDrsOpen: 'Routine = To Open the Doors to allow the wheel to go up into the body
          ErrFrtDrs=Pulsein-FrtDoor
          If Skip>=Delay then FrtDrsOpen1 'Loop to delay change to Delay x 20ms input periods
          Skip=Skip+1
          Goto FrtDrsOpen2

FrtDrsOpen1:
          Skip=0
          FrtDoor=FrtDoor+1

FrtDrsOpen2:
          Pulsout 2,FrtDoor 'Send the output pulse to the servo
          If PulseWheel=Pulsein then DoorUp1
          Goto MoveUp1

WheelsUp: 'Routine = To allow Wheels to go into the body
          ErrWheels=Pulsein-PulseWheel
          If Skip>=Delay then WheelUp1 'Loop to delay change to Delay x 20ms input periods
          Skip=Skip+1
          Goto WheelUp2

WheelUp1:
          Skip=0
          PulseWheel=PulseWheel+1

WheelUp2:
          Pulsout 2,PulseWheel 'Send the output pulse to the servo
          If PulseWheel=Pulsein then DoorUp1
          Goto MoveUp2

DoorUp: 'Routine = To close both Doors after the Wheels have gone into the body
          ErrDoors=Pulsein-BothDoor
          If Skip>=Delay then DoorUp1 'Loop to delay change to Delay x 20ms input periods
          Skip=Skip+1
          Goto DoorUp2

DoorUp1:
          Skip=0
          BothDoor=BothDoor+1

DoorUp2:
          Pulsout 0,BothDoor 'Send the output pulse to the servo
          Pulsout 1,BothDoor 'Send the output pulse to the servo
          Goto MoveUp3 'Return to re-measure the input pulse


'***Servo Change For Wheels To Come Down ***

DoorsOpen: 'Routine = To Open both Doors before the Wheels come out of the body
          ErrDoors=BothDoor-Pulsein
          If Skip>=Delay then DoorsOpen1 'Loop to delay change to Delay x 20ms input periods
          Skip=Skip+1
          Goto DoorsOpen2

DoorsOpen1:
          Skip=0
          BothDoor=BothDoor-1

DoorsOpen2:
          Pulsout 0,BothDoor 'Send the output pulse to the servo
          Pulsout 1,BothDoor 'Send the output pulse to the servo
          If BothDoor=Pulsein then WheelDown1
          Goto MoveDown1

WheelDown: 'Routine = To allow Wheels to come out of the body
          ErrWheels=PulseWheel-Pulsein
          If Skip>=Delay then WheelDown1 'Loop to delay change to Delay x 20ms input periods
          Skip=Skip+1
          Goto WheelDown2

WheelDown1:
          Skip=0
          PulseWheel=PulseWheel-1

WheelDown2:
          Pulsout 2,PulseWheel 'Send the output pulse to the servo
          Goto MoveDown2 'Return to re-measure the input pulse

FrtDrsClose: 'Routine = To Close the Doors after the wheels have came out of the body
          ErrWheels=FrtDoor-Pulsein
          If Skip>=Delay then FrtDrsClose1 'Loop to delay change to Delay x 20ms input periods
          Skip=Skip+1
          Goto FrtDrsClose2

FrtDrsClose1:
          Skip=0
          FrtDoor=FrtDoor-1

FrtDrsClose2:
          Pulsout 2,FrtDoor 'Send the output pulse to the servo
          Goto MoveDown2 'Return to re-measure the input pulse


StayPut: 'Routine = To send the same output pulse
          Pulsout 0,FrtDoor
          Pulsout 1,BothDoor
          Pulsout 2,PulseWheel
          Goto Submain 'Return to re-measure the input pulse

StraightThru:
          Pulsin 3,1,Pulsein
          If Pulsein<75 or Pulsein>225 then Main 'Go back if no valid input detected
          Goto StraightThru
 
Last edited:

goom

Senior Member
I was not seeking acknowledgement, merely pleased to see some of my work being used.
I have put together some code which accomplish what you want to do. It runs O.K in the simulator.
It may need some additional code to keep the servos positioned initially, or once the full retract or wheels down sequence has been completed. As it stands, there are no commands going to the servos. Perhaps this is acceptable, particularly if you have, for example, an over-center locking on the doors and wheels.
Code size is 168 bytes, so 88 bytes left for a -08M. It would be really easy to, for example, turn off/on the landing lights via Out0.
Code:
'Helicopter landing gear retracts PICAXE-08M
'Kevin Goom 28 September 2008
'PICAXE-08M connections are:
' Leg 1                   +5V
' Leg 2 (Serial in)       Tie to Ground through 10K resistor
' Leg 3  (In4/Out4)    Front door servo
' Leg 4  (In3)             Pulse input from radio receiver
' Leg 5 (In2/Out2)        Wheels servo
' Leg 6 (In1/Out1)        Rear door servo
' Leg 7 (Out0/Serial Out) NC
' Leg 8                   Ground
symbol OutWh=2    'Name Wheels output pin (leg5)
symbol OutRD=1    'Name Rear Door output pin (leg6)
symbol OutFD=4    'Name Front Door output pin (leg3)
symbol Pulse_Width=w0  'Name measured input pulse width
symbol Prev_Pulse_Width=w1 'Name previous measured input pulse width 
symbol Status=b4   'Name status (0=wheels up, 1=wheels down)
symbol Pulse_In=3   'Name pulse input pin (leg4)
symbol Delay=4    'Change to slow servo as required (0= full speed, 12= approx. 20 seconds)
Status=0  'Set status 0 initially (wheels up)
Pause 500 'Wait for 1/2 second initially
Restart:
low OutWH 'Turn off all pulses to sevos
low OutRD
low OutFD
pulsin Pulse_In,1,Pulse_Width  'Measure and store input pulse
if Pulse_Width<50 or Pulse_Width>250 then Restart 'Go back if no valid pulse detected
   
for b5=0 to 3     'Wait for 4 valid and identical pulses
   Prev_Pulse_Width=Pulse_Width
   pulsin Pulse_In,1,Pulse_Width 'Measure and store input pulse
   if Pulse_Width<50 or Pulse_Width>250 then Restart 'Go back if no valid pulse detected
   if Prev_Pulse_Width<>Pulse_Width then restart
next b5
if Status = 0 then
   if Pulse_Width>175 then
      status=1  'change to wheels down status
      goto Wheels_Down 'go to routine to lower wheels
   else
      goto restart 'go back and wait for a wheels down command
   endif
else
    if Pulse_Width<125 then
      status=0  'change to wheels up status
      goto Wheels_Up'go to routine to retract wheels
   else
      goto restart 'go back and wait for a wheels up command
   endif
endif
'Note that the 120 and 180 end points will need to be tuned for fully open/closed of doors & wheels 
'You may need to move each door separately if they have different end points.
Wheels_Down:
   for b5=120 to 180 step 1 'Open front and rear doors
      for b8=0 to delay 'outputs same pulse (Dalay+1) times
         pulsin Pulse_In,1,Pulse_Width 'read pulse in for timing porposes
         pulsout OutRD,b6
         pulsout OutFD,b6
      next b8
   next b5
   
   for b5=120 to 180 step 1 'Lower wheels
      for b8=0 to delay 'outputs same pulse (Dalay+1) times
         pulsin Pulse_In,1,Pulse_Width 'read pulse in for timing porposes
         pulsout OutWh,b6
      next b8
   next b5
goto restart
Wheels_up:
   for b5=180 to 120 step -1 'Retract wheels
      for b8=0 to delay 'outputs same pulse (Dalay+1) times
         pulsin Pulse_In,1,Pulse_Width 'read pulse in for timing porposes
         pulsout OutWh,b6
      next b8
   next b5
   
for b5=180 to 120 step -1 'Close doors
      for b8=0 to delay 'outputs same pulse (Dalay+1) times
         pulsin Pulse_In,1,Pulse_Width 'read pulse in for timing porposes
         pulsout OutRD,b6
         pulsout OutFD,b6
      next b8
   next b5
goto restart
Keep us appraised of your progress, and post in finished projects when all is working well.
 

danielwi11iams

New Member
Thanks for your help, I'll have a look at your code and try and get my head around it and get back to you hopefully with the finished code.


From what I've seen it looks promising.

Thanks Again Goom.
 

danielwi11iams

New Member
I've had a look at your program and was just woundering if the output pulse for the servos (B6) should be equal to B5

just that I'm not getting any value shown on simulation.
 

danielwi11iams

New Member
Just tried the code and it works great, made some alterations to it, Thanks again, it would have taken me ages to work that out. I was going to use the "For / Next" command, but got confused me when it would not let me use some commands within the code.

Code:
' Leg 1				+5V
' Leg 2 (Serial in)		Tie to Ground through 10K resistor
' Leg 3 (In4/Out4)		Wiper of 10K potentiometer connected to +5V and ground	
' Leg 4 (In3)			Pulse input from radio receiver
' Leg 5 (In2/Out2)		Wheels servo
' Leg 6 (In1/Out1)		Rear Door Servo
' Leg 7 (Out0/Serial Out)	Front Door Servo
' Leg 8				Ground


Symbol OutWh=2    						'Name Wheels output pin (leg5)
Symbol OutRD=1    						'Name Rear Door output pin (leg6)
Symbol OutFD=0    						'Name Front Door output pin (leg7)
Symbol Pulse_Width=w0  						'Name measured input pulse width
Symbol Prev_Pulse_Width=w1 					'Name previous measured input pulse width 
Symbol Status=b4   						'Name status (0=wheels up, 1=wheels down)
Symbol Pulse_In=3   						'Name pulse input pin (leg4)
Symbol Delay=b10    						'Change to slow servo as required (0= full speed, 12= approx. 20 seconds)


Main:
	Status=0  								'Set status 0 initially (wheels up)
	Pause 500 								'Wait for 1/2 second initially
	Low OutWH 								'Turn off all pulses to sevos
	Low OutRD
	Low OutFD
	Readadc 4,Delay							'Read the voltage from the delay potentiometer (Leg 3)
	Pulsin Pulse_In,1,Pulse_Width  				'Measure and store input pulse
	If Pulse_Width<50 or Pulse_Width>250 then Main 		'Go back if no valid pulse detected
	If Delay<5 then Main						'If delay pot set near zero skip slowdown routines
	Delay=Delay/21							'Set delay to 0 (1.5s stop-to-stop) to 12 (20s stop-to-stop)

Restart:
	Pulsin Pulse_In,1,Pulse_Width  				'Measure and store input pulse
	If Pulse_Width<50 or Pulse_Width>250 then Restart	'Go back if no valid pulse detected
   
	For b5=0 to 3     							'Wait for 4 valid and identical pulses
		Prev_Pulse_Width=Pulse_Width
		Pulsin Pulse_In,1,Pulse_Width 					'Measure and store input pulse
		If Pulse_Width<50 or Pulse_Width>250 then Restart		'Go back if no valid pulse detected
		If Prev_Pulse_Width<>Pulse_Width then restart
	Next b5
		If Status = 0 then
   	If Pulse_Width>175 then
      	Status=1								'Change to wheels down status
      	Goto Wheels_Up							'Go to routine to lower wheels
   	Else
      	Goto restart							'Go back and wait for a wheels down command
   	Endif
	Else
    	If Pulse_Width<125 then
      	Status=0  								'Change to wheels up status
      	Goto Wheels_Down							'Go to routine to retract wheels
   	Else
      	Goto restart							'Go back and wait for a wheels up command
   	Endif
	Endif

'*** Note that the 120 and 180 end points will need to be tuned for fully open/closed of doors & 
'wheels, You may need to move each door separately if they have different end points.***.



Wheels_Down:
	For b5=210 to 90 Step -1 						'Open BOTH Doors
		For b8=0 to Delay							'Outputs same pulse (Dalay+1) times
		Pulsin Pulse_In,1,Pulse_Width 				'Read pulse in for timing porposes
		Pulsout OutRD,b5
		Pulsout OutFD,b5
		Next b8
	Next b5
	For b5=230 to 140 Step -1 						'Lower All Wheels
      	For b8=0 to Delay 						'Outputs same pulse (Dalay+1) times
		Pulsin Pulse_In,1,Pulse_Width 				'Read pulse in for timing porposes
		Pulsout OutWh,b5
		Next b8
	Next b5
	For b5=90 to 210 Step 1 						'Close Front Door
		For b8=0 to Delay 						'Outputs same pulse (Dalay+1) times
		Pulsin Pulse_In,1,Pulse_Width 				'Read pulse in for timing porposes
		Pulsout OutFD,b5
		Next b8
	Next b5
Goto Restart

  
Wheels_up:

	For b5=210 to 90 Step -1 						'Open Front doors
      	For b8=0 to Delay 						'Outputs same pulse (Dalay+1) times
		Pulsin Pulse_In,1,Pulse_Width 				'Read pulse in for timing porposes
		Pulsout OutFD,b5
		Next b8
	Next b5
	For b5=140 to 230 Step 1 						'Retract All Wheels
		For b8=0 to Delay 						'Outputs same pulse (Dalay+1) times
		Pulsin Pulse_In,1,Pulse_Width 				'Read pulse in for timing porposes
		Pulsout OutWh,b5
		Next b8
	Next b5
	For b5=90 to 210 step 1 						'Close BOTH Doors
		For b8=0 to delay 						'Outputs same pulse (Dalay+1) times
		Pulsin Pulse_In,1,Pulse_Width 				'Read pulse in for timing porposes
		Pulsout OutRD,b5
		Pulsout OutFD,b5
		Next b8
	Next b5
Goto Restart
Code:
	BODY OF HELICOPTOR
    `-.__________________________/       CLOSED DOORS
             


	BODY OF HELICOPTOR
    `-.__________________________/	FRONT AND REAR DOORS OPEN
           \______]      `-------


	BODY OF HELICOPTOR
   `-.__________________________/	WHEELS LOWERED
           \______][]    `-------
                   []
                  /  \
                  \__/

	BODY OF HELICOPTOR
   `-.__________________________/	FRONT DOORS CLOSED
                   []    `-------
                   []
                  /  \
                  \__/

Thanks Again Kevin, it great just what I needed.
 

goom

Senior Member
Well spotted Daniel. Yes, output pulse should be B5.
Another thought would be to use the Servo command (initially) then servopos to update the servo position. That way, you would not have to rely on continuously reading an input pulse for the timing. The sequence would then complete regardless of radio contact (but I guess that you would have bigger problems in such the event of signal loss).
You could also trap for invalid pulses during the sequence, and quickly put the wheels up or down as a default. Not sure how useful that would be. I sail RC boats (power and sail), so signal loss default settings are simpler to choose.
 

danielwi11iams

New Member
You have lost me with all of that I've only been doing it for a sort while, since I joined on here. I've not got the knowledge you have with all the commands, but would be great full for any advice.

Managed to try it in my helicopter today. Works great but I just hope it works has good when it is all finished and up and running.

If you could help out on that code for the Servo pulse that would be good.

Just that I found if the servo moves out of range, creating tension, until the pulse stops in the program. The tension build up in the servo creates a spring back with all the linkages, making the servo move back, due to no pulse. I managed to get round it changing the range numbers. but if the wheels don't lock out due to no pulse, landing funny might cause a bit of a problem.
 

goom

Senior Member
The pulsout command only gives a single pulse. It is repeated in your code every time a pulse input is recieved from the receiver (50 to 60 times per second typically).
The servo and servopos commands incorporate their own timing, and put out continuous pulses at 20us intervals until turned off in code. You need the servo command initially to get things going, then update with servopos.
The command works in the background, so you can leave it running while doing other things in your code. Hence, if you do not turn it off when the wheels are fully down, they will stay locked in this position by the servo. Definitely a better solution. Of course, when retracting, you can use the same technique, and keep them locked up. You can only use the servo commands on one pin at a time, so you cannot lock the doors and wheels at the same time. You would need another PICAXE, but ultra cheap 08's would probably suffice. They could talk to each other through input/output pins to make sure that the doors sequence is complete before lowering the gear, and vice-versa.
The following code should do the trick:

b8=20*delay
servo OutWh,120 'start the pulse stream to lower wheels
for b5=120 to 180 step 1
pause b8 'continues with same pulse width according to delay value
servopos OutWh,b5 'updates pulse to servo
next b5
goto restart 'pulse to servo continues at 180

Try it and see what happens.
 

danielwi11iams

New Member
I tried the extra bit of code, but it made all the servos go mad.

I pasted the code in to where the wheels should be in the exciting code. the program ran find until it got to the new code. once it read that code and all the servo started to operate in funny ways

So I removed it and when back to the old code, it works find. I made a circuit board for it, and placed it in to my helicopter. it looks great working.

I also put on the circuit board connections for programming the chip again (if needed) but for some reason the software will not see the chip connected to it. I've done all the connections as shown in the Getting Started PDF. any ideas.
 
Top