I have an ultramotion linear servo that i am trying to read positional data from using an Arduino Mega2560's Serial1 pins. I havent been able to read the data in but i can control the motor perfectly fine when i issue it movement commands. The motor is supposed to be queried for position using the "AP\r"
command. I have gotten it so that i receive a -1 but that's the only thing I am receiving. The feedback is supposed to be carriage return terminated but all my other attempts at querying the data have given me nothing else back. The current code that I have will give me a y with two dots above it when i comment out the while Serial1.available part but if i dont comment that out i just get nothing
//Receiving Variables
const byte numChars = 32; //defines size of byte array
char receivedChars[numChars]; //defines receivedChars as character array
boolean newData = false; //Inititalezes boolean value
// timing variables
int ServoCorrectionInterval = 500;
unsigned long CurrentMillis = 0;
unsigned long CorrectionMillis = 0;
//Pressure Variables and Pins
int analogPin = 0; //sets the analog pin to
//Define Variables we'll be connecting to
double Setpoint, Input;
long IntError;
long Accel;
int MoveSet;
char* MOVE;
unsigned long PrintMillis = 0;
int PrintValMillis = 50;
long IntSet;
int scalar = 350;
int Activate=0;
char OnOff;
String read1;
//Averaging values
const int numReadings = 5;
int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
long minVal = 5000;
void setup() {
Input = analogRead(analogPin); //reads the pressure sensor
Serial.begin(115200); //set baud rate for arduino to pc
Serial1.begin(115200); //set baud rate for arduino to actuator
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
while (!Serial1) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial1.println("SP2500000"); //set initial speed
Serial1.println("AC25000"); //set initial acceleration
Serial1.println("TR"); //return to start of movement
delay(500);
Serial1.println("TA8000"); //cycle through some movements to let me know everythings working
delay(500);
Serial1.println("TR"); //return to start of movement
delay(500);
}
void loop()
{
CurrentMillis = millis();
movePiston();
readPiston();
String content = "";
char character;
while(Serial.available()) {
character = Serial.read();
content.concat(character);
}
if (content != "") {
Serial.println(content);
}
}
void movePiston()
{
if (CurrentMillis - CorrectionMillis >= ServoCorrectionInterval)
{
Serial1.println("TA" + String(minVal));
minVal = minVal + 100;
//Serial.println("Sent Value: TA" + String(minVal));
if (minVal > 22500)
{
minVal = 5000;
}
CorrectionMillis += ServoCorrectionInterval;
}
}
void readPiston()
{
if (CurrentMillis - PrintMillis >= PrintValMillis)
{
Serial1.println("AP");
PrintMillis += PrintValMillis;
}
}
Thanks in advance for any help. Attached is the motor guide Appendix A has the important info