-
Notifications
You must be signed in to change notification settings - Fork 0
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
Drive #3
Open
marialramosc
wants to merge
5
commits into
main
Choose a base branch
from
drive
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Drive #3
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c5c378d
Tests for the angle detected
marialramosc 81cfbfd
Line Detection with new libraries
marialramosc f7267b4
new libs for motors
marialramosc 426c97e
drive with BNO
marialramosc e0c54ad
lineDetection libs deleted and modified
marialramosc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "Arduino.h" | ||
#include "BNO.h" | ||
|
||
BNO::BNO() { | ||
} | ||
|
||
void BNO::iniciar() { | ||
if (!bno.begin(OPERATION_MODE_IMUPLUS)) { | ||
/* There was a problem detecting the BNO055 ... check your connections */ | ||
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!"); | ||
while (1); | ||
} | ||
bno.setExtCrystalUse(true); | ||
} | ||
|
||
void BNO::readValues() { | ||
|
||
sensors_event_t orientationData; | ||
bno.getEvent(&orientationData, Adafruit_BNO055::VECTOR_EULER); | ||
yaw = (double)orientationData.orientation.x; | ||
// convert yaw angle to range -180 to 180 | ||
yaw = (yaw > 0) ? (360 - yaw) : yaw; | ||
yaw = (yaw > 180) ? (yaw - 360) : yaw; | ||
|
||
if (offset > 0) { | ||
yaw = (yaw > 0) ? (-180 + yaw) : (180 + yaw); | ||
} | ||
// determine the direction | ||
right = (yaw >= 0) ? false : true; | ||
} | ||
|
||
|
||
void BNO::displayCalStatus() | ||
{ | ||
/* Get the four calibration values (0..3) */ | ||
/* Any sensor data reporting 0 should be ignored, */ | ||
/* 3 means 'fully calibrated" */ | ||
uint8_t system, gyro, accel, mag; | ||
system = gyro = accel = mag = 0; | ||
bno.getCalibration(&system, &gyro, &accel, &mag); | ||
|
||
/* The data should be ignored until the system calibration is > 0 */ | ||
Serial.print("\t"); | ||
|
||
/* Display the individual values */ | ||
Serial.print("Sys:"); | ||
Serial.print(system, DEC); | ||
Serial.print(" G:"); | ||
Serial.print(gyro, DEC); | ||
Serial.print(" A:"); | ||
Serial.print(accel, DEC); | ||
Serial.print(" M:"); | ||
Serial.println(mag, DEC); | ||
} | ||
|
||
|
||
double BNO::getYaw() { | ||
return yaw; | ||
} | ||
|
||
double BNO::getMag() { | ||
return mag; | ||
} | ||
|
||
void BNO::setOffset(double off) { | ||
offset = off; | ||
} | ||
|
||
bool BNO::isRight() { | ||
return right; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef BNO_h | ||
#define BNO_h | ||
|
||
#include <Wire.h> | ||
#include <Adafruit_Sensor.h> | ||
#include <Adafruit_BNO055.h> | ||
|
||
class BNO { | ||
private: | ||
double yaw; | ||
bool right = true; | ||
Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28, &Wire); | ||
double offset = 0; | ||
double mag = 0; | ||
|
||
public: | ||
|
||
BNO(); | ||
void iniciar(); | ||
void readValues(); | ||
double getYaw(); | ||
double getMag(); | ||
void setOffset(double off); | ||
bool isRight(); | ||
void displayCalStatus(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include "Arduino.h" | ||
#include "BNO.h" | ||
#include "drive.h" | ||
|
||
const int m1Speed = 4; | ||
const int m1P1 = 23; | ||
const int m1P2 = 22; | ||
const int m2Speed = 5; | ||
const int m2P1 = 24; | ||
const int m2P2 = 25; | ||
const int m3Speed = 6; | ||
const int m3P1 = 26; | ||
const int m3P2 = 27; | ||
const int testSpeed = 100; | ||
drive robotDrive(m1Speed, m1P1, m1P2, m2Speed, m2P1, m2P2, m3Speed, m3P1, m3P2); | ||
|
||
BNO orientationSensor; // Create an instance of the BNO class | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
orientationSensor.iniciar(); // Initialize the orientation sensor | ||
robotDrive.initialize(); | ||
} | ||
|
||
void loop() { | ||
orientationSensor.readValues(); // Read orientation values | ||
|
||
double yaw = orientationSensor.getYaw(); // Get yaw angle | ||
double mag = orientationSensor.getMag(); // Get magnetometer data | ||
bool right = orientationSensor.isRight(); // Check if yaw angle is to the right | ||
|
||
// Display orientation data | ||
Serial.print("Yaw: "); | ||
Serial.println(yaw); | ||
Serial.print("Magnetometer: "); | ||
Serial.println(mag); | ||
Serial.print("Right: "); | ||
Serial.println(right ? "Yes" : "No"); | ||
|
||
// Display calibration status | ||
Serial.println("Calibration Status:"); | ||
orientationSensor.displayCalStatus(); | ||
|
||
robotDrive.giro(testSpeed, yaw); | ||
|
||
delay(1000); // Delay for stability | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to make this expression in a single line.