1
Fork 0

path sequencing

This commit is contained in:
Andy Killorin 2026-02-05 08:46:51 -05:00
parent ab507bb68a
commit 890cc88143
Signed by: ank
GPG key ID: 23F9463ECB67FE8C
3 changed files with 26 additions and 3 deletions

View file

@ -3,6 +3,7 @@
*/ */
#include "robot.h" #include "robot.h"
#include "utils.h"
void Robot::UpdatePose(const Pose& delta) void Robot::UpdatePose(const Pose& delta)
{ {
@ -23,7 +24,7 @@ void Robot::UpdatePose(const Pose& delta)
Serial.print(currPose.x); Serial.print(currPose.x);
Serial.print(':'); Serial.print(':');
Serial.print(currPose.y); Serial.print(currPose.y);
Serial.print('|xy\n'); Serial.print("|xy\n");
//TeleplotPrint("x", currPose.x); //TeleplotPrint("x", currPose.x);
//TeleplotPrint("y", currPose.y); //TeleplotPrint("y", currPose.y);
@ -85,6 +86,17 @@ float boost(float input, float boost) {
return input; return input;
} }
Pose PATH[2] = {
Pose(43.0,0,0),
Pose(0,0,0),
};
void Robot::DrivePath(void) {
currPose = Pose(); // clear pose
index = 0;
SetDestination(PATH[index]);
}
void Robot::DriveToPoint(void) void Robot::DriveToPoint(void)
{ {
if(robotState == ROBOT_DRIVE_TO_POINT) if(robotState == ROBOT_DRIVE_TO_POINT)
@ -112,16 +124,23 @@ void Robot::DriveToPoint(void)
TeleplotPrint("linear_dist", SquareDistance()); TeleplotPrint("linear_dist", SquareDistance());
#endif #endif
//chassis.SetMotorEfforts(20, 20);
float boost_f = 15.0; float boost_f = 15.0;
chassis.SetMotorEfforts(boost(forward_effort - turn_effort,boost_f), boost(forward_effort + turn_effort, boost_f)); chassis.SetMotorEfforts(boost(forward_effort - turn_effort,boost_f), boost(forward_effort + turn_effort, boost_f));
} }
} }
#define len(x) sizeof(x) / sizeof(x[0])
void Robot::HandleDestination(void) void Robot::HandleDestination(void)
{ {
/** /**
* TODO: Stop and change state. Turn off LED. * TODO: Stop and change state. Turn off LED.
*/ */
EnterIdleState(); // TODO: sequence index += 1;
if (index == len(PATH)) {
EnterIdleState();
}
TeleplotPrint("path_index", index);
SetDestination(PATH[index]);
} }

View file

@ -79,6 +79,7 @@ void Robot::RobotLoop(void)
if (chassis.buttonA.isPressed()) { if (chassis.buttonA.isPressed()) {
Pose dest(0.0, 10.0, 0.0); Pose dest(0.0, 10.0, 0.0);
index = 0;
SetDestination(dest); SetDestination(dest);
} }
if (chassis.buttonB.isPressed()) { if (chassis.buttonB.isPressed()) {

View file

@ -36,6 +36,8 @@ protected:
Pose currPose; Pose currPose;
Pose destPose; Pose destPose;
int index = 0;
public: public:
Robot(void) {keyString.reserve(10);} Robot(void) {keyString.reserve(10);}
void InitializeRobot(void); void InitializeRobot(void);
@ -51,6 +53,7 @@ protected:
void UpdatePose(const Pose& u); void UpdatePose(const Pose& u);
void SetDestination(const Pose& destination); void SetDestination(const Pose& destination);
void DriveToPoint(void); void DriveToPoint(void);
void DrivePath(void);
void CalibTurn(void); void CalibTurn(void);
void CalibDrive(void); void CalibDrive(void);
bool CheckReachedDestination(void); bool CheckReachedDestination(void);