Skip to content

Commit

Permalink
goalkeeper
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Pusch committed Mar 5, 2019
1 parent 910cf42 commit ebab60b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 10 deletions.
35 changes: 31 additions & 4 deletions Pilot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,30 @@ Pilot::Pilot() {
}

void Pilot::setState() {
if (io.seeBall.rising()) io.state.set(BALL_TRACKING, "view");
if (io.seeBall.falling()) io.state.set(BACK, "blind");
if (io.seeBall.change() && io.seeBall.on()) io.state.set(BALL_TRACKING, "view");
if (io.seeBall.change() && io.seeBall.off()) io.state.set(BACK, "blind");

switch (io.state.get()) {
default:
case BACK:

if (us.back() <= COURT_REARWARD_MAX) io.state.set(GOALKEEPER, "dis_b<");
//else if (io.state.outsidePeriod(BACKWARD_MAX_DURATION)) io.state.set(FREEING, "time>");
break;
case GOALKEEPER:

if (io.seeBall.off() && io.state.outsidePeriod(SIDEWARD_MAX_DURATION)) {
if (us.back() > COURT_REARWARD_MAX) io.state.set(BACK, "dis_b>"); // fahre rückwärts
} else if (io.state.outsidePeriod(SIDEWARD_MIN_DURATION)) {
if (us.back() > COURT_REARWARD_MAX) io.state.set(BACK, "dis_b>"); // fahre rückwärts
else if (io.seeBall.on()) {
if (io.ball.left(BALL_ANGLE_TRIGGER)) {
io.stateDirection.set(LEFT, "ball<");
io.state.now();
} else if (io.ball.right(BALL_ANGLE_TRIGGER)) {
io.stateDirection.set(RIGHT, "ball>");
io.state.now();
}
}
}
break;
case GOALPOST_GO:

Expand Down Expand Up @@ -89,7 +103,20 @@ void Pilot::update() {
drive(180, speed, rotation);
break;
case GOALKEEPER:
if (io.seeBall.off()) speed = map(abs(io.ball.get()), 0, BALL_ANGLE_TRIGGER, SPEED_KEEPER, 0.6 * SPEED_KEEPER);
else speed = SPEED_KEEPER;
if (io.stateDirection.left()) {
direction = ANGLE_SIDEWAY;
if (us.left() < COURT_BORDER_MIN) speed = SPEED_KEEPER * 0.7; // fahre langsamer am Spielfeldrand
} else {
direction = -ANGLE_SIDEWAY;
if (us.right() < COURT_BORDER_MIN) speed = SPEED_KEEPER * 0.7; // fahre langsamer am Spielfeldrand
}
if (us.back() < COURT_REARWARD_MIN) direction *= map(us.back(), 0, COURT_REARWARD_MIN, 8, 10) / 10.0; // fahre leicht schräg nach vorne

rotation = face(0);
speed = max(speed - abs(rotation), 0);
drive(direction, speed, rotation);
break;
case GOALPOST_GO:

Expand Down
1 change: 1 addition & 0 deletions Pilot.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "Chassis.h"
#include <PID_v1.h>
#include "Ultrasonic.h"

#define BACK 0
#define GOALKEEPER 1
Expand Down
2 changes: 1 addition & 1 deletion Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ void Timer::setSurviveTime(unsigned long _surviveTime) {
@param require: external condition to be active
*****************************************************/
void Timer::update() {
if(surviveTime > 0) Value::muteSet(insidePeroid(surviveTime));
Value::update();
Value::muteSet(surviveTime > 0 && insidePeroid(surviveTime));
}
/*****************************************************
trigger time
Expand Down
4 changes: 4 additions & 0 deletions UltraSonic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@ int Ultrasonic::frontRight() { return distance[4]; }
int Ultrasonic::front() { return min(frontLeft(), frontRight()); }

void Ultrasonic::init() {
beginSegment("us");
for(int i = 0; i < 5; i++) {
Wire.beginTransmission(addresses[i]);
Wire.write(byte(0x02));
Wire.write(byte(70));
Wire.endTransmission();
}
endSegment();
}

void Ultrasonic::update() {
beginSegment("us");
fetch();
for(int i = 0; i < 5; i++) {
Wire.beginTransmission(addresses[i]);
Wire.write(byte(0x00));
Wire.write(byte(0x51));
Wire.endTransmission();
}
endSegment();
}

void Ultrasonic::fetch() {
Expand Down
14 changes: 14 additions & 0 deletions core.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@
#define SPEED_AVOID_MATE 100 // [0 bis 255]~100 STATUS 9: Ausweichen
#define SPEED_DRIFT 80 // [0 bis 255]~140
#define SPEED_LINE 70 // [0 bis 255]~90
// 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 1500 // max Zeit für Seitwärtsfahren
#define SIDEWARD_MIN_DURATION 700 // 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
#define LOST_DURATION 700 // max Zeit für Ausweichmanöver
#define ROLE_LED_DURATION 350 // wie lange soll die Spielrolle angezeigt werden?
#define LINE_DURATION 300 // wie lange steuern wir der Linie entgegen?
#define HEADSTART_DURATION 350 // wie lange fahren wir volle Geschwindigkeit?
#define AVOID_MATE_DURATION 200 // wie lange weichen wir aus
#define DRIFT_DURATION 200 // wie lange steuern wir einem Drift entgegen?
#define PIXY_RESPONSE_DURATION 20000 // wie lange soll die Pixy-Led grün nachleuchten?

// BATTERY
#define BATTERY_MIN_VOLTAGE 800
Expand Down
7 changes: 2 additions & 5 deletions iceberg.19.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ void setup() {

/*****************************************************/
io.turbo.setLimits(false, false); // set broken turbo key to off
//io.state.startDebug();
//io.drivePower.startDebug();
io.kick.startDebug();
io.kick.showDebug(DEBUG_PIN);
io.kick.set(true);
io.state.startDebug();
io.drivePower.startDebug();
digitalWrite(io.kick.getPin(), LOW);
/*****************************************************/
}
Expand Down

0 comments on commit ebab60b

Please sign in to comment.