Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn Only Braking Method #96

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/subsystems/odometry/odometry_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class OdometryBase {
* Gets the current position and rotation
* @return the position that the odometry believes the robot is at
*/
pose_t get_position(void);
virtual pose_t get_position(void);

/**
* Sets the current position of the robot
Expand Down
5 changes: 4 additions & 1 deletion include/subsystems/odometry/odometry_nwheel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../core/include/subsystems/custom_encoder.h"
#include "../core/include/subsystems/odometry/odometry_base.h"
#include "../core/include/utils/math_util.h"
#include <iostream>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed i dont think

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


/**
* OdometryNWheel
Expand Down Expand Up @@ -116,6 +117,8 @@ template <int WHEELS> class OdometryNWheel : public OdometryBase {

pose_t updated_pos = calculate_new_pos(radian_deltas, current_pos);

// std::cout << "x: " << updated_pos.x << " y: " << updated_pos.y << " rot: " << updated_pos.rot << std::endl;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this print?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


// if we do not pass in an IMU we use the wheels for rotation
if (imu != nullptr) {
angle = 0;
Expand Down Expand Up @@ -186,7 +189,7 @@ template <int WHEELS> class OdometryNWheel : public OdometryBase {
* Gets the current position and rotation
* @return the position that the odometry believes the robot is at
*/
pose_t get_position(void) {
pose_t get_position(void) override {
pose_t unwrapped_radians = OdometryBase::get_position();
pose_t wrapped_degrees = {unwrapped_radians.x, unwrapped_radians.y, wrap_angle_deg((unwrapped_radians.rot / (2 * M_PI)) * 360)};
return wrapped_degrees;
Expand Down
1 change: 1 addition & 0 deletions include/subsystems/tank_drive.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class TankDrive {
None, ///< just send 0 volts to the motors
ZeroVelocity, ///< try to bring the robot to rest. But don't try to hold position
Smart, ///< bring the robot to rest and once it's stopped, try to hold that position
TurnOnly,
};
/**
* Create the TankDrive object
Expand Down
13 changes: 13 additions & 0 deletions src/subsystems/tank_drive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,24 @@ void TankDrive::drive_tank_raw(double left_norm, double right_norm) {
*/
bool captured_position = false;
bool was_breaking = false;

void TankDrive::drive_tank(double left, double right, int power, BrakeType bt) {

left = modify_inputs(left, power);
right = modify_inputs(right, power);
double brake_threshold = 0.05;
if(((left_motors.velocity(vex::velocityUnits::rpm) * (right_motors.velocity(vex::velocityUnits::rpm))) < 0)){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be (if bt == TurnOnly && (left.vel * right.vel < 0)) that way it's turned off when not specified?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, should be fixed now

bt = BrakeType::ZeroVelocity;
}
else{
bt = BrakeType::None;
}
if(bt == BrakeType::None){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove these prints before merging?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

printf("bt None \n");
}
else if(bt == BrakeType::ZeroVelocity){
printf("bt zerovel \n");
}
bool should_brake = (bt != BrakeType::None) && fabs(left) < brake_threshold && fabs(right) < brake_threshold;

if (!should_brake) {
Expand Down