Last active
July 17, 2019 11:04
-
-
Save brian-kiplagat/65b7c34de9167cf5831c0be4a8db3ba6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//electric cycle engine for test in conjuction with gas generator.....pump to force kerosene through heat exchange......releies on good batteries...simplifies plumbing.... | |
/*#define takeoff;//define a function to be called at takeoff | |
#define landing;//define a function to be called at landing*/ | |
#include <NMEAGPS.h>//include neo gps library to guide rocket during landing | |
#include <Servo.h> | |
Servo extractionvalve, refillingvalve, mainoxygenvalve, mainkerosenevalve, chamberoxygenvalve, chamberkerosenevalve, Xaxis, Yaxis, gas; //declare servo types | |
const int startermotorrelay2 = 14; //set startermotorrelay2 to pin 13(power starter motor with internal-on board battery power) | |
const int sparkplug2 = 15;//lights up combustion engine | |
const int parachuterelay = 16;//lights up explosive bolts to eject parachute | |
const int leglock = 16; | |
const int conelock = 18; | |
void setup() { | |
//---------------------------------------------------------- | |
// set up relays,solenoid locks as outputs: | |
pinMode(startermotorrelay2, OUTPUT); | |
pinMode(sparkplug2, OUTPUT); | |
pinMode(parachuterelay, OUTPUT); | |
pinMode(leglock, OUTPUT); | |
//------------------------------------------------------ | |
//lock up everything | |
digitalWrite(conelock, LOW); //setting lock off closes it,setting it on opens it(two locks powered by one relay or transistor) | |
digitalWrite(leglock, LOW); //Close leg clamps(three locks powered by one relay or transistor) | |
//------------------------------------------------------ | |
//set up all valves | |
//attach servo valves to PWM pins OF MEGA | |
extractionvalve.attach(15); | |
refillingvalve.attach(16); | |
mainoxygenvalve.attach(17); | |
mainkerosenevalve.attach(18); | |
chamberoxygenvalve.attach(21); | |
chamberkerosenevalve.attach(22); | |
Xaxis.attach(26); | |
Yaxis.attach(27); | |
gas.attach(25); | |
//-------------------------------------------------------------- | |
//close all valves for safety | |
//------------------------------------------------------- | |
refillingvalve.write(0);//close oxygen refilling valve at the start before powering rocket | |
mainoxygenvalve.write(0);//fully close main oxygen valve | |
mainkerosenevalve.write(0);//fully close main kerosene valve | |
chamberoxygenvalve.write(0);//fully close chamber oxygenvalve | |
chamberkerosenevalve.write(0);//fully close chamber kerosene valve | |
gas.write(0);//close leg gas cylinder | |
} | |
void loop() { | |
if (Serial.available() > 0) { | |
char data = Serial.read(); | |
switch (data) { | |
case '1'://case for takeoff | |
//turbine engine start | |
//************************************************************************************************************************************************************ | |
extractionvalve.write(20);//open exraction valve a bit to replalce outgoing kerosene,enabling rocket to function efficiently | |
mainoxygenvalve.write(90);//fully open main oxygen valve | |
mainkerosenevalve.write(90);//fully open main kerosene valve | |
digitalWrite(startermotorrelay2, HIGH); //turn on starter motor with relay that routes power from launch pad into the motor to spin turbine | |
delay(5000);//delay 5 seconds for turbine to get up to full speed | |
//main engine start | |
//---------------------------------------------------------------- | |
chamberoxygenvalve.write(90);//fully open chamber oxygenvalve to allow oxygen in | |
chamberkerosenevalve.write(90);//fully open chamber kerosene valve to allow fuel in | |
//-----------and take off---------------------------------------- | |
break; | |
//****************************************************************************************************************************************************************** | |
/* case'2': | |
//The rocket is in space. | |
digitalWrite(solenoidlock, HIGH); //The solenoid locks in the cones open to unlock allowing steppers to do their work | |
Serial.println("clockwise"); // step one revolution in the other direction: | |
conestepper.step(stepsPerRevolution);//the stepper motor in the cone rotates clockwise to open cone | |
delay(500);//Wait for full opening | |
//deploy payload. | |
// step one revolution in the other direction: | |
Serial.println("counterclockwise"); | |
conestepper.step(-stepsPerRevolution);//the stepper motor in the cone rotates counterclockwise to close cone | |
delay(500);//Wait for full closing | |
digitalWrite(solenoidlock, LOW); //The solenoid locks in the cones close to lock allowing landing to occur | |
break; | |
//************************************************************************************************************************************************** | |
*/ | |
case '0': | |
//---------------------------------------- | |
//tilt the craft to fire into the trajectory to slow down | |
//get data from accelerometers | |
//get data to cause cold thrusters to flip the craft | |
//get the hypergolic stuf to react | |
//open valves to let fuel and oxygen react to produce thrust and slow the craft | |
//get data from gyro/acelerometer to bring the craft into vertical position for decent using cold thrusters | |
//get drid fins to manipulate rocket position for a while. | |
//get rocket to riignite using hypergolic stuff to slow it down | |
//get a combination of rocket burns to slow the rocket down a bit | |
//at a sulitable altitude get the parachute to deploy. | |
//use gps data to control the accuracy of the descent using vectored-thrust....enabled by using hydraulic or servo gimbals | |
//we can let the descent be piloted | |
//at 700 metres fire rockets to slow it down | |
//at 350 metres unclamp the legs | |
//since were using parrachutes...vectored thrust can take the rocket to very accurate points | |
//this will need to be man guided using google maps in real time | |
//--------------------wait for data on the I2C bus and execute data in cases// | |
if (Serial.available() > 0) { | |
char data = Serial.read(); | |
if (data == '1') { | |
//if height is less than 2000 metres try to land and deploy legs | |
//map deceleration to effective thrust such that increased deceleration speed leads to increesd thrust | |
digitalWrite(startermotorrelay2, HIGH); //turn on starter motor with relay that routes power from battery into the motor to spin turbine | |
digitalWrite(sparkplug2, HIGH); //turn on a spark to ignite reaction in combustion chamber | |
extractionvalve.write(20);//open exraction valve a bit to replalce outgoing kerosene,eabling rocket to function efficiently | |
mainoxygenvalve.write(90);//fully open main oxygen valve | |
mainkerosenevalve.write(90);//fully open main kerosene valve | |
chamberoxygenvalve.write(0);//fully OPEN chamber oxygenvalve | |
chamberkerosenevalve.write(0);//fully OPEN chamber kerosene valve | |
} | |
if (data == '2') { //if height is less than one kilometer continue firing | |
digitalWrite(startermotorrelay2, HIGH); //turn on starter motor with relay that routes power from battery into the motor to spin turbine | |
digitalWrite(sparkplug2, HIGH); //turn on a spark to ignite reaction in combustion chamber | |
extractionvalve.write(20);//open exraction valve a bit to replalce outgoing kerosene,eabling rocket to function efficiently | |
mainoxygenvalve.write(90);//fully open main oxygen valve | |
mainkerosenevalve.write(90);//fully open main kerosene valve | |
chamberoxygenvalve.write(0);//fully OPEN chamber oxygenvalve | |
chamberkerosenevalve.write(0);//fully OPEN chamber kerosene valve | |
//unclamp the legs and allow them to extend.....the system is powered by high pressure gas..for quick leg deployment | |
// unclamp legs | |
Serial.println("unclamping legs"); | |
digitalWrite(leglock, HIGH); //turn on solenoid lock to unclamp the legs allowing them to extend(three locks powered by one relay or transistor)...powered by a cylinder of compressed gas..tubes feed the legs from one servo valve | |
gas.write(180);//fully open gas cylinder for leg exttension | |
delay(500); | |
} | |
if (data == '3') { //if height is less than 500 metre continue firing | |
digitalWrite(startermotorrelay2, HIGH); //turn on starter motor with relay that routes power from battery into the motor to spin turbine | |
digitalWrite(sparkplug2, HIGH); //turn on a spark to ignite reaction in combustion chamber | |
extractionvalve.write(20);//open exraction valve a bit to replalce outgoing kerosene,eabling rocket to function efficiently | |
mainoxygenvalve.write(90);//fully open main oxygen valve | |
mainkerosenevalve.write(90);//fully open main kerosene valve | |
chamberoxygenvalve.write(90);//fully OPEN chamber oxygenvalve | |
chamberkerosenevalve.write(90);//fully OPEN chamber kerosene valve | |
//rocket sholuld reener at less than 500kph...then let the parachute absorb much of that speed | |
//get accelerometrers to read its orientation then flip the rocket to face opposite the trajectory using cold thrusters...fire rocket into trajectory to slow it down for landing | |
//get gps to lead the rocket to a slow touch down | |
// i have no freakin idea...lemme get gps library to guide the rocket down | |
//also have to get mpu-6050 library to see how...the idea is to wait and see if the rocket starts decending...at the point of apogee..the first stage separates | |
//....cold gas thrusters fire to change orientation of the fist stage into the opposite direction..engines light up and fire into the new direction...to slow down the space | |
//craft....then grid fins deploy to guide the craft into desired trajectory.....then it fires engines to slow down a bit....grid fins continue guiding properly | |
//at a desired altiude say 1km....engines fire to bring the space craft to a halt on the ground... | |
//near the gound the mpu6050 maps changes in y acceleration/y gyro and slightly maps the readings to y servo to adjust orientation for one straight deceleration | |
} | |
if (data == '4') { //if height is less than one metre turn off every thing | |
digitalWrite(startermotorrelay2, LOW); //turn on starter motor with relay that routes power from battery into the motor to spin turbine | |
digitalWrite(sparkplug2, LOW); //turn on a spark to ignite reaction in combustion chamber | |
extractionvalve.write(0);//open exraction valve a bit to replalce outgoing kerosene,eabling rocket to function efficiently | |
mainoxygenvalve.write(0);//fully open main oxygen valve | |
mainkerosenevalve.write(0);//fully open main kerosene valve | |
chamberoxygenvalve.write(0);//fully OPEN chamber oxygenvalve | |
chamberkerosenevalve.write(0);//fully OPEN chamber kerosene valve | |
} | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment