Hello Guys and Girls,
I am building an installation that has two X,Y moving carriages on either side of a room (so up/down - side/side). I have built a chassis/ frame using the coreXY method: http://corexy.com and have used this example to test the movement of the system and see if it works, which it does, phew! :
This code is in the public domain...
You can: copy it, use it, modify it, share it or just plain ignore it!
Thx!
*/
#include "AccelStepper.h"
// Library created by Mike McCauley at http://www.airspayce.com/mikem/arduino/AccelStepper/
// AccelStepper Setup
AccelStepper stepperX(1, 2, 3); // 1 = Easy Driver interface
// UNO Pin 2 connected to STEP pin of Easy Driver
// UNO Pin 3 connected to DIR pin of Easy Driver
AccelStepper stepperZ(1, 5, 6); // 1 = Easy Driver interface
// UNO Pin 5 connected to STEP pin of Easy Driver
// UNO Pin 6 connected to DIR pin of Easy Driver
// Stepper Travel Variables
long TravelX; // Used to store the X value entered in the Serial Monitor
long TravelZ; // Used to store the Z value entered in the Serial Monitor
int move_finished=1; // Used to check if move is completed
void setup() {
Serial.begin(9600); // Start the Serial monitor with speed of 9600 Bauds
// Print out Instructions on the Serial Monitor at Start
Serial.println("Enter Travel distance seperated by a comma: X,Z ");
Serial.print("Enter Move Values Now: ");
// Set Max Speed and Acceleration of each Steppers
stepperX.setMaxSpeed(400.0); // Set Max Speed of X axis
stepperX.setAcceleration(500.0); // Acceleration of X axis
stepperZ.setMaxSpeed(400.0); // Set Max Speed of Y axis slower for rotation
stepperZ.setAcceleration(500.0); // Acceleration of Y axis
}
void loop() {
while (Serial.available()>0) { // Check if values are available in the Serial Buffer
move_finished=0; // Set variable for checking move of the Steppers
TravelX= Serial.parseInt(); // Put First numeric value from buffer in TravelX variable
Serial.print(TravelX);
Serial.print(" X Travel , ");
TravelZ= Serial.parseInt(); // Put Second numeric value from buffer in TravelZ variable
Serial.print(TravelZ);
Serial.println(" Y Travel ");
stepperX.moveTo(TravelX); // Set new move position for X Stepper
stepperZ.moveTo(TravelZ); // Set new move position for Z Stepper
delay(1000); // Wait 1 seconds before moving the Steppers
Serial.print("Moving Steppers into position...");
}
// Check if the Steppers have reached desired position
if ((stepperX.distanceToGo() != 0) || (stepperZ.distanceToGo() !=0)) {
stepperX.run(); // Move Stepper X into position
stepperZ.run(); // Move Stepper Z into position
}
// If move is completed display message on Serial Monitor
if ((move_finished == 0) && (stepperX.distanceToGo() == 0) && (stepperZ.distanceToGo() == 0)) {
Serial.println("COMPLETED!");
Serial.println("");
Serial.println("Enter Next Move Values (0,0 for reset): "); // Get ready for new Serial monitor values
move_finished=1; // Reset move variable
}
}
the trouble is that i want to have this thing running constantly without me having to type inputs each time!
a feasible option for this is the random stepper function:
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
void setup()
{
}
void loop()
{
if (stepper.distanceToGo() == 0)
{
// Random change to speed, position and acceleration
// Make sure we dont get 0 speed or accelerations
delay(1000);
stepper.moveTo(rand() % 200);
stepper.setMaxSpeed((rand() % 200) + 1);
stepper.setAcceleration((rand() % 200) + 1);
}
stepper.run();
}
this would be better because it would look great! but as is it might break off the wall if the trolly was randomly pulled to far left/right/up/down
It would be awesome if someone could shed some light onto how to stop this random movement from going to far out of the sides of my frame; since this is a 2 by 2 meter metal structure .
sorry for being such a noob, i wanna learn this stuff
Cheers, in advance