#include <SpeedyStepper.h>
//const int MOTOR_STEP_PINX = 3;
//const int MOTOR_DIRECTION_PINX = 4;
//ramps 1.4
const int MOTOR_STEP_PINX = 54;
const int MOTOR_DIRECTION_PINX = 55;
const int enableX = 38;
const int MOTOR_STEP_PINY = 60;
const int MOTOR_DIRECTION_PINY = 61;
const int enableY = 56;
const int MOTOR_STEP_PINZ = 46;
const int MOTOR_DIRECTION_PINZ = 48;
const int enableZ = 62;
const int MOTOR_STEP_PINA = 26;
const int MOTOR_DIRECTION_PINA = 28;
const int enableA = 24;
String dataIn = " ";
double angulosX[10];
double angulosY[10];
double angulosZ[10];
double angulosA[10];
int countX;
int countY;
int countZ;
int countA;
int x;
int y;
int z;
int a;
SpeedyStepper stepperX;
SpeedyStepper stepperY;
SpeedyStepper stepperZ;
SpeedyStepper stepperA;
void setup() {
stepperX.connectToPins(MOTOR_STEP_PINX, MOTOR_DIRECTION_PINX);
stepperY.connectToPins(MOTOR_STEP_PINY, MOTOR_DIRECTION_PINY);
stepperZ.connectToPins(MOTOR_STEP_PINZ, MOTOR_DIRECTION_PINZ);
stepperA.connectToPins(MOTOR_STEP_PINA, MOTOR_DIRECTION_PINA);
Serial.begin(9600);
pinMode(enableX, OUTPUT);
digitalWrite(enableX, LOW);
pinMode(enableY, OUTPUT);
digitalWrite(enableY, LOW);
pinMode(enableZ, OUTPUT);
digitalWrite(enableZ, LOW);
pinMode(enableA, OUTPUT);
digitalWrite(enableA, LOW);
}
void loop() {
Serial.println(angulosX[0]);
Serial.println(angulosY[0]);
Serial.println(angulosZ[0]);
Serial.println(angulosA[0]);
if (Serial.available() > 0) {
dataIn = Serial.readStringUntil('\n');
if (dataIn.startsWith("X"))
{
angulosX[countX] = dataIn.substring(1, dataIn.length()).toDouble();
countX += 1;
//Serial.println(count);
}
if (dataIn.startsWith("Y"))
{
angulosY[countY] = dataIn.substring(1, dataIn.length()).toDouble();
countY += 1;
//Serial.println(count);
}
if (dataIn.startsWith("Z"))
{
angulosZ[countZ] = dataIn.substring(1, dataIn.length()).toDouble();
countZ += 1;
//Serial.println(count);
}
if (dataIn.startsWith("A"))
{
angulosA[countA] = dataIn.substring(1, dataIn.length()).toDouble();
countA += 1;
//Serial.println(count);
}
if (dataIn.startsWith("J"))
{
for (int i = 0; i <= 10; i++) {
stepperX.setSpeedInStepsPerSecond(100*10);
stepperX.setAccelerationInStepsPerSecondPerSecond(100*10);
stepperX.setupMoveInSteps(angulosX[i]*85.3);
stepperY.setSpeedInStepsPerSecond(100*10);
stepperY.setAccelerationInStepsPerSecondPerSecond(100*10);
stepperY.setupMoveInSteps(angulosY[i]*85.3);
stepperZ.setSpeedInStepsPerSecond(100*10);
stepperZ.setAccelerationInStepsPerSecondPerSecond(100*10);
stepperZ.setupMoveInSteps(angulosZ[i]*85.3);
stepperA.setSpeedInStepsPerSecond(100*10);
stepperA.setAccelerationInStepsPerSecondPerSecond(100*10);
stepperA.setupMoveInSteps(angulosA[i]*85.3);
while((!stepperX.motionComplete()) || (!stepperY.motionComplete()) || (!stepperZ.motionComplete()) || (!stepperA.motionComplete()))
{
stepperX.processMovement();
stepperY.processMovement();
stepperZ.processMovement();
stepperA.processMovement();
}
y += 1;
x += 1;
z += 1;
a += 1;
}
}
}
}
python code:
import linecache
import time
import serial
serialcomm = serial.Serial('COM12', 9600)
serialcomm.timeout = 1
time.sleep(1)
f = open("commands.txt", "r")
time.sleep(0.2)
count = 1
while True:
print(1)
commandsFile = linecache.getline('commands.txt',count)
file = commandsFile.split(" ")
for x in file:
print(x)
serialcomm.write((x + '\n').encode())
time.sleep(0.5)
#serialcomm.flush()
else:
count += 1
print(count)