diff --git a/lander-team/tvc-test-code/.gitignore b/lander-team/tvc-test-code/.gitignore new file mode 100644 index 000000000..89cc49cbd --- /dev/null +++ b/lander-team/tvc-test-code/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/lander-team/tvc-test-code/.vscode/extensions.json b/lander-team/tvc-test-code/.vscode/extensions.json new file mode 100644 index 000000000..e80666bfb --- /dev/null +++ b/lander-team/tvc-test-code/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + // See http://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": [ + "platformio.platformio-ide" + ] +} diff --git a/lander-team/tvc-test-code/include/README b/lander-team/tvc-test-code/include/README new file mode 100644 index 000000000..194dcd432 --- /dev/null +++ b/lander-team/tvc-test-code/include/README @@ -0,0 +1,39 @@ + +This directory is intended for project header files. + +A header file is a file containing C declarations and macro definitions +to be shared between several project source files. You request the use of a +header file in your project source file (C, C++, etc) located in `src` folder +by including it, with the C preprocessing directive `#include'. + +```src/main.c + +#include "header.h" + +int main (void) +{ + ... +} +``` + +Including a header file produces the same results as copying the header file +into each source file that needs it. Such copying would be time-consuming +and error-prone. With a header file, the related declarations appear +in only one place. If they need to be changed, they can be changed in one +place, and programs that include the header file will automatically use the +new version when next recompiled. The header file eliminates the labor of +finding and changing all the copies as well as the risk that a failure to +find one copy will result in inconsistencies within a program. + +In C, the usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +Read more about using header files in official GCC documentation: + +* Include Syntax +* Include Operation +* Once-Only Headers +* Computed Includes + +https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/lander-team/tvc-test-code/lib/README b/lander-team/tvc-test-code/lib/README new file mode 100644 index 000000000..6debab1e8 --- /dev/null +++ b/lander-team/tvc-test-code/lib/README @@ -0,0 +1,46 @@ + +This directory is intended for project specific (private) libraries. +PlatformIO will compile them to static libraries and link into executable file. + +The source code of each library should be placed in a an own separate directory +("lib/your_library_name/[here are source files]"). + +For example, see a structure of the following two libraries `Foo` and `Bar`: + +|--lib +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE +| +|- platformio.ini +|--src + |- main.c + +and a contents of `src/main.c`: +``` +#include +#include + +int main (void) +{ + ... +} + +``` + +PlatformIO Library Dependency Finder will find automatically dependent +libraries scanning project source files. + +More information about PlatformIO Library Dependency Finder +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/lander-team/tvc-test-code/platformio.ini b/lander-team/tvc-test-code/platformio.ini new file mode 100644 index 000000000..a13d0343a --- /dev/null +++ b/lander-team/tvc-test-code/platformio.ini @@ -0,0 +1,14 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:teensy41] +platform = teensy +board = teensy41 +framework = arduino diff --git a/lander-team/tvc-test-code/src/main.cpp b/lander-team/tvc-test-code/src/main.cpp new file mode 100644 index 000000000..58b344c57 --- /dev/null +++ b/lander-team/tvc-test-code/src/main.cpp @@ -0,0 +1,9 @@ +#include + +void setup() { + // put your setup code here, to run once: +} + +void loop() { + // put your main code here, to run repeatedly: +} \ No newline at end of file diff --git a/lander-team/tvc-test-code/test/README b/lander-team/tvc-test-code/test/README new file mode 100644 index 000000000..b94d0890f --- /dev/null +++ b/lander-team/tvc-test-code/test/README @@ -0,0 +1,11 @@ + +This directory is intended for PlatformIO Unit Testing and project tests. + +Unit Testing is a software testing method by which individual units of +source code, sets of one or more MCU program modules together with associated +control data, usage procedures, and operating procedures, are tested to +determine whether they are fit for use. Unit testing finds problems early +in the development cycle. + +More information about PlatformIO Unit Testing: +- https://docs.platformio.org/page/plus/unit-testing.html -- 2.51.2 From ebd89dd21098d1451134efd71a1e7f48bbbd564f Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Tue, 2 Nov 2021 11:56:37 -0700 Subject: [PATCH 02/15] added readme --- lander-team/tvc-test-code/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 lander-team/tvc-test-code/README.md diff --git a/lander-team/tvc-test-code/README.md b/lander-team/tvc-test-code/README.md new file mode 100644 index 000000000..372ab732a --- /dev/null +++ b/lander-team/tvc-test-code/README.md @@ -0,0 +1,3 @@ +# TVC Test + +The purpose of this test is to demonstrate the capabilities of the TVC system. The TVC is mechanically very complex, and it is vital that the servo movements accurately rotate the rocket motor to the correct angle. This test will verify requirements for the Test Software, Test Stand, and Control Mechanisms Subsystem. \ No newline at end of file -- 2.51.2 From 41581ed57418b1a7a912f3e7cfb2c7e682c7d23b Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Tue, 2 Nov 2021 12:16:11 -0700 Subject: [PATCH 03/15] simple servo boilerplay --- lander-team/tvc-test-code/src/main.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lander-team/tvc-test-code/src/main.cpp b/lander-team/tvc-test-code/src/main.cpp index 58b344c57..ac1b478d5 100644 --- a/lander-team/tvc-test-code/src/main.cpp +++ b/lander-team/tvc-test-code/src/main.cpp @@ -1,9 +1,23 @@ #include +#include + +Servo yaw; +Servo pitch; void setup() { - // put your setup code here, to run once: + yaw.attach(9); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + pitch.attach(10); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE } void loop() { - // put your main code here, to run repeatedly: + for (int pos = 0; pos <= 180; pos += 1) { + yaw.write(pos); + pitch.write(pos); + delay(15); + } + for (int pos = 180; pos >= 0; pos -= 1) { + yaw.write(pos); + pitch.write(pos); + delay(15); + } } \ No newline at end of file -- 2.51.2 From 83007a7fe95dc18a175e0977bbb6cb003359ea97 Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Wed, 3 Nov 2021 15:47:08 -0700 Subject: [PATCH 04/15] started outlining test --- lander-team/tvc-test-code/src/main.cpp | 37 +++++++++++++++++--------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/lander-team/tvc-test-code/src/main.cpp b/lander-team/tvc-test-code/src/main.cpp index ac1b478d5..e052a409a 100644 --- a/lander-team/tvc-test-code/src/main.cpp +++ b/lander-team/tvc-test-code/src/main.cpp @@ -4,20 +4,33 @@ Servo yaw; Servo pitch; +double YAW_MAX = 7; +double PITCH_MAX = 7; + +double zero_height; + +double point_height(double TVC_angle) { return sin(TVC_angle) + zero_height; } + void setup() { - yaw.attach(9); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + yaw.attach(9); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE pitch.attach(10); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE -} -void loop() { - for (int pos = 0; pos <= 180; pos += 1) { - yaw.write(pos); - pitch.write(pos); - delay(15); - } - for (int pos = 180; pos >= 0; pos -= 1) { - yaw.write(pos); - pitch.write(pos); + Serial.println("Level the TVC and press enter."); + Serial.readString(); + + // Do a full range of movement of the servos + for (double pct = -100.0; pct <= 100.0; pct += 1.0) { + double yaw_pos = pct * YAW_MAX; + double pitch_pos = pct * PITCH_MAX; + + yaw.write(yaw_pos); + pitch.write(pitch_pos); delay(15); } -} \ No newline at end of file + + Serial.print("Please input the point height in millimeters: "); + String zero_string = Serial.readString(); + zero_height = zero_string.toFloat(); +} + +void loop() {} \ No newline at end of file -- 2.51.2 From 2785c4088cf65439dda01d74eaf452c947de28bd Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Wed, 3 Nov 2021 20:29:10 -0700 Subject: [PATCH 05/15] hopefully this works on the teensy --- lander-team/tvc-test-code/src/main.cpp | 28 +++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/lander-team/tvc-test-code/src/main.cpp b/lander-team/tvc-test-code/src/main.cpp index e052a409a..e3d15f6e4 100644 --- a/lander-team/tvc-test-code/src/main.cpp +++ b/lander-team/tvc-test-code/src/main.cpp @@ -9,8 +9,6 @@ double PITCH_MAX = 7; double zero_height; -double point_height(double TVC_angle) { return sin(TVC_angle) + zero_height; } - void setup() { yaw.attach(9); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE pitch.attach(10); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE @@ -33,4 +31,28 @@ void setup() { zero_height = zero_string.toFloat(); } -void loop() {} \ No newline at end of file +void loop() { + Serial.print("Enter Yaw Coord: "); + float yaw_pos = Serial.readString().toFloat(); + Serial.println(); + Serial.print("Enter Pitch Coord: "); + float pitch_pos = Serial.readString().toFloat(); + Serial.println(); + + Serial.println("Moving servos..."); + + yaw.write(yaw_pos); + pitch.write(pitch_pos); + + Serial.print("Calculating current height"); + for (int i = 0; i < 5; i++) { + Serial.print("."); + delay(i * 100); + } + Serial.println(""); + + 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"); +} \ No newline at end of file -- 2.51.2 From e135a60f115927006ad6b8ef5ead1a30fc9d5d6d Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Wed, 17 Nov 2021 15:48:37 -0700 Subject: [PATCH 06/15] fixed terminal reading --- lander-team/tvc-test-code/src/main.cpp | 34 +++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/lander-team/tvc-test-code/src/main.cpp b/lander-team/tvc-test-code/src/main.cpp index e3d15f6e4..bef12cc3f 100644 --- a/lander-team/tvc-test-code/src/main.cpp +++ b/lander-team/tvc-test-code/src/main.cpp @@ -9,12 +9,15 @@ double PITCH_MAX = 7; double zero_height; +float read_float(); + void setup() { - yaw.attach(9); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE - pitch.attach(10); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + delay(1000); + // yaw.attach(9); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + // pitch.attach(10); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE - Serial.println("Level the TVC and press enter."); - Serial.readString(); + Serial.println("Level the TVC and press 1."); + read_float(); // Do a full range of movement of the servos for (double pct = -100.0; pct <= 100.0; pct += 1.0) { @@ -22,27 +25,27 @@ void setup() { double pitch_pos = pct * PITCH_MAX; yaw.write(yaw_pos); - pitch.write(pitch_pos); + // pitch.write(pitch_pos); delay(15); } Serial.print("Please input the point height in millimeters: "); - String zero_string = Serial.readString(); - zero_height = zero_string.toFloat(); + String zero_string = read_float(); } void loop() { Serial.print("Enter Yaw Coord: "); - float yaw_pos = Serial.readString().toFloat(); + float yaw_pos = read_float(); + Serial.println(); Serial.print("Enter Pitch Coord: "); - float pitch_pos = Serial.readString().toFloat(); + float pitch_pos = read_float(); Serial.println(); Serial.println("Moving servos..."); - yaw.write(yaw_pos); - pitch.write(pitch_pos); + // yaw.write(yaw_pos); + // pitch.write(pitch_pos); Serial.print("Calculating current height"); for (int i = 0; i < 5; i++) { @@ -55,4 +58,13 @@ void loop() { Serial.println("Please verify current height is correct: " + String(height) + "\n\n\n\n\n"); +} + +float read_float() { + while (Serial.available() == 0) { + delay(100); + } + float num = Serial.parseFloat(); + Serial.print(num); + return num; } \ No newline at end of file -- 2.51.2 From f020228f72202199d18420fe5b1b3e53bbb56a3c Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Thu, 18 Nov 2021 12:15:41 -0700 Subject: [PATCH 07/15] terminal input working --- lander-team/tvc-test-code/src/main.cpp | 38 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/lander-team/tvc-test-code/src/main.cpp b/lander-team/tvc-test-code/src/main.cpp index bef12cc3f..e5ead201a 100644 --- a/lander-team/tvc-test-code/src/main.cpp +++ b/lander-team/tvc-test-code/src/main.cpp @@ -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; -} \ No newline at end of file +} -- 2.51.2 From 5b2d20773b030676f565f25867f64b90c67a5ba6 Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Thu, 18 Nov 2021 12:19:11 -0700 Subject: [PATCH 08/15] enable servos in prep for verification --- lander-team/tvc-test-code/src/main.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lander-team/tvc-test-code/src/main.cpp b/lander-team/tvc-test-code/src/main.cpp index e5ead201a..98805110a 100644 --- a/lander-team/tvc-test-code/src/main.cpp +++ b/lander-team/tvc-test-code/src/main.cpp @@ -14,8 +14,8 @@ float calc_height(float yaw, float pitch); void setup() { delay(5000); - // yaw.attach(9); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE - // pitch.attach(10); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + yaw.attach(9); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + pitch.attach(10); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE Serial.println("Level the TVC and press enter."); read_float(); @@ -26,7 +26,7 @@ void setup() { double pitch_pos = pct * PITCH_MAX; yaw.write(yaw_pos); - // pitch.write(pitch_pos); + pitch.write(pitch_pos); delay(15); } @@ -38,19 +38,27 @@ void setup() { void loop() { Serial.print("Enter Yaw Coord: "); float yaw_pos = read_float(); + if (abs(yaw_pos) > YAW_MAX) { + Serial.println("Value too large, defaulting to maximum deflection"); + yaw_pos = YAW_MAX; + } Serial.println(); Serial.println(); Serial.print("Enter Pitch Coord: "); float pitch_pos = read_float(); + if (abs(pitch_pos) > PITCH_MAX) { + Serial.println("Value too large, defaulting to maximum deflection"); + pitch_pos = PITCH_MAX; + } Serial.println(); Serial.println(); Serial.println("Moving servos to [" + String(yaw_pos) + ", " + String(pitch_pos) + "]"); - // yaw.write(yaw_pos); - // pitch.write(pitch_pos); + yaw.write(yaw_pos); + pitch.write(pitch_pos); Serial.print("Calculating current height"); for (int i = 0; i < 5; i++) { -- 2.51.2 From ff340daf2a1082a15afe0758a98a256c68e6abbb Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Thu, 18 Nov 2021 12:27:52 -0700 Subject: [PATCH 09/15] made test more verbose --- lander-team/tvc-test-code/src/main.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lander-team/tvc-test-code/src/main.cpp b/lander-team/tvc-test-code/src/main.cpp index 98805110a..c81d09193 100644 --- a/lander-team/tvc-test-code/src/main.cpp +++ b/lander-team/tvc-test-code/src/main.cpp @@ -17,17 +17,25 @@ void setup() { yaw.attach(9); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE pitch.attach(10); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE - Serial.println("Level the TVC and press enter."); + Serial.println("Remove Servo Horns and press enter."); read_float(); + yaw.write(0); + pitch.write(0); + + Serial.println("Replace horns, level the TVC and press enter."); + read_float(); + + Serial.println("Testing Servos"); // Do a full range of movement of the servos - for (double pct = -100.0; pct <= 100.0; pct += 1.0) { + for (double pct = -100.0; pct <= 100.0; pct += 10.0) { + Serial.print("."); double yaw_pos = pct * YAW_MAX; double pitch_pos = pct * PITCH_MAX; yaw.write(yaw_pos); pitch.write(pitch_pos); - delay(15); + delay(100); } Serial.print("Please input the point height in millimeters: "); -- 2.51.2 From 329c61a4fcf6444acf84b40cd7cebb2e194df7ee Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Fri, 19 Nov 2021 20:00:05 -0700 Subject: [PATCH 10/15] code where it was left in class --- lander-team/tvc-test-code/src/main.cpp | 38 ++++++++++++++++++++------ 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/lander-team/tvc-test-code/src/main.cpp b/lander-team/tvc-test-code/src/main.cpp index c81d09193..a6b973f40 100644 --- a/lander-team/tvc-test-code/src/main.cpp +++ b/lander-team/tvc-test-code/src/main.cpp @@ -11,16 +11,18 @@ double zero_height; float read_float(); float calc_height(float yaw, float pitch); +float yaw_conv(float theta); +float pitch_conv(float theta); void setup() { delay(5000); - yaw.attach(9); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE - pitch.attach(10); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + yaw.attach(29); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE + pitch.attach(33); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE Serial.println("Remove Servo Horns and press enter."); read_float(); - yaw.write(0); - pitch.write(0); + yaw.write(yaw_conv(0)); + pitch.write(pitch_conv(0)); Serial.println("Replace horns, level the TVC and press enter."); read_float(); @@ -33,8 +35,8 @@ void setup() { double yaw_pos = pct * YAW_MAX; double pitch_pos = pct * PITCH_MAX; - yaw.write(yaw_pos); - pitch.write(pitch_pos); + yaw.write(yaw_conv(yaw_pos)); + pitch.write(pitch_conv(pitch_pos)); delay(100); } @@ -65,8 +67,8 @@ void loop() { Serial.println("Moving servos to [" + String(yaw_pos) + ", " + String(pitch_pos) + "]"); - yaw.write(yaw_pos); - pitch.write(pitch_pos); + yaw.write(yaw_conv(yaw_pos)); + pitch.write(pitch_conv(pitch_pos)); Serial.print("Calculating current height"); for (int i = 0; i < 5; i++) { @@ -98,3 +100,23 @@ float read_float() { } } } + +float yaw_conv(float thetad) { + Serial.println(thetad); + float h = .2875; + float H = 1.5; + + float theta = thetad * 3.14 / 180; + + return 2 * asin((H * sin(theta / 2)) / h); +} +float pitch_conv(float thetad) { + Serial.println(thetad); + float h = .2875; + float H = 1.6; + + float theta = thetad * 3.14 / 180; + + Serial.println(2 * asin((H * sin(theta / 2)) / h)); + return 2 * asin((H * sin(theta / 2)) / h); +} -- 2.51.2 From 9e6f4b4ed5a82280b60580f70335fbc3475a09c7 Mon Sep 17 00:00:00 2001 From: Brendan McGeeney Date: Sun, 21 Nov 2021 13:16:14 -0700 Subject: [PATCH 11/15] changed to PWMServo.h --- lander-team/tvc-test-code/src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lander-team/tvc-test-code/src/main.cpp b/lander-team/tvc-test-code/src/main.cpp index a6b973f40..9304af1a0 100644 --- a/lander-team/tvc-test-code/src/main.cpp +++ b/lander-team/tvc-test-code/src/main.cpp @@ -1,8 +1,8 @@ #include -#include +#include -Servo yaw; -Servo pitch; +PWMServo yaw; +PWMServo pitch; double YAW_MAX = 7; double PITCH_MAX = 7; -- 2.51.2 From 89866da7813ec73d591c1dd4a274cf76d9888c9d Mon Sep 17 00:00:00 2001 From: Brendan McGeeney Date: Sun, 21 Nov 2021 16:18:40 -0700 Subject: [PATCH 12/15] made sure we were writing to our servos in degrees --- lander-team/tvc-test-code/src/main.cpp | 64 ++++++++++++++++---------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/lander-team/tvc-test-code/src/main.cpp b/lander-team/tvc-test-code/src/main.cpp index 9304af1a0..60ae7e0be 100644 --- a/lander-team/tvc-test-code/src/main.cpp +++ b/lander-team/tvc-test-code/src/main.cpp @@ -14,15 +14,16 @@ float calc_height(float yaw, float pitch); float yaw_conv(float theta); float pitch_conv(float theta); -void setup() { +void setup() +{ delay(5000); yaw.attach(29); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE pitch.attach(33); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE Serial.println("Remove Servo Horns and press enter."); read_float(); - yaw.write(yaw_conv(0)); - pitch.write(pitch_conv(0)); + yaw.write(yaw_conv(90)); + pitch.write(pitch_conv(90)); Serial.println("Replace horns, level the TVC and press enter."); read_float(); @@ -30,14 +31,18 @@ void setup() { Serial.println("Testing Servos"); // Do a full range of movement of the servos - for (double pct = -100.0; pct <= 100.0; pct += 10.0) { + for (double pct = -100.0; pct <= 100.0; pct += 10.0) + { Serial.print("."); - double yaw_pos = pct * YAW_MAX; - double pitch_pos = pct * PITCH_MAX; + double yaw_pos = (pct / 100) * YAW_MAX; + double pitch_pos = (pct / 100) * PITCH_MAX; - yaw.write(yaw_conv(yaw_pos)); - pitch.write(pitch_conv(pitch_pos)); - delay(100); + Serial.println(90 + yaw_conv(yaw_pos)); + Serial.println(90 + pitch_conv(pitch_pos)); + + yaw.write(90 + yaw_conv(yaw_pos)); + pitch.write(90 + pitch_conv(pitch_pos)); + delay(500); } Serial.print("Please input the point height in millimeters: "); @@ -45,10 +50,12 @@ void setup() { delay(1000); } -void loop() { +void loop() +{ Serial.print("Enter Yaw Coord: "); float yaw_pos = read_float(); - if (abs(yaw_pos) > YAW_MAX) { + if (abs(yaw_pos) > YAW_MAX) + { Serial.println("Value too large, defaulting to maximum deflection"); yaw_pos = YAW_MAX; } @@ -57,7 +64,8 @@ void loop() { Serial.print("Enter Pitch Coord: "); float pitch_pos = read_float(); - if (abs(pitch_pos) > PITCH_MAX) { + if (abs(pitch_pos) > PITCH_MAX) + { Serial.println("Value too large, defaulting to maximum deflection"); pitch_pos = PITCH_MAX; } @@ -71,7 +79,8 @@ void loop() { pitch.write(pitch_conv(pitch_pos)); Serial.print("Calculating current height"); - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 5; i++) + { Serial.print("."); delay(i * 100); } @@ -85,38 +94,43 @@ void loop() { read_float(); } -float read_float() { +float read_float() +{ char line[80]; int count = 0; - while (1) { - if (Serial.available() > 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 + if (line[count++] == '\r') + { // if its a CR, + line[count] = '\0'; // zero-terminate it return String(line).toFloat(); } } } } -float yaw_conv(float thetad) { - Serial.println(thetad); +float yaw_conv(float thetad) +{ + //Serial.println(thetad); float h = .2875; float H = 1.5; float theta = thetad * 3.14 / 180; - return 2 * asin((H * sin(theta / 2)) / h); + return (2 * asin((H * sin(theta / 2)) / h)) * 180.0 / 3.14; } -float pitch_conv(float thetad) { - Serial.println(thetad); +float pitch_conv(float thetad) +{ + //Serial.println(thetad); float h = .2875; float H = 1.6; float theta = thetad * 3.14 / 180; - Serial.println(2 * asin((H * sin(theta / 2)) / h)); - return 2 * asin((H * sin(theta / 2)) / h); + return (2 * asin((H * sin(theta / 2)) / h)) * 180.0 / 3.14; } -- 2.51.2 From 2c24aa7a8ee6b8a4b7c7e97c3ee9cfce533f21fc Mon Sep 17 00:00:00 2001 From: Brendan McGeeney Date: Sun, 21 Nov 2021 17:29:09 -0700 Subject: [PATCH 13/15] fixed servos, still need to run full TVC test --- lander-team/tvc-test-code/src/main.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lander-team/tvc-test-code/src/main.cpp b/lander-team/tvc-test-code/src/main.cpp index 60ae7e0be..8d87ee0c3 100644 --- a/lander-team/tvc-test-code/src/main.cpp +++ b/lander-team/tvc-test-code/src/main.cpp @@ -22,8 +22,8 @@ void setup() Serial.println("Remove Servo Horns and press enter."); read_float(); - yaw.write(yaw_conv(90)); - pitch.write(pitch_conv(90)); + yaw.write(90); + pitch.write(90); Serial.println("Replace horns, level the TVC and press enter."); read_float(); @@ -37,14 +37,17 @@ void setup() double yaw_pos = (pct / 100) * YAW_MAX; double pitch_pos = (pct / 100) * PITCH_MAX; - Serial.println(90 + yaw_conv(yaw_pos)); - Serial.println(90 + pitch_conv(pitch_pos)); + Serial.println(yaw_conv(yaw_pos)); + Serial.println(pitch_conv(pitch_pos)); yaw.write(90 + yaw_conv(yaw_pos)); pitch.write(90 + pitch_conv(pitch_pos)); - delay(500); + delay(50); } + yaw.write(90); + pitch.write(90); + Serial.print("Please input the point height in millimeters: "); zero_height = read_float(); delay(1000); -- 2.51.2 From e5acef2e90340302aa12179839847bab6682a914 Mon Sep 17 00:00:00 2001 From: Brendan McGeeney Date: Mon, 22 Nov 2021 10:52:13 -0700 Subject: [PATCH 14/15] maths stuffs --- lander-team/tvc-test-code/src/main.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lander-team/tvc-test-code/src/main.cpp b/lander-team/tvc-test-code/src/main.cpp index 8d87ee0c3..0e890f9fd 100644 --- a/lander-team/tvc-test-code/src/main.cpp +++ b/lander-team/tvc-test-code/src/main.cpp @@ -37,12 +37,9 @@ void setup() double yaw_pos = (pct / 100) * YAW_MAX; double pitch_pos = (pct / 100) * PITCH_MAX; - Serial.println(yaw_conv(yaw_pos)); - Serial.println(pitch_conv(pitch_pos)); - yaw.write(90 + yaw_conv(yaw_pos)); pitch.write(90 + pitch_conv(pitch_pos)); - delay(50); + delay(25); } yaw.write(90); @@ -78,8 +75,8 @@ void loop() Serial.println("Moving servos to [" + String(yaw_pos) + ", " + String(pitch_pos) + "]"); - yaw.write(yaw_conv(yaw_pos)); - pitch.write(pitch_conv(pitch_pos)); + yaw.write(90 + yaw_conv(yaw_pos)); + pitch.write(90 + pitch_conv(pitch_pos)); Serial.print("Calculating current height"); for (int i = 0; i < 5; i++) @@ -89,7 +86,7 @@ void loop() } Serial.println(""); - float height = sin(yaw_pos) + sin(pitch_pos) + zero_height; + float height = 235 * (sin(yaw_pos * 3.14 / 180) + sin(pitch_pos * 3.14 / 180)) + zero_height; Serial.println("Please verify current height is correct: " + String(height) + "\n"); @@ -121,7 +118,7 @@ float yaw_conv(float thetad) { //Serial.println(thetad); float h = .2875; - float H = 1.5; + float H = 1.6; float theta = thetad * 3.14 / 180; @@ -131,7 +128,7 @@ float pitch_conv(float thetad) { //Serial.println(thetad); float h = .2875; - float H = 1.6; + float H = 1.2; float theta = thetad * 3.14 / 180; -- 2.51.2 From 4ee03294cbe87a0db4964313fa4053491ffed31d Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Tue, 30 Nov 2021 17:42:31 -0700 Subject: [PATCH 15/15] final code used for VR --- lander-team/tvc-test-code/src/main.cpp | 50 +++++++++++--------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/lander-team/tvc-test-code/src/main.cpp b/lander-team/tvc-test-code/src/main.cpp index 0e890f9fd..9aa3cb476 100644 --- a/lander-team/tvc-test-code/src/main.cpp +++ b/lander-team/tvc-test-code/src/main.cpp @@ -14,8 +14,7 @@ float calc_height(float yaw, float pitch); float yaw_conv(float theta); float pitch_conv(float theta); -void setup() -{ +void setup() { delay(5000); yaw.attach(29); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE pitch.attach(33); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE @@ -31,8 +30,7 @@ void setup() Serial.println("Testing Servos"); // Do a full range of movement of the servos - for (double pct = -100.0; pct <= 100.0; pct += 10.0) - { + for (double pct = -100.0; pct <= 100.0; pct += 10.0) { Serial.print("."); double yaw_pos = (pct / 100) * YAW_MAX; double pitch_pos = (pct / 100) * PITCH_MAX; @@ -50,12 +48,10 @@ void setup() delay(1000); } -void loop() -{ +void loop() { Serial.print("Enter Yaw Coord: "); float yaw_pos = read_float(); - if (abs(yaw_pos) > YAW_MAX) - { + if (abs(yaw_pos) > YAW_MAX) { Serial.println("Value too large, defaulting to maximum deflection"); yaw_pos = YAW_MAX; } @@ -64,8 +60,7 @@ void loop() Serial.print("Enter Pitch Coord: "); float pitch_pos = read_float(); - if (abs(pitch_pos) > PITCH_MAX) - { + if (abs(pitch_pos) > PITCH_MAX) { Serial.println("Value too large, defaulting to maximum deflection"); pitch_pos = PITCH_MAX; } @@ -79,14 +74,15 @@ void loop() pitch.write(90 + pitch_conv(pitch_pos)); Serial.print("Calculating current height"); - for (int i = 0; i < 5; i++) - { + for (int i = 0; i < 5; i++) { Serial.print("."); delay(i * 100); } Serial.println(""); - float height = 235 * (sin(yaw_pos * 3.14 / 180) + sin(pitch_pos * 3.14 / 180)) + zero_height; + float height = + 235 * (sin(yaw_pos * 3.14 / 180) + sin(pitch_pos * 3.14 / 180)) + + zero_height; Serial.println("Please verify current height is correct: " + String(height) + "\n"); @@ -94,43 +90,37 @@ void loop() read_float(); } -float read_float() -{ +float read_float() { char line[80]; int count = 0; - while (1) - { - if (Serial.available() > 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 + if (line[count++] == '\r') { // if its a CR, + line[count] = '\0'; // zero-terminate it return String(line).toFloat(); } } } } -float yaw_conv(float thetad) -{ - //Serial.println(thetad); +float yaw_conv(float thetad) { + // Serial.println(thetad); float h = .2875; float H = 1.6; float theta = thetad * 3.14 / 180; - return (2 * asin((H * sin(theta / 2)) / h)) * 180.0 / 3.14; + return -(2 * asin((H * sin(theta / 2)) / h)) * 180.0 / 3.14; } -float pitch_conv(float thetad) -{ - //Serial.println(thetad); +float pitch_conv(float thetad) { + // Serial.println(thetad); float h = .2875; float H = 1.2; float theta = thetad * 3.14 / 180; - return (2 * asin((H * sin(theta / 2)) / h)) * 180.0 / 3.14; + return -(2 * asin((H * sin(theta / 2)) / h)) * 180.0 / 3.14; }