Compare commits

..

No commits in common. "7bcd6e5f647cc3d7bbcf5ab8d0f941075754649d" and "f8d0b85defe20a819fa3b630db82f10e117573d5" have entirely different histories.

3 changed files with 15 additions and 20 deletions

View file

@ -1,15 +0,0 @@
#pragma once
const float ACCEL_LIMIT = 4.0; // cm/s/s
const float VEL_LIMIT = 16.0; // cm/s
const float BACKLASH_RIGHT = 0.0; // degrees
const float BACKLASH_LEFT = 0.0; // degrees
const float WHEEL_DIAMETER = 6.37; // cm
const float WHEEL_TO_WHEEL = 0.0; // cm
const float FORWARD_DISTANCE = 100.0; // cm
// centimeters per second to rpm
const float CMS_RPM = 60.0 / (PI*WHEEL_DIAMETER);
const float TURN_AMOUNT = 180.0; // degrees
const float RETURN_DISTANCE = 100.0; // cm

View file

@ -3,7 +3,17 @@
#include <smartmotor.h> #include <smartmotor.h>
#include <SMC_gains.h> #include <SMC_gains.h>
#include "trapezoidal.h" #include "trapezoidal.h"
#include "constants.h"
const float ACCEL_LIMIT = 4.0; // cm/s/s
const float VEL_LIMIT = 16.0; // cm/s
const float BACKLASH_RIGHT = 0.0; // degrees
const float BACKLASH_LEFT = 0.0; // degrees
const float WHEEL_DIAMETER = 6.37; // cm
const float WHEEL_TO_WHEEL = 0.0; // cm
const float FORWARD_DISTANCE = 100.0; // cm
const float TURN_AMOUNT = 180.0; // degrees
const float RETURN_DISTANCE = 100.0; // cm
SmartMotor left_motor(0x0A); SmartMotor left_motor(0x0A);
SmartMotor right_motor(0x0B); SmartMotor right_motor(0x0B);
@ -53,7 +63,7 @@ void setup() {
} }
void loop() { void loop() {
float time = (float)millis() / 1000.0 - phase_start; float time = (float)millis() / 1000.0;
switch (robot_state) { switch (robot_state) {
case FORWARD: case FORWARD:
setpoint = trapezoidal_planner(&forward, time); setpoint = trapezoidal_planner(&forward, time);
@ -66,7 +76,7 @@ void loop() {
left_motor.write_rpm(setpoint.velocity * CMS_RPM); left_motor.write_rpm(velocity);
//right_motor.write_rpm(robot_state == TURN ? velocity : -velocity); //right_motor.write_rpm(robot_state == TURN ? velocity : -velocity);
delay(20); delay(20);

View file

@ -8,7 +8,7 @@ struct Setpoint trapezoidal_planner(struct Trapezoidal* trapezoidal, float time)
struct Setpoint setpoint = {0.0, 0.0}; struct Setpoint setpoint = {0.0, 0.0};
float time_accelerating = max_vel / max_acc; float time_accelerating = max_acc / max_vel;
float distance_while_accelerating = 0.5 * max_acc * time_accelerating * time_accelerating; float distance_while_accelerating = 0.5 * max_acc * time_accelerating * time_accelerating;
if (2.0 * distance_while_accelerating > dist) { if (2.0 * distance_while_accelerating > dist) {
@ -48,7 +48,7 @@ struct Setpoint trapezoidal_planner(struct Trapezoidal* trapezoidal, float time)
} else if (time < total_time) { } else if (time < total_time) {
// slowing down // slowing down
float time_decay = time - (time_accelerating + cruise_time); float time_decay = time - (time_accelerating + cruise_time);
setpoint.velocity = max_vel - (time_decay * max_acc); setpoint.velocity = max_vel - time_decay * max_acc;
setpoint.position = distance_while_accelerating + cruise_distance setpoint.position = distance_while_accelerating + cruise_distance
+ (max_vel * time_decay) + (max_vel * time_decay)
- 0.5 * max_acc * time_decay * time_decay; - 0.5 * max_acc * time_decay * time_decay;