From f8195c3f37c577e4c052c343f20ff7aa5715e1f8 Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 1 Apr 2022 12:11:19 +0200 Subject: [PATCH] testPoints --- control/control.ino | 94 +++++++++++++++++++++++++++++++++++++++++++++ gyro/gyro.ino | 44 --------------------- 2 files changed, 94 insertions(+), 44 deletions(-) create mode 100644 control/control.ino delete mode 100644 gyro/gyro.ino diff --git a/control/control.ino b/control/control.ino new file mode 100644 index 0000000..7d9e5c4 --- /dev/null +++ b/control/control.ino @@ -0,0 +1,94 @@ +//#include "MeOrion.h" +#include +#include + +MeGyro gyro; +MeDCMotor motor3(M1); +MeDCMotor motor4(M2); + +uint8_t motorSpeed = 200; +MeUltrasonicSensor ultraSensor(PORT_3); + +double rWheel = 6.5; +double dWheel = 11.5; + +double Pos[4][1]; + +double angularError = 10; +double posError = 10; + +double angle1; +double angle2; +double dist; + +void setup() +{ + Serial.begin(115200); + gyro.begin(); + + Pos[0][0] = 0; + Pos[0][1] = 0; + Pos[1][0] = 25; + Pos[1][1] = 0; + Pos[2][0] = 25; + Pos[2][1] = 25; + Pos[3][0] = 0; + Pos[3][1] = 25; +} + +void loop() +{ + Serial.println("Start Loop"); + int i; + int j; + Serial.read(); + for(i=0;i<4;i++){ + Serial.print("Beggin angular adjustment for i: "); + Serial.println(i); + //angle adjustment + gyro.update(); + + angle1=gyro.getAngleZ(); + angle2=atan( (Pos[i+1][1]-Pos[i][1])/ (Pos[i+1][0]-Pos[i][0]) ); + motorSpeed = 70; + Serial.print("angle1: "); + Serial.print(angle1); + Serial.print(" angle2: "); + Serial.println(angle2); + + while(angle1-angle2+360 > angularError) { + gyro.update(); + angle1=gyro.getAngleZ(); + angle2=atan( (Pos[i+1][0]-Pos[i][0])/ (Pos[i+1][1]-Pos[i][1]) ); + Serial.println("i: "); + Serial.println(i); + Serial.print(" angle1: "); + Serial.print(angle1); + Serial.print(" angle2: "); + Serial.println(angle2); + if(angle2+180 - *