// These define all the pin outs for the Rambo board
#define ELECTRONICS "RAMBo11b"
#define stepPinX1 37//function D37 , port PD7
#define dirPinX1 48//function D48 , port PL1
#define X_MIN_PIN 12//function PWM12, port PB6
#define X_MAX_PIN 24//function D24 , port PA2
#define enPinX1 29//function D29 , port PA7
#define X_MS1_PIN 40//function D40 , port PG1
#define X_MS2_PIN 41//function D41 , port PG0
#define stepPinY 36//function D36 , port PC1
#define dirPinY 49//function D49 , port PL0
#define Y_MIN_PIN 11//function PWM11, port PB5
#define enPinY 28//function D28 , port PA6
#define Y_MS1_PIN 69//function A15 , port PK7
#define Y_MS2_PIN 39//function D39 , port PG2
//These step pin X2 take place of the Z pinout. The Z pin actually goes from the board to the second x axis motor
#define stepPinX2 35//function D35 , port PC2
#define dirPinX2 47//function D47 , port PL2
#define enPinX2 27//function D27 , port PA5
#define stepPinE0 34//function D34 , port PC3
#define dirPinE0 43//function D43 , port PL6
#define enPinE0 26//function D26 , port PA4
#define E0_MS1_PIN 65//function A11 , port PK3
#define E0_MS2_PIN 66//function D12 , port PK4
#define MOTOR_CURRENT_PWM_XY_PIN 46//function D46 , port PL3
#define MOTOR_CURRENT_PWM_Z_PIN 45//function D45 , port PL4
#define MOTOR_CURRENT_PWM_E_PIN 44//function D44 , port PL5
#define LED_PIN 13//function PWM13, port PB7
//These are as named. These focus on how fast, far, and long the motors move, respectively.
float speedMove = 40; //mm/s
float speedHome = 70; //mm/s
float steps = .15; //mm/step (distance of one step)
int tMove = (steps / (speedMove*2))*1000000;// microsec
int tHome = (steps / (speedHome*2))*1000000;// microsec
//Below we will be defining the buffer size for the probe that will be navigating around the field attached to the end of the positioner. Also
//will be defining the 0,0 point in the x and y plane. CENTER PROBE FOR THIS ITERATION OF CODE!
//Setup function initializes all the outputs and inputs of the system
pinMode(stepPinY, OUTPUT); //function D36 , port PC1
pinMode(dirPinY, OUTPUT); //function D49 , port PL0
pinMode(enPinY, OUTPUT); //function D28 , port PA6
pinMode(stepPinX1, OUTPUT); //function D37 , port PD7
pinMode(dirPinX1, OUTPUT); //function D48 , port PL1
pinMode(enPinX1, OUTPUT); //function D29 , port PA7
pinMode(stepPinX2, OUTPUT); //function D35 , port PC2
pinMode(dirPinX2, OUTPUT); //function D47 , port PL2
pinMode(enPinX2, OUTPUT); //function D27 , port PA5
pinMode(stepPinE0, OUTPUT); //function D34 , port PC3
pinMode(dirPinE0, OUTPUT); //function D43 , port PL6
pinMode(enPinE0, OUTPUT); //function D26 , port PA4
//Starts the serial monitor in order to give commands to the motors.
//Sets direction of x-axis motors to negative (left)
digitalWrite(dirPinX2,HIGH);
digitalWrite(dirPinX1, LOW);
//Sets direction of x-axis motors to positive (right)
digitalWrite(dirPinX2,LOW);
digitalWrite(dirPinX1, HIGH);
//Sets direction of y-axis motor to negative (left)
digitalWrite(dirPinY, LOW);
//Sets direction of y-axis motor to positive (right)
digitalWrite(dirPinY, HIGH);
//This function will move in the x direction a specified amount (int X) in mm, in the specified direction (int dir)
float moveX(int X, int dir){
for (int i = 0; i < numxSteps; i++) {
digitalWrite(stepPinX2,HIGH);
digitalWrite(stepPinX1, HIGH);
delayMicroseconds(tMove);
digitalWrite(stepPinX2,LOW);
digitalWrite(stepPinX1, LOW);
delayMicroseconds(tMove);
float moveY(int Y, int dir){
for (int i = 0; i < numySteps; i++) {
digitalWrite(stepPinY,HIGH);
delayMicroseconds(tMove);
digitalWrite(stepPinY, LOW);
delayMicroseconds(tMove);
////TAKE USER INPUT FOR X OR Y////
while (!Serial.available()){
if (ans == 1 or ans == 2){//move along x- or y-axis
////TAKE USER INPUT FOR NEGATIVE OR POSITIVE////
while (!Serial.available()){
////TAKE USER INPUT FOR DISTANCE////
while (!Serial.available()){
int dist = Serial.read();
if (ans == 1){//move along x-axis
}else if (ans == 2){//move along y-axis