started porting bt, corrected smth

pull/1/head
u-siri-ous 2019-12-11 16:29:18 +01:00
parent 0dabecbed5
commit f200685ffb
8 changed files with 62 additions and 4 deletions

14
include/data_source_bt.h Normal file
View File

@ -0,0 +1,14 @@
#pragma once
#include "data_source.h"
#include "vars.h"
class DataSourceBT : public DataSource{
public:
DataSourceBT(HardwareSerial* ser, int baud);
void test() override;
void connect();
void reconnect();
bool b, comrade;
};

View File

@ -16,6 +16,7 @@
#include "motor.h" #include "motor.h"
#include "ds_ctrl.h" #include "ds_ctrl.h"
#include "drivecontroller.h" #include "drivecontroller.h"
#include "data_source_bt.h"
void initSensors(); void initSensors();
void updateSensors(); void updateSensors();
@ -31,5 +32,6 @@ s_extr DataSourceBNO055* compass;
s_extr DataSourceBall* ball; s_extr DataSourceBall* ball;
s_extr DataSourceCamera* camera; s_extr DataSourceCamera* camera;
s_extr DriveController* drive; s_extr DriveController* drive;
s_extr DataSourceBT* bt;
s_extr int role; s_extr int role;

38
src/data_source_bt.cpp Normal file
View File

@ -0,0 +1,38 @@
#include "data_source_bt.h"
DataSourceBT :: DataSourceBT(HardwareSerial* ser_, int baud) : DataSource(ser_, baud){
connect();
}
void DataSourceBT :: connect(){
Serial3.print("$");
Serial3.print("$");
Serial3.print("$");
delay(100);
Serial3.println("C");
}
void DataSourceBT :: reconnect(){
if(!comrade){
if(!b){
Serial3.print("$");
Serial3.print("$");
Serial3.print("$");
}else{
Serial3.println("C");
}
b = !b;
}else{
Serial3.println("---");
}
}
void DataSourceBT :: test(){
if (DEBUG.available()) {
DEBUG.println((char)DEBUG.read());
}
if (Serial3.available()) {
Serial3.write((char)Serial3.read());
}
}

View File

@ -34,7 +34,7 @@ DriveController::DriveController(Motor* m1_, Motor* m2_, Motor* m3_, Motor* m4_)
integral = 0; integral = 0;
} }
void DriveController::prepareDrive(int dir=0, int speed=0, int tilt=0){ void DriveController::prepareDrive(int dir, int speed, int tilt){
pDir = dir; pDir = dir;
pSpeed = speed; pSpeed = speed;
pTilt = tilt; pTilt = tilt;
@ -48,7 +48,7 @@ float DriveController::torad(float f){
return (f * PI / 180.0); return (f * PI / 180.0);
} }
void DriveController::drive(int dir=0, int speed=0, int tilt=0){ void DriveController::drive(int dir, int speed, int tilt){
vx = ((speed * cosins[dir])); vx = ((speed * cosins[dir]));
vy = ((-speed * sins[dir])); vy = ((-speed * sins[dir]));

View File

@ -2,6 +2,6 @@
Game::Game() {} Game::Game() {}
void Game::play(bool condition=true){ void Game::play(bool condition){
if(condition) realPlay(); if(condition) realPlay();
} }

View File

@ -12,6 +12,7 @@ void Goalie::realPlay(){
} }
void Goalie::goalie() { void Goalie::goalie() {
compass->readSensor();
if(ball->angle >= 350 || ball->angle <= 10) { if(ball->angle >= 350 || ball->angle <= 10) {
if(ball->distance > 190) atk_direction = 0; if(ball->distance > 190) atk_direction = 0;
else atk_direction = ball->angle; else atk_direction = ball->angle;

View File

@ -25,4 +25,6 @@ void loop() {
// Last thing to do: movement // Last thing to do: movement
drive->drivePrepared(); drive->drivePrepared();
/* compass->test(); */
} }

View File

@ -17,6 +17,7 @@ void initSensors(){
camera = new DataSourceCamera(&Serial2, 19200); camera = new DataSourceCamera(&Serial2, 19200);
usCtrl = new DataSourceCtrl(dUs); usCtrl = new DataSourceCtrl(dUs);
linesCtrl = new DataSourceCtrlLines(lIn, lOut); linesCtrl = new DataSourceCtrlLines(lIn, lOut);
bt = new DataSourceBT(&Serial3, 115200);
/*game = new Game(); /*game = new Game();
goalie = new Goalie(); goalie = new Goalie();