US sensors using DataSourceController now working

pull/1/head
EmaMaker 2019-12-02 14:50:59 +01:00
parent 80a01ee00a
commit 9c3ea8d602
6 changed files with 70 additions and 4 deletions

View File

@ -19,6 +19,7 @@
"unordered_map": "cpp", "unordered_map": "cpp",
"vector": "cpp", "vector": "cpp",
"string_view": "cpp", "string_view": "cpp",
"initializer_list": "cpp" "initializer_list": "cpp",
"*.tcc": "cpp"
} }
} }

View File

@ -0,0 +1,22 @@
#include "data_source.h"
#include "vars.h"
#include <Arduino.h>
#include <vector>
using namespace std;
class DataSourceController {
public:
DataSourceController();
DataSourceController(vector<DataSource*>);
public:
void update();
void test();
void postProcess();
void readSensor();
void getValue();
vector<DataSource*> ds;
};

View File

@ -4,6 +4,7 @@
#include "data_source_camera.h" #include "data_source_camera.h"
#include "data_source_us.h" #include "data_source_us.h"
#include "motor.h" #include "motor.h"
#include "data_source_controller.h"
#include "drivecontroller.h" #include "drivecontroller.h"
#ifdef SENSORS_CPP #ifdef SENSORS_CPP
@ -18,5 +19,6 @@ void updateSensors();
extr DataSource* compass; extr DataSource* compass;
extr DataSource* ball; extr DataSource* ball;
extr DataSource* camera; extr DataSource* camera;
extr DataSource* us; //extr DataSource* us;
extr DataSourceController* usCtrl;
extr DriveController* drive; extr DriveController* drive;

View File

@ -0,0 +1,37 @@
#include "data_source_controller.h"
using namespace std;
DataSourceController::DataSourceController() {}
DataSourceController::DataSourceController(vector<DataSource*> ds_){
this->ds = ds_;
}
void DataSourceController::readSensor(){
for(DataSource* d : ds){
d->readSensor();
}
}
void DataSourceController::update(){
for(DataSource* d : ds){
d->update();
}
}
void DataSourceController::postProcess(){
for(DataSource* d : ds){
d->postProcess();
}
}
void DataSourceController::getValue(){
for(DataSource* d : ds){
d->getValue();
}
}
void DataSourceController::test(){
DEBUG_PRINT.println("========================================");
for(DataSource* d : ds){
d->test();
}
DEBUG_PRINT.println("========================================");
}

View File

@ -17,4 +17,6 @@ void loop() {
updateSensors(); updateSensors();
/*if(millis() % 100 == 0) /*if(millis() % 100 == 0)
DEBUG_PRINT.println(us->getValue());*/ DEBUG_PRINT.println(us->getValue());*/
usCtrl->test();
delay(200);
} }

View File

@ -4,17 +4,19 @@
void initSensors(){ void initSensors(){
pinMode(SWITCH_DX, INPUT); pinMode(SWITCH_DX, INPUT);
pinMode(SWITCH_SX, INPUT); pinMode(SWITCH_SX, INPUT);
vector<DataSource*> dUs { new DataSourceUS(&Wire1, int(112)), new DataSourceUS(&Wire1, int(113)),
new DataSourceUS(&Wire1, int(114)), new DataSourceUS(&Wire1, int(115)) };
drive = new DriveController(new Motor(12, 11, 2, 45),new Motor(25, 24, 5, 135), new Motor(27, 26, 6, 225), new Motor(21, 22, 23, 315)); drive = new DriveController(new Motor(12, 11, 2, 45),new Motor(25, 24, 5, 135), new Motor(27, 26, 6, 225), new Motor(21, 22, 23, 315));
compass = new DataSourceBNO055(); compass = new DataSourceBNO055();
ball = new DataSourceBall(&Serial4, 57600); ball = new DataSourceBall(&Serial4, 57600);
camera = new DataSourceCamera(&Serial2, 19200); camera = new DataSourceCamera(&Serial2, 19200);
us = new DataSourceUS(&Wire1, int(113)); usCtrl = new DataSourceController(dUs);
} }
void updateSensors(){ void updateSensors(){
compass->update(); compass->update();
ball->update(); ball->update();
camera->update(); camera->update();
us->update(); // usCtrl->test();
} }