ball, maybe
parent
7dd994e00c
commit
46fe1ca4a3
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
|
@ -1,5 +1,6 @@
|
|||
#include <Arduino.h>
|
||||
#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 DataSource* ball;
|
||||
extr DriveController* drive;
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
|
@ -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(){
|
||||
|
|
Loading…
Reference in New Issue