1
Fork 0

Compare commits

..

No commits in common. "511d5fc28158feb07d01dbe64f68dbc9d88f64c3" and "09bce37a9a1edf0edd2566dd3bc29ad397c7ccfd" have entirely different histories.

5 changed files with 24 additions and 26 deletions

View file

@ -95,7 +95,7 @@ void Chassis::InititalizeChassis(void)
/** /**
* The main Chassis loop. * The main Chassis loop.
*/ */
bool Chassis::ChassisLoop(Pose& delta) bool Chassis::ChassisLoop(Twist& velocity)
{ {
bool retVal = false; bool retVal = false;
@ -109,7 +109,7 @@ bool Chassis::ChassisLoop(Pose& delta)
#endif #endif
/* Update the wheel velocity so it gets back to Robot. */ /* Update the wheel velocity so it gets back to Robot. */
delta = CalcOdomFromWheelMotion(); velocity = CalcOdomFromWheelMotion();
loopFlag = 0; loopFlag = 0;
@ -137,22 +137,22 @@ void Chassis::SetMotorEfforts(int16_t left, int16_t right)
} }
Pose Chassis::CalcOdomFromWheelMotion(void) Twist Chassis::CalcOdomFromWheelMotion(void)
{ {
Pose delta; Twist delta;
float leftDelta = (float) leftMotor.speed float leftDelta = (float) leftMotor.speed * (float) CONTROL_LOOP_PERIOD_MS / 1000.0;
/ LEFT_TICKS_PER_CM; float rightDelta = (float) rightMotor.speed * (float) CONTROL_LOOP_PERIOD_MS / 1000.0;
float rightDelta = (float) rightMotor.speed
/ RIGHT_TICKS_PER_CM;
float distance = (leftDelta + rightDelta) / 2.0; float distance = (leftDelta + rightDelta) / 2.0;
distance /= LEFT_TICKS_PER_CM;
float deltaHeading = (rightDelta - leftDelta) float deltaHeading = (rightDelta - leftDelta)
/ (2.0 * ROBOT_RADIUS); / LEFT_TICKS_PER_CM
/ (3.14 * ROBOT_RADIUS);
delta.x = distance; delta.u = distance;
delta.theta = deltaHeading; delta.omega = deltaHeading;
/** /**
@ -163,8 +163,8 @@ Pose Chassis::CalcOdomFromWheelMotion(void)
*/ */
#ifdef __NAV_DEBUG__ #ifdef __NAV_DEBUG__
TeleplotPrint("u", delta.x); TeleplotPrint("u", delta.u);
TeleplotPrint("omega", delta.theta); TeleplotPrint("omega", delta.omega);
#endif #endif
return delta; return delta;

View file

@ -30,13 +30,13 @@ public:
void InititalizeChassis(void); void InititalizeChassis(void);
/* Where the bulk of the work for the motors gets done. */ /* Where the bulk of the work for the motors gets done. */
bool ChassisLoop(Pose&); bool ChassisLoop(Twist&);
/* Needed for managing motors. */ /* Needed for managing motors. */
static void Timer4OverflowISRHandler(void); static void Timer4OverflowISRHandler(void);
public: public:
Pose CalcOdomFromWheelMotion(void); Twist CalcOdomFromWheelMotion(void);
void SetMotorEfforts(int16_t, int16_t); void SetMotorEfforts(int16_t, int16_t);

View file

@ -4,23 +4,21 @@
#include "robot.h" #include "robot.h"
void Robot::UpdatePose(const Pose& delta) void Robot::UpdatePose(const Twist& twist)
{ {
/** /**
* TODO: Add your FK algorithm to update currPose here. * TODO: Add your FK algorithm to update currPose here.
*/ */
float transitHeading = currPose.theta + (delta.theta * 0.5); float transitHeading = currPose.theta + (twist.omega * 0.5);
currPose.x += delta.x * cos(transitHeading); currPose.x += twist.u * cos(transitHeading);
currPose.y += delta.x * sin(transitHeading); currPose.y += twist.u * sin(transitHeading);
currPose.theta += delta.theta;
#ifdef __NAV_DEBUG__ #ifdef __NAV_DEBUG__
TeleplotPrint("x", currPose.x); TeleplotPrint("x", currPose.x);
TeleplotPrint("y", currPose.y); TeleplotPrint("y", currPose.y);
TeleplotPrint("theta", currPose.theta * 180.0 / PI); TeleplotPrint("theta", currPose.theta);
#endif #endif
} }

View file

@ -27,11 +27,11 @@ void Robot::RobotLoop(void)
/** /**
* Run the chassis loop, which handles low-level control. * Run the chassis loop, which handles low-level control.
*/ */
Pose delta; Twist velocity;
if(chassis.ChassisLoop(delta)) if(chassis.ChassisLoop(velocity))
{ {
// We do FK regardless of state // We do FK regardless of state
UpdatePose(delta); UpdatePose(velocity);
chassis.SetMotorEfforts(220,-220); chassis.SetMotorEfforts(220,-220);
/** /**

View file

@ -38,7 +38,7 @@ protected:
void EnterIdleState(void); void EnterIdleState(void);
// /* Navigation methods.*/ // /* Navigation methods.*/
void UpdatePose(const Pose& u); void UpdatePose(const Twist& u);
void SetDestination(const Pose& destination); void SetDestination(const Pose& destination);
void DriveToPoint(void); void DriveToPoint(void);
bool CheckReachedDestination(void); bool CheckReachedDestination(void);