Skip to content

Commit

Permalink
improved goalkeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Pusch committed Mar 15, 2019
1 parent 4ff5e37 commit 29327e1
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 25 deletions.
6 changes: 4 additions & 2 deletions IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class IO {
Key *_resetProperties [2] = { &decreasePage, &increasePage }; Shortcut resetProperties = Shortcut( _resetProperties, 2, MUTE_KEYS, 2000 ); // Alle Konfigurationen und Kalibrierungen zurücksetzten
Key *_kickerStart [2] = { &increasePage, &start }; Shortcut kickerStart = Shortcut( _kickerStart, 2, MUTE_KEYS, 0 ); // aktiviere einen dauerhaften Schuss
Key *_kickerStop [2] = { &increasePage, &stop }; Shortcut kickerStop = Shortcut( _kickerStop, 2, MUTE_KEYS, 0 ); // deaktiviere einen dauerhaften Schuss
Key *_shiftStart [2] = { &selectMenu, &start }; Shortcut shiftStart = Shortcut( _shiftStart, 2, MUTE_KEYS, 0, 600, 200 ); //
Key *_shiftStop [2] = { &selectMenu, &stop }; Shortcut shiftStop = Shortcut( _shiftStop, 2, MUTE_KEYS, 0, 600, 200 ); //
Key *_shiftStart [2] = { &selectMenu, &start }; Shortcut shiftStart = Shortcut( _shiftStart, 2, MUTE_KEYS, 0, 200, 50 ); //
Key *_shiftStop [2] = { &selectMenu, &stop }; Shortcut shiftStop = Shortcut( _shiftStop, 2, MUTE_KEYS, 0, 600, 50 ); //

void update();

Expand All @@ -163,6 +163,8 @@ class IO {
Timer kickActive = Timer( 50 );
Timer sendHeartBeat = Timer( 250 ); // wurde Heartbeat des Gegners empfangen?
Timer bluetoothSend = Timer( 100 ); // sollen Bluetooth-Updates gesendet werden?
Timer farSidelineRight= Timer( 100 ); // befinden wir uns am rechten seitlichen Rand des Spielfeldes
Timer farSidelineLeft = Timer( 100 ); // befinden wir uns am linken seitlichen Rand des Spielfeldes

// all global variables
Value aggressive = Value( BOOLEAN );
Expand Down
3 changes: 2 additions & 1 deletion Light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ void Light::light() {

if (pui.onDemand()) {
//NO Animation
if(! io.animationEnabled.get()){

if (!io.animationEnabled.get()){
pui.setPixelState(0, 0, true);
pui.setPixelState(1, io.battery.on());
pui.setPixelState(2, io.seeMate.on(), true);
Expand Down
16 changes: 8 additions & 8 deletions Pilot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ void Pilot::setState() {
switch (io.state.get()) {
default:
case BACK:
if (us.back() <= COURT_REARWARD_MAX) io.state.set(GOALKEEPER, "dis_b<");
if (us.back() <= COURT_REARWARD_MAX) io.state.set(GOALKEEPER, "enter penalty area");
//else if (io.state.outsidePeriod(BACKWARD_MAX_DURATION)) io.state.set(FREEING, "time>");
break;
case GOALKEEPER:
if (io.seeBall.off() && io.stateDirection.outsidePeriod(SIDEWARD_MAX_DURATION)) io.stateDirection.set(io.stateDirection.off(), "t>");
if (io.seeBall.off() && io.stateDirection.outsidePeriod(SIDEWARD_MAX_DURATION)) io.stateDirection.set(io.stateDirection.off(), "turn:timeout");
else if (io.seeBall.on() || io.stateDirection.outsidePeriod(SIDEWARD_MIN_DURATION)) {
if (io.seeBallLeft.on()) io.stateDirection.set(LEFT, "ball<");
else if (io.seeBallRight.on()) io.stateDirection.set(RIGHT, "ball>");
if (io.seeBallLeft.on()) io.stateDirection.set(LEFT, "turn:ball left");
else if (io.seeBallRight.on()) io.stateDirection.set(RIGHT, "turn:ball right");

if (us.back() > COURT_REARWARD_MAX) io.state.set(BACK, "dis_b>"); // fahre rückwärts
if (atGatepost()) io.stateDirection.set(io.stateDirection.off(), "g");
if (us.back() > COURT_REARWARD_MAX) io.state.set(BACK, "leave penalty area"); // fahre rückwärts
else if (atGatepost()) io.stateDirection.set(io.stateDirection.off(), "turn:at gatepost");
}
break;
case GOALPOST_GO:
Expand Down Expand Up @@ -185,8 +185,8 @@ int Pilot::face(int angle, int speed) {

bool Pilot::atGatepost() {
// benutze Abstand in Bewegungsrichtung
if (io.stateDirection.left()) return us.left() < COURT_BORDER_MIN;
else return us.right() < COURT_BORDER_MIN;
if (io.stateDirection.left()) return io.farSidelineLeft.on();
else return io.farSidelineRight.on();
}

Pilot drive;
2 changes: 2 additions & 0 deletions UltraSonic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ void Ultrasonic::update() {
Wire.write(byte(0x51));
Wire.endTransmission();
}
if (right() >= COURT_BORDER_MIN) io.farSidelineRight.set();
if (left() >= COURT_BORDER_MIN) io.farSidelineLeft.set();
endSegment();
}

Expand Down
1 change: 1 addition & 0 deletions UltraSonic.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define Ultrasonic_h

#include "Demand.h"
#include "IO.h"

class Ultrasonic : public Demand {
public:
Expand Down
5 changes: 1 addition & 4 deletions Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ void printDebug(String str, bool space) {
DEBUG_SERIAL.print(F(" "));
}
if (DEBUG_INFO) {
DEBUG_SERIAL.print(format(us.left(), 3, 3));
DEBUG_SERIAL.print(F("<>"));
DEBUG_SERIAL.print(format(us.right(), 3, 3));
DEBUG_SERIAL.print(F(" "));

}
io.runtime.set();
}
Expand Down
2 changes: 1 addition & 1 deletion Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ void Value::sendDebug(byte pin) {
void Value::sendDebug(String reason, byte pin) {
if (isDebug()) {
String m = prepareDebug(pin);
if (isDebug(DEBUG_REASON)) m += reason;
if (isDebug(DEBUG_REASON)) m += ":" + reason;
debug(m);
}
}
Expand Down
4 changes: 2 additions & 2 deletions core.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
// TIMES
#define BACKWARD_MAX_DURATION 4000 // wann darf frühestens eingegriffen werden
#define GOAL_STUCK_DURATION 500 // wie lange soll nach vorne gefahren werden?
#define SIDEWARD_MAX_DURATION 4000 // max Zeit für Seitwärtsfahren
#define SIDEWARD_MAX_DURATION 5000 // max Zeit für Seitwärtsfahren
#define SIDEWARD_MIN_DURATION 1000 // min Zeit für Seitwärtsfahren
#define TURN_MAX_DURATION 1500 // max Zeit für Drehmodus
#define RETURN_MAX_DURATION 1500 // max Zeit für Drehmodus zurück
Expand Down Expand Up @@ -87,7 +87,7 @@
#define COURT_REARWARD_MAX 35 // optimaler Abstand nach hinten
#define COURT_REARWARD_MIN 25 // optimaler Abstand nach hinten
#define COURT_WIDTH 150 // Summe der Abstände nach rechts und links
#define COURT_BORDER_MIN 40 // Abstand nach rechts bzw. links am Torpfosten
#define COURT_BORDER_MIN 20 // Abstand nach rechts bzw. links am Torpfosten
#define COURT_WIDTH_FREE 140
#define COURT_POST_TO_BORDER 110 // Abstand nach rechts bzw. links am Torpfosten
#define MAX_DISTANCE 200
Expand Down
17 changes: 12 additions & 5 deletions iceberg.19.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ void setup() {
setupDone();

/*****************************************************/
// io.state.startDebug();
io.state.startDebug();
// io.drivePower.startDebug();
// io.stateDirection.startDebug();
// digitalWrite(io.kick.getPin(), LOW);
io.stateDirection.startDebug();
/*****************************************************/
}

Expand All @@ -51,7 +50,7 @@ void loop() {
if (io.selectPage.click()) { /*d.toggle(); */ }
if (io.decreaseMenu.click()) { /*d.scroll(-1); */ }
if (io.increaseMenu.click()) { /*d.scroll(1); */ }
if (io.selectMenu.click()) { debug(F("selectMenu")); }
if (io.selectMenu.click()) { /*debug(F("selectMenu")); */ }
if (io.testKick.click()) { kick(); }
if (io.compassCalibration.click()) {
io.headingOffset.set(io.zOrientation.get());
Expand All @@ -68,7 +67,15 @@ void loop() {
if (io.resetProperties.click()) { debug(F("resetProperties")); }
if (io.kickerStart.click()) { debug(F("kickerStart")); io.kickPermanent.set(true); }
if (io.kickerStop.click()) { debug(F("kickerStop")); io.kickPermanent.set(false); }
if (io.shiftStart.click()) { debug(F("shiftStart")); }
if (io.shiftStart.click()) {
debug(format(us.left(), 3, 3));
debug(format(us.left2(), 3, 3));
debug(format(us.left3(), 3, 3));
debug(F("<>"));
debug(format(us.right(), 3, 3));
debug(format(us.right2(), 3, 3));
debug(format(us.right3(), 3, 3));
}
if (io.shiftStop.click()) { debug(F("shiftShop")); }
/*
if (io.drivePower.outsidePeriod(400)) drive.brake(false);
Expand Down
4 changes: 2 additions & 2 deletions include.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
#define include_h

// Lade fundamentale Daten, die alle benötigen: Einstellungen, Pintabelle, Basiswerkzeuge, Bibliotheken, Initialisiere globale Variablen
#include "IO.h"
#include "IO.h"
#include "Demand.h"

// Lade alle aufwendigeren Klassen und Werkzeuze
#include "Utility.h"
#include "Camera.h"
#include "Light.h"
#include "Pilot.h"
#include "Orientation.h"

#include "Ultrasonic.h"
#include "Reflexion.h"

Expand Down

0 comments on commit 29327e1

Please sign in to comment.