diff --git a/include/data_source.h b/include/data_source.h index c995c08..f5596b8 100644 --- a/include/data_source.h +++ b/include/data_source.h @@ -9,7 +9,7 @@ class DataSource { public: DataSource(); - DataSource(HardwareSerial, int); + DataSource(usb_serial_class, int); DataSource(TwoWire); DataSource(int, bool); @@ -29,7 +29,7 @@ class DataSource { P_PIND }; - HardwareSerial* ser; + usb_serial_class* ser; TwoWire* i2c; int pin; diff --git a/include/data_source_ball.h b/include/data_source_ball.h new file mode 100644 index 0000000..857df3e --- /dev/null +++ b/include/data_source_ball.h @@ -0,0 +1,11 @@ +#include "data_source.h" + +class DataSourceBall : public DataSource{ + + public: + DataSourceBall(usb_serial_class ser, int baud); + void postProcess() override; + void test() override; + int angle,distance; + bool ballSeen; +}; \ No newline at end of file diff --git a/include/sensors.h b/include/sensors.h index 7473793..54fb6c3 100644 --- a/include/sensors.h +++ b/include/sensors.h @@ -1,5 +1,6 @@ #include #include "data_source_bno055.h" +#include "data_source_ball.h" #include "motor.h" #include "drivecontroller.h" @@ -13,4 +14,5 @@ void initSensors(); void updateSensors(); extr DataSource* compass; -extr DriveController* drive; \ No newline at end of file +extr DataSource* ball; +extr DriveController* drive; diff --git a/src/data_source.cpp b/src/data_source.cpp index e72c70d..9324adf 100644 --- a/src/data_source.cpp +++ b/src/data_source.cpp @@ -13,7 +13,7 @@ DataSource::DataSource(TwoWire i2c_){ } -DataSource::DataSource(HardwareSerial ser_, int baud){ +DataSource::DataSource(usb_serial_class ser_, int baud){ this->ser = &(ser_); protocol = 2; diff --git a/src/data_source_ball.cpp b/src/data_source_ball.cpp new file mode 100644 index 0000000..6434c51 --- /dev/null +++ b/src/data_source_ball.cpp @@ -0,0 +1,25 @@ +#include "data_source_ball.h" +#include "vars.h" + +DataSourceBall::DataSourceBall(usb_serial_class ser_, int baud) : DataSource(ser_, baud) { +} + +void DataSourceBall :: postProcess(){ + if((value & 0x01) == 1){ + distance = value; + ballSeen = distance > 1; + }else{ + angle = value * 2; + } +} + +void DataSourceBall :: test(){ + this->update(); + if(ballSeen){ + DEBUG_PRINT.print(angle); + DEBUG_PRINT.print(" | "); + DEBUG_PRINT.println(distance); + }else{ + DEBUG_PRINT.println("Not seeing ball"); + } +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index aacf1b0..0ef2899 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,5 +16,6 @@ void setup() { void loop() { updateSensors(); //should recenter using predefined values - drive->drive(0, 0, 0); + // drive->drive(0, 0, 0); + ball->test(); } \ No newline at end of file diff --git a/src/sensors.cpp b/src/sensors.cpp index 747493d..29efefb 100644 --- a/src/sensors.cpp +++ b/src/sensors.cpp @@ -4,6 +4,7 @@ void initSensors(){ compass = new DataSourceBNO055(); 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)); + ball = new DataSourceBall(Serial, 57600); } void updateSensors(){