From c0b8771c470bd8dea2307e1613708639d368a532 Mon Sep 17 00:00:00 2001 From: "ema.coletta@gmail.com" Date: Sat, 31 Oct 2020 15:37:38 +0100 Subject: [PATCH] a bit of recalibration for everything for the presentation game --- include/position/positionsys_camera.h | 12 ++- include/sensors/linesys_camera.h | 2 +- include/sensors/linesys_camera_new.h | 40 +++++++++ include/strategy_roles/goalie.h | 2 +- src/sensors/linesys_camera_new.cpp | 116 ++++++++++++++++++++++++++ src/strategy_roles/keeper.cpp | 3 +- utility/OpenMV/conic_eff.py | 14 ++-- 7 files changed, 176 insertions(+), 13 deletions(-) create mode 100644 include/sensors/linesys_camera_new.h create mode 100644 src/sensors/linesys_camera_new.cpp diff --git a/include/position/positionsys_camera.h b/include/position/positionsys_camera.h index d75673f..a5bb905 100644 --- a/include/position/positionsys_camera.h +++ b/include/position/positionsys_camera.h @@ -2,10 +2,16 @@ #include "position/systems.h" -#define CAMERA_CENTER_X 0 -#define CAMERA_CENTER_Y 0 +//Note: those variables can be changes, and will need to change depending on camera calibration + +//Camera center: those setpoints correspond to the center of the field +#define CAMERA_CENTER_X 1 +#define CAMERA_CENTER_Y -10 + +//Camera goal: those setpoints correspond to the position of the center of the goal on the field #define CAMERA_GOAL_X 0 -#define CAMERA_GOAL_Y -13 +#define CAMERA_GOAL_Y -20 + #define CAMERA_CENTER_Y_ABS_SUM 72 //Actually it's ± MAX_VAL #define MAX_X 25 diff --git a/include/sensors/linesys_camera.h b/include/sensors/linesys_camera.h index 6a301f3..333ea1d 100644 --- a/include/sensors/linesys_camera.h +++ b/include/sensors/linesys_camera.h @@ -17,7 +17,7 @@ #define S4O A2 #define LINE_THRESH_CAM 90 -#define EXIT_TIME 100 +#define EXIT_TIME 125 #define LINES_EXIT_SPD 350 class LineSysCamera : public LineSystem{ diff --git a/include/sensors/linesys_camera_new.h b/include/sensors/linesys_camera_new.h new file mode 100644 index 0000000..8de96bd --- /dev/null +++ b/include/sensors/linesys_camera_new.h @@ -0,0 +1,40 @@ +// #pragma once + +// #include + +// #include "behaviour_control/ds_ctrl.h" +// #include "position/systems.h" + +// #include "vars.h" + +// #define S1I A14 +// #define S1O A15 +// #define S2I A16 +// #define S2O A17 +// #define S3I A20 +// #define S3O A0 +// #define S4I A1 +// #define S4O A2 + +// #define LINE_THRESH_CAM 90 +// #define EXTIME_CAM 75 +// #define LINES_EXIT_SPD_CAM 300 + +// class LineSysCamera : public LineSystem{ + +// public: +// LineSysCamera(); +// LineSysCamera(vector in_, vector out); + +// void update() override; +// void test() override; +// void outOfBounds(); + +// private: +// vector in, out; +// DataSource* ds; +// bool fboundsX, fboundsY, fboundsOX, fboundsOY, slow; +// int inV, outV, linesensOldX, linesensOldY, value, linetriggerI[4], linetriggerO[4], i; +// unsigned long exitTimer; +// byte linesens; +// }; \ No newline at end of file diff --git a/include/strategy_roles/goalie.h b/include/strategy_roles/goalie.h index aee10d5..cefb904 100644 --- a/include/strategy_roles/goalie.h +++ b/include/strategy_roles/goalie.h @@ -5,7 +5,7 @@ #include "strategy_roles/game.h" #define TILT_MULT 1.8 -#define TILT_DIST 180 +#define TILT_DIST 170 #define CATCH_DIST 150 #define GOALIE_ATKSPD_LAT 320 //255 #define GOALIE_ATKSPD_BAK 350 diff --git a/src/sensors/linesys_camera_new.cpp b/src/sensors/linesys_camera_new.cpp new file mode 100644 index 0000000..5a906fe --- /dev/null +++ b/src/sensors/linesys_camera_new.cpp @@ -0,0 +1,116 @@ +// #include "sensors/linesys_camera.h" +// #include "position/positionsys_camera.h" +// #include "sensors/sensors.h" +// #include "strategy_roles/games.h" + +// using namespace std; +// LineSysCamera::LineSysCamera() {} +// LineSysCamera::LineSysCamera(vector in_, vector out_){ +// this->in = in_; +// this->out = out_; + +// fboundsX = false; +// fboundsY = false; +// slow = false; + +// linesensOldX = 0; +// linesensOldY = 0; + +// tookLine = false; + +// for(int i = 0; i < 4; i++){ +// linetriggerI[i] = 0; +// linetriggerO[i] = 0; +// } + +// exitTimer = 0; +// linesens = 0; +// } + +// void LineSysCamera::update(){ +// inV = 0; +// outV = 0; +// tookLine = false; + +// for(DataSource* d : in) d->readSensor(); +// for(DataSource* d : out) d->readSensor(); + +// for(auto it = in.begin(); it != in.end(); it++){ +// i = it - in.begin(); +// ds = *it; +// linetriggerI[i] = ds->getValue() > LINE_THRESH_CAM; +// } +// for(auto it = out.begin(); it != out.end(); it++){ +// i = it - out.begin(); +// ds = *it; +// linetriggerO[i] = ds->getValue() > LINE_THRESH_CAM; +// } + +// for(int i = 0; i < 4; i++){ +// inV = inV | (linetriggerI[i] << i); +// outV = outV | (linetriggerO[i] << i); +// } + + +// if ((inV > 0) || (outV > 0)) { +// if(millis() - exitTimer > EXTIME_CAM) { +// fboundsX = true; +// fboundsY = true; +// } +// exitTimer = millis(); +// } + +// linesens |= inV | outV; +// outOfBounds(); +// } + +// void LineSysCamera::outOfBounds(){ + +// if(fboundsX == true) { +// if(linesens & 0x02) linesensOldX = 2; +// else if(linesens & 0x08) linesensOldX = 8; +// if(linesensOldX != 0) fboundsX = false; +// } +// if(fboundsY == true) { +// if(linesens & 0x01) linesensOldY = 1; +// else if(linesens & 0x04) linesensOldY = 4; +// if(linesensOldY != 0) fboundsY = false; +// } + +// if (millis() - exitTimer <= EXTIME_CAM){ +// if(linesens > 0) ((PositionSysCamera*)goalie->ps)->goCenter(); + +// tookLine = true; +// }else{ +// linesens = 0; +// linesensOldY = 0; +// linesensOldX = 0; +// } +// } + +// void LineSysCamera::test(){ +// update(); +// DEBUG.print("In: "); +// for(DataSource* d : in){ +// d->update(); +// DEBUG.print(d->getValue()); +// DEBUG.print(" | "); +// } +// DEBUG.print(" |---| "); +// DEBUG.print("Out: "); +// for(DataSource* d : out){ +// d->update(); +// DEBUG.print(d->getValue()); +// DEBUG.print(" | "); +// } +// DEBUG.println(); +// for(int i = 0; i < 4; i++){ +// DEBUG.print(linetriggerI[i]); +// DEBUG.print(" | "); +// DEBUG.println(linetriggerO[i]); +// } + +// DEBUG.println(inV); +// DEBUG.println(outV); +// DEBUG.println(); +// } \ No newline at end of file diff --git a/src/strategy_roles/keeper.cpp b/src/strategy_roles/keeper.cpp index 6d0040b..7e77f28 100644 --- a/src/strategy_roles/keeper.cpp +++ b/src/strategy_roles/keeper.cpp @@ -5,6 +5,7 @@ #include "sensors/sensors.h" #include "strategy_roles/keeper.h" #include "strategy_roles/games.h" +#include "position/positionsys_camera.h" Keeper::Keeper() : Game() { @@ -28,7 +29,7 @@ void Keeper::init(){ void Keeper::realPlay() { if(ball->ballSeen) keeper(); - else drive->prepareDrive(0,0,0); + else ((PositionSysCamera*)ps)->centerGoal(); } void Keeper::keeper() { diff --git a/utility/OpenMV/conic_eff.py b/utility/OpenMV/conic_eff.py index 0fdfd21..b04961c 100644 --- a/utility/OpenMV/conic_eff.py +++ b/utility/OpenMV/conic_eff.py @@ -38,8 +38,8 @@ blue_led.on() ############################################################################## -thresholds = [ (50, 98, -2, 30, 57, 113), # thresholds yellow goal - (22, 45, -32, -6, -16, 10)] # thresholds blue goal (6, 31, -15, 4, -35, 0) +thresholds = [ (58, 97, 9, 45, 51, 92), # thresholds yellow goal + (12, 30, -25, 1, -49, -2)] # thresholds blue goal (6, 31, -15, 4, -35, 0) roi = (0, 6, 318, 152) @@ -59,13 +59,13 @@ clock = time.clock()''' sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) -sensor.set_contrast(1) -sensor.set_saturation(1) +sensor.set_contrast(3) +sensor.set_saturation(3) sensor.set_brightness(0) sensor.set_quality(0) sensor.set_auto_whitebal(False) -sensor.set_auto_exposure(False, 6500) -sensor.set_auto_gain(True) +sensor.set_auto_exposure(False, 4500) +sensor.set_auto_gain(False, 15) sensor.skip_frames(time = 300) clock = time.clock() @@ -84,7 +84,7 @@ while(True): tt_blue = [(0,999,0,2)] ## creo una lista di tuple per il blue, valore x = 999 : non trovata img = sensor.snapshot() - for blob in img.find_blobs(thresholds, pixels_threshold=40, area_threshold=50, merge = True): + for blob in img.find_blobs(thresholds, pixels_threshold=30, area_threshold=40, merge = True): img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy())