US sensors using DataSourceController now working
parent
80a01ee00a
commit
9c3ea8d602
|
@ -19,6 +19,7 @@
|
|||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"string_view": "cpp",
|
||||
"initializer_list": "cpp"
|
||||
"initializer_list": "cpp",
|
||||
"*.tcc": "cpp"
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
};
|
|
@ -4,6 +4,7 @@
|
|||
#include "data_source_camera.h"
|
||||
#include "data_source_us.h"
|
||||
#include "motor.h"
|
||||
#include "data_source_controller.h"
|
||||
#include "drivecontroller.h"
|
||||
|
||||
#ifdef SENSORS_CPP
|
||||
|
@ -18,5 +19,6 @@ void updateSensors();
|
|||
extr DataSource* compass;
|
||||
extr DataSource* ball;
|
||||
extr DataSource* camera;
|
||||
extr DataSource* us;
|
||||
//extr DataSource* us;
|
||||
extr DataSourceController* usCtrl;
|
||||
extr DriveController* drive;
|
||||
|
|
|
@ -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("========================================");
|
||||
|
||||
}
|
|
@ -17,4 +17,6 @@ void loop() {
|
|||
updateSensors();
|
||||
/*if(millis() % 100 == 0)
|
||||
DEBUG_PRINT.println(us->getValue());*/
|
||||
usCtrl->test();
|
||||
delay(200);
|
||||
}
|
|
@ -4,17 +4,19 @@
|
|||
void initSensors(){
|
||||
pinMode(SWITCH_DX, 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));
|
||||
compass = new DataSourceBNO055();
|
||||
ball = new DataSourceBall(&Serial4, 57600);
|
||||
camera = new DataSourceCamera(&Serial2, 19200);
|
||||
us = new DataSourceUS(&Wire1, int(113));
|
||||
usCtrl = new DataSourceController(dUs);
|
||||
}
|
||||
|
||||
void updateSensors(){
|
||||
compass->update();
|
||||
ball->update();
|
||||
camera->update();
|
||||
us->update();
|
||||
// usCtrl->test();
|
||||
}
|
Loading…
Reference in New Issue