calculate heading error
This commit is contained in:
parent
f4373cdc59
commit
718a551d72
2 changed files with 20 additions and 2 deletions
|
|
@ -42,22 +42,37 @@ void Robot::SetDestination(const Pose& dest)
|
|||
robotState = ROBOT_DRIVE_TO_POINT;
|
||||
}
|
||||
|
||||
float Robot::SquareDistance(void) {
|
||||
return pow((destPose.x - currPose.x),2) + pow((destPose.y-currPose.y),2);
|
||||
}
|
||||
|
||||
bool Robot::CheckReachedDestination(void)
|
||||
{
|
||||
/**
|
||||
* TODO: Add code to check if you've reached destination here.
|
||||
*/
|
||||
|
||||
float sq_dist = pow((destPose.x - currPose.x),2) + pow((destPose.y-currPose.y),2);
|
||||
float rad_error = abs(destPose.theta - currPose.theta);
|
||||
|
||||
return sq_dist < TARGET_SQ_DIST && rad_error < TARGET_RAD_ERR;
|
||||
return SquareDistance() < TARGET_SQ_DIST && rad_error < TARGET_RAD_ERR;
|
||||
}
|
||||
|
||||
void Robot::DriveToPoint(void)
|
||||
{
|
||||
if(robotState == ROBOT_DRIVE_TO_POINT)
|
||||
{
|
||||
float target_heading;
|
||||
|
||||
if (SquareDistance() < TARGET_SQ_DIST) {
|
||||
target_heading = destPose.theta;
|
||||
} else {
|
||||
target_heading = atan2(destPose.x - currPose.x, destPose.y - currPose.y);
|
||||
}
|
||||
|
||||
float heading_err = destPose.theta - target_heading;
|
||||
float forward_effort = cos(heading_err);
|
||||
|
||||
|
||||
/**
|
||||
* TODO: Add your IK algorithm here.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -52,4 +52,7 @@ protected:
|
|||
void CalibDrive(void);
|
||||
bool CheckReachedDestination(void);
|
||||
void HandleDestination(void);
|
||||
|
||||
// Square distance between current and target pose
|
||||
float SquareDistance(void);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue