1
0
mirror of https://gitlab.com/lander-team/tvc-test-code.git synced 2025-08-02 03:21:34 +00:00

final code used for VR

This commit is contained in:
2021-11-30 17:42:31 -07:00
parent 9893658935
commit 9e8bac67cb

View File

@@ -14,8 +14,7 @@ float calc_height(float yaw, float pitch);
float yaw_conv(float theta); float yaw_conv(float theta);
float pitch_conv(float theta); float pitch_conv(float theta);
void setup() void setup() {
{
delay(5000); delay(5000);
yaw.attach(29); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE yaw.attach(29); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
pitch.attach(33); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE pitch.attach(33); // CHANGE MEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
@@ -31,8 +30,7 @@ void setup()
Serial.println("Testing Servos"); Serial.println("Testing Servos");
// Do a full range of movement of the 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("."); Serial.print(".");
double yaw_pos = (pct / 100) * YAW_MAX; double yaw_pos = (pct / 100) * YAW_MAX;
double pitch_pos = (pct / 100) * PITCH_MAX; double pitch_pos = (pct / 100) * PITCH_MAX;
@@ -50,12 +48,10 @@ void setup()
delay(1000); delay(1000);
} }
void loop() void loop() {
{
Serial.print("Enter Yaw Coord: "); Serial.print("Enter Yaw Coord: ");
float yaw_pos = read_float(); 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"); Serial.println("Value too large, defaulting to maximum deflection");
yaw_pos = YAW_MAX; yaw_pos = YAW_MAX;
} }
@@ -64,8 +60,7 @@ void loop()
Serial.print("Enter Pitch Coord: "); Serial.print("Enter Pitch Coord: ");
float pitch_pos = read_float(); 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"); Serial.println("Value too large, defaulting to maximum deflection");
pitch_pos = PITCH_MAX; pitch_pos = PITCH_MAX;
} }
@@ -79,14 +74,15 @@ void loop()
pitch.write(90 + pitch_conv(pitch_pos)); pitch.write(90 + pitch_conv(pitch_pos));
Serial.print("Calculating current height"); Serial.print("Calculating current height");
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++) {
{
Serial.print("."); Serial.print(".");
delay(i * 100); delay(i * 100);
} }
Serial.println(""); 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) + Serial.println("Please verify current height is correct: " + String(height) +
"\n"); "\n");
@@ -94,19 +90,15 @@ void loop()
read_float(); read_float();
} }
float read_float() float read_float() {
{
char line[80]; char line[80];
int count = 0; int count = 0;
while (1) while (1) {
{ if (Serial.available() > 0) {
if (Serial.available() > 0)
{
line[count] = (char)Serial.read(); // store the char line[count] = (char)Serial.read(); // store the char
Serial.print(line[count]); Serial.print(line[count]);
if (line[count++] == '\r') if (line[count++] == '\r') { // if its a CR,
{ // if its a CR,
line[count] = '\0'; // zero-terminate it line[count] = '\0'; // zero-terminate it
return String(line).toFloat(); return String(line).toFloat();
} }
@@ -114,23 +106,21 @@ float read_float()
} }
} }
float yaw_conv(float thetad) float yaw_conv(float thetad) {
{
// Serial.println(thetad); // Serial.println(thetad);
float h = .2875; float h = .2875;
float H = 1.6; float H = 1.6;
float theta = thetad * 3.14 / 180; 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) float pitch_conv(float thetad) {
{
// Serial.println(thetad); // Serial.println(thetad);
float h = .2875; float h = .2875;
float H = 1.2; float H = 1.2;
float theta = thetad * 3.14 / 180; 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;
} }