From f3e49b2a7af55e84e259cc8785d02b71a26498ac Mon Sep 17 00:00:00 2001 From: u-siri-ous Date: Thu, 5 Dec 2019 11:50:58 +0100 Subject: [PATCH] started writing goalie(), kinda dumb but seems to work --- include/game.h | 8 +++++--- include/goalie.h | 13 +++++++++++++ include/keeper.h | 11 +++++++++++ include/sensors.h | 9 +++++++-- src/game.cpp | 19 +++++++------------ src/goalie.cpp | 22 ++++++++++++++++++++++ src/keeper.cpp | 15 +++++++++++++++ src/main.cpp | 10 +++++----- src/sensors.cpp | 2 ++ 9 files changed, 87 insertions(+), 22 deletions(-) create mode 100644 include/goalie.h create mode 100644 include/keeper.h create mode 100644 src/goalie.cpp create mode 100644 src/keeper.cpp diff --git a/include/game.h b/include/game.h index 4421355..0b02f40 100644 --- a/include/game.h +++ b/include/game.h @@ -7,13 +7,15 @@ #include "sensors.h" #include "vars.h" #include "data_source_bno055.h" +#include "goalie.h" +#include "keeper.h" class Game{ public: Game(); - void keeper(); - void goalie(); - void ballBack(); + //void keeper(); + //void goalie(); + //void ballBack(); bool role, attackGoal; //1->goalie 0->keeper, 1->yellow 0->blue //~Game(); }; \ No newline at end of file diff --git a/include/goalie.h b/include/goalie.h new file mode 100644 index 0000000..029fe32 --- /dev/null +++ b/include/goalie.h @@ -0,0 +1,13 @@ +#pragma once + +#include "game.h" + +class Goalie{ + + public: + Goalie(); + void goalie(); + void ballBack(); + //void rigore(); to be implemented + +}; diff --git a/include/keeper.h b/include/keeper.h new file mode 100644 index 0000000..527cd8d --- /dev/null +++ b/include/keeper.h @@ -0,0 +1,11 @@ +#pragma once + +#include "game.h" + +class Keeper{ + + public: + Keeper(); + void keeper(); + //void keeperGoalie(); to be implemented +}; \ No newline at end of file diff --git a/include/sensors.h b/include/sensors.h index 7ded117..bd98eb6 100644 --- a/include/sensors.h +++ b/include/sensors.h @@ -1,4 +1,5 @@ #include +#pragma once #include "data_source_bno055.h" #include "data_source_ball.h" #include "data_source_camera.h" @@ -6,7 +7,6 @@ #include "motor.h" #include "data_source_controller.h" #include "drivecontroller.h" -#pragma once #include "game.h" #ifdef SENSORS_CPP #define extr @@ -15,6 +15,8 @@ #endif class Game; +class Goalie; +class Keeper; void initSensors(); void updateSensors(); @@ -24,4 +26,7 @@ extr DataSourceCamera* camera; //extr DataSource* us; extr DataSourceController* usCtrl; extr DriveController* drive; -extr Game* game; \ No newline at end of file + +extr Game* game; +extr Goalie* goalie; +extr Keeper* keeper; \ No newline at end of file diff --git a/src/game.cpp b/src/game.cpp index b71998c..04c054f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -4,16 +4,14 @@ Game::Game(){ } -void Game::goalie(){ - compass->readSensor(); - //drive->prepareDrive(0, 150, 0); +/* void Game::goalie(){ + /* //drive->prepareDrive(0, 150, 0); digitalWrite(LED_G, HIGH); if(ball->ballSeen){ - if(ball->angle >= 0 && ball->angle <= 45) drive->drive(0, 75, 0); - //else if(ball->angle <= 45) drive->drive(45, 75, 0); - else if(ball->angle > 45 && ball->angle <= 90) drive->drive(90, 75, 0); - //else if(ball->angle <= 135) drive->drive(135, 75, 0); - else if(ball->angle > 90 && ball->angle <= 180) drive->drive(180, 75, 0); + if(ball->angle >= 0 && ball->angle < 45) drive->drive(0, 75, 0); + else if(ball->angle >= 45 && ball->angle <= 60) drive->drive(45, 75, 0); + else if(ball->angle > 60 && ball->angle < 90) drive->drive(75, 75, 0); + else if(ball->angle >= 90 && ball->angle < 135) drive->drive(90, 75, 0); } else { drive->prepareDrive(0, 0, 0); drive->drive(0, 0, 0); @@ -21,7 +19,6 @@ void Game::goalie(){ } void Game::keeper(){ - compass->readSensor(); digitalWrite(LED_Y, HIGH); drive->prepareDrive(0, 0, 0); drive->drive(0, 0, 0); @@ -29,6 +26,4 @@ void Game::keeper(){ void ballBack(){ -} - - +} */ diff --git a/src/goalie.cpp b/src/goalie.cpp new file mode 100644 index 0000000..d99cf56 --- /dev/null +++ b/src/goalie.cpp @@ -0,0 +1,22 @@ +#include "goalie.h" + +Goalie::Goalie(){ + +} + +void Goalie::goalie(){ + digitalWrite(LED_G, HIGH); + if(ball->ballSeen){ + if(ball->angle >= 0 && ball->angle < 45) drive->drive(ball->angle, 75, 0); + else if(ball->angle >= 45 && ball->angle <= 60) drive->drive(ball->angle, 75, 0); + else if(ball->angle > 60 && ball->angle < 90) drive->drive(ball->angle, 75, 0); + else if(ball->angle >= 90 && ball->angle < 135) drive->drive(ball->angle, 75, 0); + } else { + drive->prepareDrive(0, 0, 0); + drive->drive(0, 0, 0); + } +} + +void Goalie::ballBack(){ + +} \ No newline at end of file diff --git a/src/keeper.cpp b/src/keeper.cpp new file mode 100644 index 0000000..667a7ce --- /dev/null +++ b/src/keeper.cpp @@ -0,0 +1,15 @@ +#include "keeper.h" + +Keeper::Keeper(){ + +} + +void Keeper::keeper(){ + digitalWrite(LED_Y, HIGH); + drive->prepareDrive(0, 0, 0); + drive->drive(0, 0, 0); +} + +/* void Keeper::keeperGoalie(){ + to be implemented +} */ \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 4cc77e7..103da14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,14 +12,14 @@ void setup() { } void loop() { - //updateSensors(); + updateSensors(); /*if(millis() % 100 == 0) DEBUG_PRINT.println(us->getValue());*/ - game->role = digitalRead(SWITCH_DX); + /* game->role = digitalRead(SWITCH_DX); game->attackGoal = digitalRead(SWITCH_SX); - if(game->role) game->goalie(); - else game->keeper(); - //game->goalie(); + if(game->role) goalie->goalie(); + else keeper->keeper(); */ + goalie->goalie(); //drive->drivePrepared(); //compass->test(); //usCtrl->test(); diff --git a/src/sensors.cpp b/src/sensors.cpp index c262ef9..55e09a0 100644 --- a/src/sensors.cpp +++ b/src/sensors.cpp @@ -14,6 +14,8 @@ void initSensors(){ usCtrl = new DataSourceController(dUs); game = new Game(); + goalie = new Goalie(); + keeper = new Keeper(); } void updateSensors(){