Compare commits
2 commits
09bce37a9a
...
511d5fc281
| Author | SHA1 | Date | |
|---|---|---|---|
| 511d5fc281 | |||
| aba495d3f1 |
5 changed files with 26 additions and 24 deletions
|
|
@ -95,7 +95,7 @@ void Chassis::InititalizeChassis(void)
|
||||||
/**
|
/**
|
||||||
* The main Chassis loop.
|
* The main Chassis loop.
|
||||||
*/
|
*/
|
||||||
bool Chassis::ChassisLoop(Twist& velocity)
|
bool Chassis::ChassisLoop(Pose& delta)
|
||||||
{
|
{
|
||||||
bool retVal = false;
|
bool retVal = false;
|
||||||
|
|
||||||
|
|
@ -109,7 +109,7 @@ bool Chassis::ChassisLoop(Twist& velocity)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Update the wheel velocity so it gets back to Robot. */
|
/* Update the wheel velocity so it gets back to Robot. */
|
||||||
velocity = CalcOdomFromWheelMotion();
|
delta = CalcOdomFromWheelMotion();
|
||||||
|
|
||||||
loopFlag = 0;
|
loopFlag = 0;
|
||||||
|
|
||||||
|
|
@ -137,22 +137,22 @@ void Chassis::SetMotorEfforts(int16_t left, int16_t right)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Twist Chassis::CalcOdomFromWheelMotion(void)
|
Pose Chassis::CalcOdomFromWheelMotion(void)
|
||||||
{
|
{
|
||||||
Twist delta;
|
Pose delta;
|
||||||
|
|
||||||
float leftDelta = (float) leftMotor.speed * (float) CONTROL_LOOP_PERIOD_MS / 1000.0;
|
float leftDelta = (float) leftMotor.speed
|
||||||
float rightDelta = (float) rightMotor.speed * (float) CONTROL_LOOP_PERIOD_MS / 1000.0;
|
/ LEFT_TICKS_PER_CM;
|
||||||
|
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)
|
||||||
/ LEFT_TICKS_PER_CM
|
/ (2.0 * ROBOT_RADIUS);
|
||||||
/ (3.14 * ROBOT_RADIUS);
|
|
||||||
|
|
||||||
delta.u = distance;
|
delta.x = distance;
|
||||||
delta.omega = deltaHeading;
|
delta.theta = deltaHeading;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -163,8 +163,8 @@ Twist Chassis::CalcOdomFromWheelMotion(void)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __NAV_DEBUG__
|
#ifdef __NAV_DEBUG__
|
||||||
TeleplotPrint("u", delta.u);
|
TeleplotPrint("u", delta.x);
|
||||||
TeleplotPrint("omega", delta.omega);
|
TeleplotPrint("omega", delta.theta);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return delta;
|
return delta;
|
||||||
|
|
|
||||||
|
|
@ -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(Twist&);
|
bool ChassisLoop(Pose&);
|
||||||
|
|
||||||
/* Needed for managing motors. */
|
/* Needed for managing motors. */
|
||||||
static void Timer4OverflowISRHandler(void);
|
static void Timer4OverflowISRHandler(void);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Twist CalcOdomFromWheelMotion(void);
|
Pose CalcOdomFromWheelMotion(void);
|
||||||
|
|
||||||
|
|
||||||
void SetMotorEfforts(int16_t, int16_t);
|
void SetMotorEfforts(int16_t, int16_t);
|
||||||
|
|
|
||||||
|
|
@ -4,21 +4,23 @@
|
||||||
|
|
||||||
#include "robot.h"
|
#include "robot.h"
|
||||||
|
|
||||||
void Robot::UpdatePose(const Twist& twist)
|
void Robot::UpdatePose(const Pose& delta)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* TODO: Add your FK algorithm to update currPose here.
|
* TODO: Add your FK algorithm to update currPose here.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
float transitHeading = currPose.theta + (twist.omega * 0.5);
|
float transitHeading = currPose.theta + (delta.theta * 0.5);
|
||||||
|
|
||||||
currPose.x += twist.u * cos(transitHeading);
|
currPose.x += delta.x * cos(transitHeading);
|
||||||
currPose.y += twist.u * sin(transitHeading);
|
currPose.y += delta.x * 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);
|
TeleplotPrint("theta", currPose.theta * 180.0 / PI);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
*/
|
*/
|
||||||
Twist velocity;
|
Pose delta;
|
||||||
if(chassis.ChassisLoop(velocity))
|
if(chassis.ChassisLoop(delta))
|
||||||
{
|
{
|
||||||
// We do FK regardless of state
|
// We do FK regardless of state
|
||||||
UpdatePose(velocity);
|
UpdatePose(delta);
|
||||||
chassis.SetMotorEfforts(220,-220);
|
chassis.SetMotorEfforts(220,-220);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ protected:
|
||||||
void EnterIdleState(void);
|
void EnterIdleState(void);
|
||||||
|
|
||||||
// /* Navigation methods.*/
|
// /* Navigation methods.*/
|
||||||
void UpdatePose(const Twist& u);
|
void UpdatePose(const Pose& u);
|
||||||
void SetDestination(const Pose& destination);
|
void SetDestination(const Pose& destination);
|
||||||
void DriveToPoint(void);
|
void DriveToPoint(void);
|
||||||
bool CheckReachedDestination(void);
|
bool CheckReachedDestination(void);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue