ball, maybe

code_midgen
u-siri-ous 2019-11-18 14:42:43 +01:00
parent 7dd994e00c
commit 46fe1ca4a3
7 changed files with 45 additions and 5 deletions

View File

@ -9,7 +9,7 @@ class DataSource {
public: public:
DataSource(); DataSource();
DataSource(HardwareSerial, int); DataSource(usb_serial_class, int);
DataSource(TwoWire); DataSource(TwoWire);
DataSource(int, bool); DataSource(int, bool);
@ -29,7 +29,7 @@ class DataSource {
P_PIND P_PIND
}; };
HardwareSerial* ser; usb_serial_class* ser;
TwoWire* i2c; TwoWire* i2c;
int pin; int pin;

View File

@ -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;
};

View File

@ -1,5 +1,6 @@
#include <Arduino.h> #include <Arduino.h>
#include "data_source_bno055.h" #include "data_source_bno055.h"
#include "data_source_ball.h"
#include "motor.h" #include "motor.h"
#include "drivecontroller.h" #include "drivecontroller.h"
@ -13,4 +14,5 @@ void initSensors();
void updateSensors(); void updateSensors();
extr DataSource* compass; extr DataSource* compass;
extr DriveController* drive; extr DataSource* ball;
extr DriveController* drive;

View File

@ -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_); this->ser = &(ser_);
protocol = 2; protocol = 2;

25
src/data_source_ball.cpp Normal file
View File

@ -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");
}
}

View File

@ -16,5 +16,6 @@ void setup() {
void loop() { void loop() {
updateSensors(); updateSensors();
//should recenter using predefined values //should recenter using predefined values
drive->drive(0, 0, 0); // drive->drive(0, 0, 0);
ball->test();
} }

View File

@ -4,6 +4,7 @@
void initSensors(){ void initSensors(){
compass = new DataSourceBNO055(); 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)); 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(){ void updateSensors(){