/* program to run 2 cyclyes simutainiously.
one cycle is faster than the other so the LCD is supposed to tick up faster as it runs.
process for 1 elevator.
take a load from the load area to the dump area
dump load and go back to load area.
elevator dumps into a storage area which in turn dumps into the loading area
the speed of the elevator is the only difference between cycles
one has to slow down as it approaches the dump area
approximate time difference between cycles could be as much as 30 seconds
when hcycle gets to 9999 scycle goes to 0 and hcycle is set to the difference between the cycles.
when the difference between the cycles is 9999 both cycles reset to 0
*/
//Global variables
long currentmilis; // the time when the loop iterates
long Hydralicstart; //the last time the hydralic cycle started
long Scrollstart;
long Hcycle //the time it take to complete one hydralic cycle
long Scycle =
int Falltime=1000; //1 second
int MaxS = 6000 //6000steps per minute(200steps per revolution- 30 rpm)
int CreepS = MaxS* 0.25 //creep speed is 1/4 of max speed
int Hnum = 0 //# of hydralic cycles completed sice
int Snum = 0 //# of scroll cycles completed
int loaddeg = ; //degres the loading servos need to turn
int storedeg = ; //degrees the storage servos need to turn
//Define pins (still no hardware in)
output to motor 1 and 2(1=hydralic 2=scroll)
outpus to solenoid 1 and servo 2-5(1=hydralic dump,2=hydralic storage,3=hydralic load,4=scroll storage,5=scroll load)
output to led screen 1 and 2(1=hydralic display, 2=scroll display)
input from start and reset bottons
//--------------------------------------------------------------------------------//
void startup()
{
}
//--------------------------------------------------------------------------------//
void loop()
{
currentmilis = milis();
if (start = High) //checks to see if the button is on
{
HydralicCycle;
ScrollCycle;
if (Hnum = 9999) //if the lcd is at 9999 subtract Snum from Hnum and then set Snum to 0
{
Hnum=Hnum-Snum;
Snum=0;
}
if (Hnum-Snum=9999) //if the diference between the two cycles is 9999 set both to 0
{
Hnum=0;
Snum=0;
}
}
If (reset = high)
{
Hnum=0;
Snum=0;
//move both skips to dump position
//close all gates
}
}
//--------------------------------------------------------------------------------//
Void ScrollCycle()
{
int faststeps; //number of steps to take when moving fast
int slowsteps; //number of steps to take when moving slow
int Slowmove = slowstep/CreepS; //time in milis to complete the movement
int fastmove = faststep/MaxS; //time in milis to complete the movement
if (currenttime >= Scrollstart + Scycle) //if it has been enough time to complete a cycle since the last cycle. start a cycle
{
Scrollstart = currenttime; //the start of the cycle is recorded.
MoveMotor(2,D,slowsteps,CreepS) // bring skip to below scrolls
}
if (currenttime >= Scrollstart + slowmove)
{
MoveMotor(2,D,faststeps,MaxS) // bring skip to shaft bottom
}
if (currenttime >= Scrollstart + slowmove + fastmove) //if skip has reached shaft bottom
{
Sevocontrol(5,open,loaddeg) //load it
}
if (currenttime >= Scrollstart + slowmove + fastmove + falltime) // after it loads
{
Sevocontrol(5,close,loaddeg) //close loading gate
MoveMotor(2,U,faststeps,MaxS) // max speed to just below scrolls
Sevocontrol(4,open,storedeg) //open the storage gate
}
if (currenttime >= Scrollstart + slowmove + fastmove + 2*falltime) //while skip movin to top
{
Sevocontrol(4,close,storedeg) //close the storage gate
}
if (currenttime >= Scrollstart + slowmove + 2*fastmove + falltime) //what skip reached scrolls. fast move >> falltime
{
MoveMotor(2,U,slowsteps,CreepS) // skip creeps through scrolls
}
if (currenttime >= Scrollstart + 2*slowmove + 2*fastmove + falltime)
{
Snum++
Scrolldisplay;
}
}
//--------------------------------------------------------------------------------//
Void HydralicCycle()
{
movesteps = //number of steps to moce from top to bottom
movetime = //time in milis to complete the movment
if (currenttime >= Hydralicstart + Hcycle) //if it has been enough time to complete a cycle since the last cycle. start a cycle
{
Hydralicstart = currenttime; //the start of the cycle is recorded.
MoveMotor(1,D,movesteps,MaxS) // bring skip to shaft bottom
}
if (currenttime >= Hydralicstart + movetime)
{ //after the skip has finished moving
Sevocontrol(3,open,loaddeg) //rotate servo 3 to load the skip
}
if (currenttime >= Hydralicstart + movetime + falltime)
{ //after the load has fallen in
Sevocontrol(3,close,loaddeg)
MoveMotor(1,U,movesteps,MaxS) // order skip to top position
Sevocontrol(2,open,storedeg) // While skip onroute. storage dumps into loading area
}
if (currenttime >= Hydralicstart + movetime + 2*falltime)
{ //after load has fallen out of storage
Sevocontrol(2,close,storedeg)
}
if (currenttime >= Hydralicstart + 2*movetime + falltime)
{ //after skip moves to the dump position
solenoidtoggle; //toggle solenoid state( on)
}
if (currenttime >= Hydralicstart + 2*movetime + 2*falltime)
{ //after the skip dumps
solenoidtoggle;
Hnum++
Hydralicdisplay;
}
}
//--------------------------------------------------------------------------------//
void MoveMotor(motor#,up or down,#ofSteps,Max or creep)
{
//code to turn the correct motor by the correct amount at the correct time
}
//--------------------------------------------------------------------------------//
void Sevocontrol(Servo#, Open or closed, degrees)
{
//code to open or close the correct sevo
}
//--------------------------------------------------------------------------------//
void solenoidtoggle()
{
If (solenoidstate = high) //if the solenoid is on, turn it off
{
solenoidstate = low
}
else //else if it is off, turn it on
{
solenoidstate = high
}
}
//--------------------------------------------------------------------------------//
void Scrolldisplay()
{
//uses the global Snum and prints it to the LED screen
}
//--------------------------------------------------------------------------------//
void Hydralicdisplay()
{
//uses the global Hnum and prints it to the LED screen
}
This is my code now. I think this should work in terms of my states.
Haven't put in the parts that send output to the motors or servos etc.
Still trying to figure out the LED screen and which method to use when talking to it.
And still don't have the parts yet so pin numbers still are up in the air. Hopeing when i do get them in I will have a program that is ready to test
Tried to add all the correct grammar in the code. I know I'm missing semicolons and stuff. It's a lot better than my first draft
Matt
Edit: Attached the notepad version if that is easier to look at
CodeVersion2.txt (6.34 KB)