tuned path sequencing
PATH is in lab coordinates, then transformed
This commit is contained in:
parent
890cc88143
commit
b2d0b01232
3 changed files with 42 additions and 10 deletions
|
|
@ -46,7 +46,21 @@ void Robot::SetDestination(const Pose& dest)
|
||||||
Serial.print(dest.y);
|
Serial.print(dest.y);
|
||||||
Serial.print('\n');
|
Serial.print('\n');
|
||||||
|
|
||||||
destPose = dest;
|
// transform to board space
|
||||||
|
|
||||||
|
Pose transformed;
|
||||||
|
|
||||||
|
// rotate clockwise
|
||||||
|
transformed.x = dest.y;
|
||||||
|
transformed.y = -dest.x;
|
||||||
|
transformed.theta = dest.theta;
|
||||||
|
|
||||||
|
// add offset
|
||||||
|
transformed.x += offsetPose.x;
|
||||||
|
transformed.y += offsetPose.y;
|
||||||
|
transformed.theta += offsetPose.theta;
|
||||||
|
|
||||||
|
destPose = transformed;
|
||||||
robotState = ROBOT_DRIVE_TO_POINT;
|
robotState = ROBOT_DRIVE_TO_POINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,13 +100,21 @@ float boost(float input, float boost) {
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pose PATH[2] = {
|
// x forward
|
||||||
Pose(43.0,0,0),
|
// y left
|
||||||
Pose(0,0,0),
|
//
|
||||||
|
// goal y forward x right
|
||||||
|
const int PATH_LEN=4;
|
||||||
|
Pose PATH[PATH_LEN] = {
|
||||||
|
Pose(0.0, 43.0, 0.0),
|
||||||
|
Pose(43.0, 0.0, 0.0),
|
||||||
|
Pose(43.0, 43.0, 0.0),
|
||||||
|
Pose(0.0,0.0,0.0),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void Robot::DrivePath(void) {
|
void Robot::DrivePath(void) {
|
||||||
currPose = Pose(); // clear pose
|
currPose = offsetPose; // clear pose
|
||||||
index = 0;
|
index = 0;
|
||||||
SetDestination(PATH[index]);
|
SetDestination(PATH[index]);
|
||||||
}
|
}
|
||||||
|
|
@ -113,9 +135,16 @@ void Robot::DriveToPoint(void)
|
||||||
float forward_err = cos(currPose.theta) * (destPose.x - currPose.x)
|
float forward_err = cos(currPose.theta) * (destPose.x - currPose.x)
|
||||||
+ sin(currPose.theta) * (destPose.y - currPose.y);
|
+ sin(currPose.theta) * (destPose.y - currPose.y);
|
||||||
|
|
||||||
|
|
||||||
|
if (heading_err > 45.0) {
|
||||||
|
forward_err = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
float turn_effort = heading_err * LATERAL_kP;
|
float turn_effort = heading_err * LATERAL_kP;
|
||||||
float forward_effort = forward_err * LONGITUDINAL_kP;
|
float forward_effort = forward_err * LONGITUDINAL_kP;
|
||||||
|
|
||||||
|
turn_effort = max(min(turn_effort, 100.0), -100.0); // constrain turn_effort
|
||||||
|
|
||||||
#ifdef __NAV_DEBUG__
|
#ifdef __NAV_DEBUG__
|
||||||
// Print useful stuff here.
|
// Print useful stuff here.
|
||||||
|
|
||||||
|
|
@ -138,6 +167,7 @@ void Robot::HandleDestination(void)
|
||||||
index += 1;
|
index += 1;
|
||||||
if (index == len(PATH)) {
|
if (index == len(PATH)) {
|
||||||
EnterIdleState();
|
EnterIdleState();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TeleplotPrint("path_index", index);
|
TeleplotPrint("path_index", index);
|
||||||
|
|
|
||||||
|
|
@ -78,9 +78,9 @@ void Robot::RobotLoop(void)
|
||||||
//chassis.SetMotorEfforts(220,-220);
|
//chassis.SetMotorEfforts(220,-220);
|
||||||
|
|
||||||
if (chassis.buttonA.isPressed()) {
|
if (chassis.buttonA.isPressed()) {
|
||||||
Pose dest(0.0, 10.0, 0.0);
|
//Pose dest = Pose(0.0,43.0, 0.0);
|
||||||
index = 0;
|
//SetDestination(dest);
|
||||||
SetDestination(dest);
|
DrivePath();
|
||||||
}
|
}
|
||||||
if (chassis.buttonB.isPressed()) {
|
if (chassis.buttonB.isPressed()) {
|
||||||
EnterCalibTurn();
|
EnterCalibTurn();
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,10 @@
|
||||||
const float TARGET_SQ_DIST = pow(3.0, 2); // distance from setpoint that is ok (cm)
|
const float TARGET_SQ_DIST = pow(3.0, 2); // distance from setpoint that is ok (cm)
|
||||||
const float TARGET_RAD_ERR = 0.25; // angle from setpoint that is ok (rad)
|
const float TARGET_RAD_ERR = 0.25; // angle from setpoint that is ok (rad)
|
||||||
|
|
||||||
const float LONGITUDINAL_kP = 3.0;
|
const float LONGITUDINAL_kP = 4.0;
|
||||||
const float LATERAL_kP = 3.0 * RAD_TO_DEG;
|
const float LATERAL_kP = 1.5 * RAD_TO_DEG;
|
||||||
|
|
||||||
|
const Pose offsetPose = Pose(100.0, 100.0, 0.0); // hack to avoid negatives
|
||||||
|
|
||||||
class Robot
|
class Robot
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue