Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
hderambure committed Jan 23, 2017
2 parents 28fe81d + 668a1c4 commit 4316166
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions includes/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ int read_message_from_server(state *s, char *buffer);
int load_game_params(state *s, char *buffer);

int send_position(state *s, position sendedPosition);
void acknowledge(state *s, char *buffer);

int is_in_arena(state *s, position testedPosition);

Expand Down
17 changes: 10 additions & 7 deletions src/first_runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ int beginner_small_stadium_1(state *s, mainpos *p)
{
//If it's truely the first run, then do unitialize
if (s->doNotUnitialize != 1)
{
update_pos(s, p->s_fr_init);

//By default we are in realeasing position so just close the clamps when starting
//log_this(s,"[%s:beginner_small_stadium_1] Grabbing the ball\n", __FILE__);
grab(s, MAX_GRABBING_SPEED);
grab(s, MAX_GRABBING_SPEED);
}

//Go to center
log_this(s,"[%s:beginner_small_stadium_1] Going to ball area\n", __FILE__);
Expand All @@ -122,6 +121,8 @@ int beginner_small_stadium_1(state *s, mainpos *p)
log_this(s, "\n[%s:beginner_small_stadium_1] Going to the end\n", __FILE__);
go_to_pos(s, p->s_fr_ending);

grab(s, MAX_GRABBING_SPEED);

return 0;
}

Expand All @@ -134,7 +135,7 @@ int beginner_small_stadium_1(state *s, mainpos *p)
int beginner_small_stadium_2(state *s, mainpos *p)
{
//We already know where we are
//We already have open clamps
release(s, RELEASING_SPEED);

//Go to ball
log_this(s,"\n[%s:beginner_small_stadium_2] Going to ball area\n", __FILE__);
Expand All @@ -155,7 +156,6 @@ int beginner_small_stadium_2(state *s, mainpos *p)
go_to_pos(s, p->s_fr_init);

//Turn to be ready for next time
// turn(s, HIGH_TURNING_SPEED, 180);
turn_absolute(s, HIGH_TURNING_SPEED, -90);
update_angle(s, gyro_angle(s));
release(s, RELEASING_SPEED);
Expand Down Expand Up @@ -202,6 +202,7 @@ int beginner_large_stadium(state *s, mainpos *p)
//Go back a little
log_this(s, "\n[%s:beginner_large_stadium] Going back a little\n", __FILE__);
go_straight(s, MAX_WHEEL_SPEED, -20);
grab(s, MAX_GRABBING_SPEED); //Close the clamps

//Go to ending position
log_this(s, "\n[%s: beginner_large_stadium] Going to the end\n", __FILE__);
Expand All @@ -225,7 +226,8 @@ int finisher_small_stadium(state *s, mainpos *p)
update_pos(s, p->s_sr_init);
update_angle(s,90);
s->gyro_reference -= 180; //To set the starting gyro value to 90° (clockwise)
}
} else
release(s, RELEASING_SPEED);

//Go to center
log_this(s,"\n[%s:finisher_small_stadium_1] Going to ball area\n", __FILE__);
Expand Down Expand Up @@ -261,6 +263,7 @@ int finisher_small_stadium(state *s, mainpos *p)
go_to_pos(s, p->s_sr_init);

turn(s, HIGH_TURNING_SPEED, 180);
grab(s, MAX_GRABBING_SPEED);

//We don't want intialization next time
s->doNotUnitialize = 1;
Expand Down
9 changes: 9 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ int read_message_from_server(state *s, char *buffer)
nice_exit(s, EXIT_SUCCESS);
}

if (buffer[HEADER_SRC] != SERVER_ID)
acknowledge(s, buffer);

return readedBytes;
}

Expand Down Expand Up @@ -240,6 +243,12 @@ int send_position(state *s, position sendedPosition)
return send_message(s, MSG_POSITION, SERVER_ID, sendedPosition.x, sendedPosition.y);
}

void acknowledge(state *s, char *buffer)
{
unsigned int idAck = (unsigned int) ((uint16_t) *buffer);
send_message(s, MSG_ACK, buffer[HEADER_SRC], idAck);
}

/**
* Parse the START message to load the game parameters
* @param s State structure
Expand Down

0 comments on commit 4316166

Please sign in to comment.