/** * This function processes the movement commands that the behaviours generate. * Depending on the values in the behaviour_command_t struct, it sets motor * speed, moves a given distance or rotates. */ void moveCommand(behaviour_command_t * cmd) { if(cmd->move_value > 0) // move or rotate? { writeString("cmd->move_value > 0\n"); if(cmd->rotate){ rotate(cmd->speed_left, cmd->dir, cmd->move_value, false); writeString("rotate\n"); }else if(cmd->move){ move(cmd->speed_left, cmd->dir, DIST_MM(cmd->move_value), false); writeString("move\n"); } cmd->move_value = 0; // clear move value - the move commands are only // given once and then runs in background. } else if(!(cmd->move || cmd->rotate)) // just move at speed? { changeDirection(cmd->dir); moveAtSpeed(cmd->speed_left,cmd->speed_right); } else if(isMovementComplete()) // movement complete? --> clear flags! { writeString("mouvement complete\n"); cmd->rotate = false; cmd->move = false; } }
void moveCommand(behaviour_command_t * cmd) { if(cmd->move_value > 0) { if(cmd->rotate) rotate(cmd->speed_left, cmd->dir, cmd->move_value, false); else if(cmd->move) move(cmd->speed_left, cmd->dir, DIST_MM(cmd->move_value), false); cmd->move_value = 0; } else if(!(cmd->move || cmd->rotate)) { changeDirection(cmd->dir); moveAtSpeed(cmd->speed_left,cmd->speed_right); } else if(isMovementComplete()) { cmd->rotate = false; cmd->move = false; } }