Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gyroscope and Serial_interface #11

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Claw/thruster code
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@






#include <Servo.h>
Servo myservo;

int thruster_Speed = 1500;
Servo mythruster;
int pos = 0;
void setup() {
mythruster.attach(7);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
mythruster.writeMicroseconds(1500);
delay(200);
Serial.begin(9600);


}

void loop() {
myservo.write(0); // tell servo to go to position in variable 'pos'


Serial.print("Enter thruster speed: ");
int temp = Serial.parseInt();
if (temp != 0) thruster_Speed = temp;
//changing the fan speed
Serial.print("thruster_speed = ");
Serial.println(thruster_Speed);
mythruster.writeMicroseconds(thruster_Speed);
Serial.write(9600);
Serial.available();
myservo.write(45); // tell servo to go to position in variable 'pos'
delay(300);

}

149 changes: 31 additions & 118 deletions Serial_Interface_Code/Serial_Interface_Code + gyro.ino
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@


import serial
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <Servo.h>
char header = 1
char footer = 10


Servo mythruster_FR;
##declaring each thruster as a servo
Servo mythruster_BR;
Servo mythruster_BL;
Servo mythruster_FL;
Servo mythruster_R;
Servo mythruster_L;
Servo myservo_rotate;
Servo myservo_grab;
Servo myservo_grab;


