Method Behind the Motors of MarBLAM!



            This is a picture of the wiring for the input buttons. The code is still being fine tuned. I need to do some more research on vectors, or arrays, for C++ since coming from most recently using Matlab. If I can get the arrays to work in the same way that can manipulate them in Matlab, the code should work as planned.

            The code is now complete and allows the user to enter the sequence of the movements they would like all in one pass. After they enter the sequence, they then press the 'run' button to execute it. After the sequence runs the sequence list is cleared and ready to receive another set of movements. If they find that there sequence is wrong during the execution they can press the 'stop' button which ends the sequence right there, or in the code pulls out of the loop, and then resets the sequence to empty. This code was slightly tricky to me put I am very pleased with the results. 

            This is the updated code that now has built in functions. This allows the user to only need to input "right" "left" "front" or "back" in a list to execute the code they want. I also created a way for the them to view what step the code is on by using the serial monitor.

            Having never created new function in arduino I was unsure of why I was receiving certain error codes. Eventually I found out that you can not have nested function in and had to move the new functions I made outside the 'void loop ()' and it finally worked.

            The next set of code that I would like to write is a way for the user to only have to push momentary switches that would then write the code its-self. Then all the user would need to do is push another run button, and on a separate LCD screen the code that is being run could also be visible. This setup would allow for the toy to not be reliant on the need of a computer and could be used by an even younger child.




 #include <AFMotor.h>

AF_Stepper motor1(48, 1);
AF_Stepper motor2(48, 2);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");

  motor1.setSpeed(100);
  motor2.setSpeed(100);        // rpm  
  
}

void loop() { //in this section the user will input the dirctions that it want the platform to tilt. 
right();
left();
right();
front();
back();
               // The user should open up the serial monitor, the looking glass in the top right hand corner, when runnning code to see the code execute 
    
}


 void right()                                       // these are the functions that the user calls when entering "right" "left" "front" or "back" 
{  Serial.println("Right");
  motor1.step(100, FORWARD, DOUBLE); 
  motor1.step(100, BACKWARD, DOUBLE);
  delay(1000);
}

void left()
{  Serial.println("Left");
  motor1.step(100, BACKWARD, DOUBLE);
  motor1.step(100, FORWARD, DOUBLE); 
  delay(1000);  
}

void back()
 { Serial.println("Back");
  motor2.step(100, FORWARD, DOUBLE); 
  motor2.step(100, BACKWARD, DOUBLE);
  delay(1000);
}

void front()
{  Serial.println("Front");
  motor2.step(100, BACKWARD, DOUBLE);
  motor2.step(100, FORWARD, DOUBLE); 
  delay(1000);
}

No comments:

Post a Comment