electric glider fun

golfnut

Member
Hi Im a nubie too, not good at this stuff. Ordered some HW and 08m chip.

Im helping an old boy at my model flying club. He likes free flight models - you start the motor and throw. A few seconds later after the climb the motor stops and you get the short floaty unpowered flight, the model comes down softly as a glider.

I did some scrappy code which does ok on the simulator.
I wanted to add safety features to it, but my mind cant make the extra step..

Currently I have,,,

If the push button on the fuselage is left alone, the code loops around a gosub Motor_off
If pilot wants to fly - pushes the momentary action button and gosub Motor_on occurs and then times out and returns.

(This is effectively what he has now on his model using r's and c's and a mosfet..)


The safety features I want to add to the existing code - if I could - are....

1)If the button for flight is knocked momentarilly by accident the motor should not run but if held down for 0.5seconds to 2seconds - run the motor

2)If the button has been pushed for between 0.5 and 2 seconds and the motor is running - the pilot can abort the motor run by pushing the button - either momentarily of for longer. The code should filp or return back to main and be ready to start off again after the panick abort.

Im struggling with the flowchart description of paralelling up code tasks or blocks. I tend to see a flowchart as a serial flow from start to end, I dont know how to put parallel flows into the design.

Any help appreciated,

Steve
 

Attachments

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum.

A lot can depend on how your specification is written. The more succinct and accurate the better you'll be able to translate that into code ...

1)If the button for flight is knocked momentarilly by accident the motor should not run but if held down for 0.5seconds to 2seconds - run the motor

So what you are really saying is a push less than 0.5s is ignored, a push of 0.5s or more turns the motor on. The "to 2 seconds" is redundant.

2)If the button has been pushed for between 0.5 and 2 seconds and the motor is running

Now redundant, because the motor will be on after 0.5s.

the pilot can abort the motor run by pushing the button - either momentarily of for longer.

So, if the motor is running, any button push will stop the motor, how long the push is for is redundant. A second push implies a previous release of the button.

Hopefully this gives you a clearer spec which you should find much easier to implement, a sequential rather than parallel flow ...

1) If button held for longer than 0.5s ...
2) Start Motor
3) If button released then
4) If button is pressed ...
5) Stop motor

To include your flight time for auto-shut off, the 4) becomes -

4) If button pushed or motor has been running for X seconds ..."
 

golfnut

Member
food for thought

Hi Hippy, thanks for the help. I will have a think on how to do what you describe. Serial is more managable for me currently. It was my first attempt last night. Ill do some more tonight and post.

If you would take a look maybe tomorrow that would be great.

I see some posts have a panel headed 'code' where the code is shown in a window, I tried to do this but I guess I just did an attachment. How does one do the code panel thing to show your code?

Golfnut
 

golfnut

Member
where its at

Hi, thanks Ibenson and mpep.

The bit of code I have seems ok. I have the 08M chip going into a futaba servo currently to viualise what the code does. This code in final form will feed an electronic speed controller (ESC) and 3phase model aero motor.

Code:
init: 	servo 4,75	                           'initialise servo

main:
label_6B:	gosub Motor_KILL		          'Safety first, Kill Motor
label_6:	if pin2=1 then label_6	          'Nobody touched button - NO Motor
		pause 2000				
		if pin2=0 then label_48     'After 2sec wait, is button down for flight?
		goto label_6B

label_48:	            gosub motor_slow	       'So you wants to fly, Fire up motor on Slow 
	            if pin2=1 then label_6B   'Final abort chance, before slow motor run ends
		gosub motor_full	       'Botton still in so Rev to Max power and throw!!!!!
		gosub motor_cruise       'Urgent ascent over, short topping off cruise
		gosub motor_off	       'Finished with motor, shut it off for now
		goto label_6B	       'Finished flight cycle, back to start

motor_off:	
		servopos 4, 75
		return
motor_slow:	
		servopos 4, 110
		pause 3000
		return
motor_full:	
		servopos 4, 200 
		pause 6000
		return
motor_cruise:	
		servopos 4, 140
		pause 4000
		return
Motor_KILL:	
		servopos 4, 75
		return0
Hope this is useful or interesting to someone, on to the next bright idea!!
Golfnut
 
Top