Skip to content

Commit

Permalink
Remove all ref to sweep
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkaMaul committed Jan 23, 2017
1 parent cbd8b1d commit 1d24288
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 108 deletions.
42 changes: 0 additions & 42 deletions src/motors.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,45 +344,3 @@ int is_running_in_correct_angle(state *s){
}
return 0;
}

//Sweep motor

/**
* Function which can be used to make the motor sweep at a specified speed at a specified angle
* @param s State structure
* @param speed Speed for Sweep motor (usually MAX_SWEEP_SPEED)
* @param angle Speed for LeE (usually MAX_SWEEP_SPEED)
* @return 0 if everything is allright -1 else
*/
int sweep(state *s, int speed, int angle)
{
log_this(s, "[%s:sweep] Sweeping for %d degrees\n", __FILE__, angle);
int cur_angle_sweep=ev3_get_position(s->sweepmotor);
int rel_sweep_angle = cur_angle_sweep + angle;
if (abs(rel_sweep_angle) > MAX_SWEEP_ANGLE) {
log_this(s, "[%s:sweep] Sweep failed current sweep angle + desired angle exceed limit (%d(actual) --> %d(desired)) \n", __FILE__, cur_angle_sweep,cur_angle_sweep+ angle);
return -1;
}
//printf("[sweep] current angle=%d desired angle=%d\n",cur_angle_sweep, rel_sweep_angle);
ev3_set_speed_sp(s->sweepmotor, speed);
ev3_set_position_sp(s->sweepmotor, rel_sweep_angle);
ev3_command_motor_by_name(s->sweepmotor, "run-to-abs-pos");

while (ev3_motor_state(s->sweepmotor) & MOTOR_RUNNING);

return 0;
}

/**
* Function which can be used to make the motor sweep at a specified speed to an absolute angle
* @param s State structure
* @param speed Speed for Sweep motor (usually MAX_SWEEP_SPEED)
* @param angle Speed for LeE (usually MAX_SWEEP_SPEED)
* @return 0 if everything is allright -1 else
*/
int sweep_absolute(state *s, int speed, int angle)
{
int current_angle = ev3_get_position(s->sweepmotor);
int relative_angle = angle - current_angle;
return sweep(s, speed, relative_angle);
}
66 changes: 0 additions & 66 deletions src/robot.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,72 +133,6 @@ int look_for_ball_mecanical(state *s)
return 0;
}

/**
* Function to look for the ball when close to the ball area
* @param s State of LeE
* @return angle if ball is found SONAR_ERROR_ANGLE otherwise
*/
int look_for_ball_in_close_perimeter(state *s){
sweep(s, 400, MAX_SWEEP_ANGLE);
int distanceToBallorObstacle = distance_from_obstacle(s);
int turn_sweep= -MAX_SWEEP_ANGLE;
log_this(s, "[%s] Look for ball started\n", __FILE__);
log_this(s, "[%s] Distance to ball or obstacle %d\n", __FILE__, distanceToBallorObstacle);
int sweep_angle=+SWEEP_ANGLE;
while((distanceToBallorObstacle == -1 || distanceToBallorObstacle > GAP_MIN_BETWEEN_ROBOT_BALL) && abs(turn_sweep) <= MAX_SWEEP_ANGLE)
{
turn_sweep+=sweep_angle;
//Positive for clockwise turn
sweep(s, 400, sweep_angle);
usleep(600000);
distanceToBallorObstacle = distance_from_obstacle(s);
log_this(s, "[%s] Distance to ball %d\n", __FILE__, distanceToBallorObstacle);
}
if(abs(turn_sweep) > MAX_SWEEP_ANGLE){
sweep(s, 400, -MAX_SWEEP_ANGLE);
return SONAR_ERROR_ANGLE;
}
//angle one detected is the first angle where the ball appears
int angle_one_detected=turn_sweep;
log_this(s, "[%s] First angle where ball is detected %d\n", __FILE__, angle_one_detected);

//sweep_absolute(s, 100, 0);
//return angle_one_detected;
/*
//Angle is too close to the limit so return the first angle found
if(abs(angle_one_detected+ERROR_DISTANCE_MARGIN) >= MAX_SWEEP_ANGLE){
int bissect_angle= -angle_one_detected+15;
log_this(s, "[%s] Not calculating second angle ball is too close to the limit of the sweeper capability. Ball at angle=%d\n", __FILE__, bissect_angle);
sweep_absolute(s, 100, 0);
return bissect_angle;
}
*/

int extra_max_sweep_angle=MAX_SWEEP_ANGLE+10;
while(distanceToBallorObstacle <= GAP_MIN_BETWEEN_ROBOT_BALL && abs(turn_sweep) < extra_max_sweep_angle && distanceToBallorObstacle!=-1)
{
turn_sweep+=sweep_angle;
//Positive for clockwise turn added 20 degrees if ball is in the limit of the sweep angle
sweep(s, 400, turn_sweep);
usleep(600000);
distanceToBallorObstacle = distance_from_obstacle(s);
log_this(s, "[%s] Distance to ball or obstacle %d\n", __FILE__, distanceToBallorObstacle);
}
int angle_two_lost=turn_sweep;
log_this(s, "[%s] Second angle where ball is not detected anymore %d\n", __FILE__, angle_two_lost);

//Calculated bisector based on the position of the robot
int bissect_angle= (angle_one_detected+angle_two_lost-sweep_angle)/2;
log_this(s, "[%s] Calculated bisector to turn to detect ball %d\n", __FILE__, bissect_angle);

//replace the motors to the original position
//sweep_absolute(s, 100, 0);
int turn_angle=bissect_angle-SWEEP_ANGLE;
turn_imprecise(s, TURNING_SPEED, turn_angle);
sweep_absolute(s, 400, 0);
return turn_angle;
}

/**
* Function to look for the ball anywhere close to the ball area //TODO Anywhere in the arena
* @param s State of LeE
Expand Down

0 comments on commit 1d24288

Please sign in to comment.