1
0
mirror of https://gitlab.com/lander-team/tvc-test-code.git synced 2025-06-16 15:06:56 +00:00

terminal input working

This commit is contained in:
Anson Biggs 2021-11-18 12:15:41 -07:00
parent e29cf9224f
commit fc987e89cc

View File

@ -10,13 +10,14 @@ double PITCH_MAX = 7;
double zero_height;
float read_float();
float calc_height(float yaw, float pitch);
void setup() {
delay(1000);
delay(5000);
// yaw.attach(9); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
// pitch.attach(10); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
Serial.println("Level the TVC and press 1.");
Serial.println("Level the TVC and press enter.");
read_float();
// Do a full range of movement of the servos
@ -30,19 +31,23 @@ void setup() {
}
Serial.print("Please input the point height in millimeters: ");
String zero_string = read_float();
zero_height = read_float();
delay(1000);
}
void loop() {
Serial.print("Enter Yaw Coord: ");
float yaw_pos = read_float();
Serial.println();
Serial.println();
Serial.print("Enter Pitch Coord: ");
float pitch_pos = read_float();
Serial.println();
Serial.println();
Serial.println("Moving servos...");
Serial.println("Moving servos to [" + String(yaw_pos) + ", " +
String(pitch_pos) + "]");
// yaw.write(yaw_pos);
// pitch.write(pitch_pos);
@ -57,14 +62,23 @@ void loop() {
float height = sin(yaw_pos) + sin(pitch_pos) + zero_height;
Serial.println("Please verify current height is correct: " + String(height) +
"\n\n\n\n\n");
"\n");
Serial.println("Press enter to continue.");
read_float();
}
float read_float() {
while (Serial.available() == 0) {
delay(100);
char line[80];
int count = 0;
while (1) {
if (Serial.available() > 0) {
line[count] = (char)Serial.read(); // store the char
Serial.print(line[count]);
if (line[count++] == '\r') { // if its a CR,
line[count] = '\0'; // zero-terminate it
return String(line).toFloat();
}
}
}
float num = Serial.parseFloat();
Serial.print(num);
return num;
}
}