void setup() {
Expand All @@ -28,6 +27,7 @@ void setup() {

mythruster_BR.attach(8,1000,2000);
mythruster_BR.writeMicroseconds(1500);
##assigns a signal number on the itsybitsy to each thruster and sets it at 1500 so that we don't need to input 1500 before inputing the microsecond that we want it set at

mythruster_BL.attach(9,1000,2000);
mythruster_BL.writeMicroseconds(1500);
Expand All @@ -46,15 +46,6 @@ void setup() {
}

void loop() {
sensors_event_t orientationData , angVelocityData , linearAccelData;
bno.getEvent(&orientationData, Adafruit_BNO055::VECTOR_EULER);
bno.getEvent(&angVelocityData, Adafruit_BNO055::VECTOR_GYROSCOPE);
bno.getEvent(&linearAccelData, Adafruit_BNO055::VECTOR_LINEARACCEL);

Serial.write(&orientationData);
Serial.write(&angVelocityData);
Serial.write(&linearAccelData);


if (Serial.available>=4){
byte packetheader = Serial.read();
Expand All @@ -64,130 +55,52 @@ void loop() {
int motor_speed = (int) (1500 + speed * (500 / 127));
byte motor_servo = serial.read();
int8_t servo_speed = Serial.read();
int servo_speed_convert = (int)((servo_speed * 0.73)-255);

int servo_speed_convert = (int)((servo_speed * 0.73)-255);
##determines the motor speed based in bytes recieved from backend
if (incomingByte[2] == 2){
mythruster_FR.writeMicroseconds(motor_speed);
} else if (incomingByte[2] == 3){
mythruster_FL.writeMicroseconds(motor_speed);
mythruster_FL.writeMicroseconds(motor_speed);
} else if (incomingByte[2] == 4){
mythruster_BR.writeMicroseconds(motor_speed);
mythruster_BR.writeMicroseconds(motor_speed);
} else if (incomingByte[2] == 5){
mythruster_BL.writeMicroseconds(motor_speed);
mythruster_BL.writeMicroseconds(motor_speed);
} else if (incomingByte[2] == 6){
mythruster_R.writeMicroseconds(motor_speed);
mythruster_R.writeMicroseconds(motor_speed);
} else if (incomingByte[2] == 7){
mythruster_L.writeMicroseconds(motor_speed);
mythruster_L.writeMicroseconds(motor_speed);
} else if (incomingByte[2] == 8){
myservo_rotate.write(servo_speed_convert);
myservo_rotate.write(servo_speed_convert);
} else if (incomingByte[2] == 9){
myservo_grab.write(servo_speed_convert);
myservo_grab.write(servo_speed_convert);
}
}
}
}

header_gyro = header_control[0]
orientation = orientation_control[1]
rotation_vector = rotation_vector_control[2]
linear_acceleration = linear_acceleration_control[3]
footer_gyro = footer_control[4]
Serial.write(linear_acceleration)
Serial.write(rotation_vector)
Serial.write(orientation)

if (Serial.available>=4){

if (incomingByte[2] == 2){
mythruster_FR.writeMicroseconds(motor_speed);
} else if (incomingByte[2] == 3){
mythruster_FL.writeMicroseconds(motor_speed);
} else if (incomingByte[2] == 4){
mythruster_BR.writeMicroseconds(motor_speed);
} else if (incomingByte[2] == 5){
mythruster_BL.writeMicroseconds(motor_speed);
} else if (incomingByte[2] == 6){
mythruster_R.writeMicroseconds(motor_speed);
} else if (incomingByte[2] == 7){
mythruster_L.writeMicroseconds(motor_speed);
}


}

if (Serial.available>=4){

if (incomingByte[2] == 2){
mythruster_FR.writeMicroseconds();
} else if (incomingByte[2] == 3){
mythruster_FL.writeMicroseconds();
} else if (incomingByte[2] == 4){
mythruster_BR.writeMicroseconds();
} else if (incomingByte[2] == 5){
mythruster_BL.writeMicroseconds();
} else if (incomingByte[2] == 6){
mythruster_R.writeMicroseconds();
} else if (incomingByte[2] == 7){
mythruster_L.writeMicroseconds();
}

}

reportIMUData();
}

if (Serial.available>=4){

if (incomingByte[2] == 2){
mythruster_FR.writeMicroseconds();
} else if (incomingByte[2] == 3){
mythruster_FL.writeMicroseconds();
} else if (incomingByte[2] == 4){
mythruster_BR.writeMicroseconds();
} else if (incomingByte[2] == 5){
mythruster_BL.writeMicroseconds();
} else if (incomingByte[2] == 6){
mythruster_R.writeMicroseconds();
} else if (incomingByte[2] == 7){
mythruster_L.writeMicroseconds();
}

}
void reportIMUData() {
sensors_event_t orientation , gyro , accel;
bno.getEvent(&orientation, Adafruit_BNO055::VECTOR_EULER);
bno.getEvent(&gyro, Adafruit_BNO055::VECTOR_GYROSCOPE);
bno.getEvent(&accel, Adafruit_BNO055::VECTOR_LINEARACCEL);

Serial.write(gyro->orientation.x);
Serial.write(gyro->orientation.y);
Serial.write(gyro->orientation.z);
Serial.write(gyro->gyro.x);
Serial.write(gyro->gyro.y);
## sends the information from getEvent to backend
Serial.write(gyro->gyro.z);
Serial.write(gyro->accel.x);
Serial.write(gyro->accel.y);
Serial.write(gyro->accel.z);




}

void printEvent(sensors_event_t* event) {
double x = -1000000, y = -1000000 , z = -1000000;
else if (event->type == SENSOR_TYPE_ORIENTATION) {
Serial.print("Orient:");
x = event->orientation.x;
y = event->orientation.y;
z = event->orientation.z;
}
else if (event->type == SENSOR_TYPE_ROTATION_VECTOR) {
Serial.print("Rot:");
x = event->gyro.x;
y = event->gyro.y;
z = event->gyro.z;
}
else if (event->type == SENSOR_TYPE_LINEAR_ACCELERATION) {
Serial.print("Linear:");
x = event->acceleration.x;
y = event->acceleration.y;
z = event->acceleration.z;
}
else {
Serial.print("Unk:");
}

Serial.print("\tx= ");
Serial.print(x);
Serial.print(" |\ty= ");
Serial.print(y);
Serial.print(" |\tz= ");
Serial.println(z);

}