Skip to content

Commit

Permalink
Merge pull request #23 from ad101-lab/ad-motor-hold
Browse files Browse the repository at this point in the history
Motor hold
  • Loading branch information
alexDickhans authored Oct 21, 2021
2 parents 24f276b + 588c62a commit 3e7574d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/driver/motorButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace Pronounce

void MotorButton::updateMotor() {
if (!enabled) {
this->motor->move(0.0);
this->motor->move_velocity(0.0);
return;
}

Expand All @@ -54,7 +54,7 @@ namespace Pronounce
this->motor->move(negativeAuthority);
}
else {
this->motor->move(neutralAuthority);
this->motor->move_velocity(neutralAuthority);
}
break;
case POSITIVE:
Expand All @@ -67,14 +67,14 @@ namespace Pronounce
this->motor->move(positiveAuthority);
}
else {
this->motor->move(neutralAuthority);
this->motor->move_velocity(neutralAuthority);
}
break;
case NEUTRAL:
default:
if (goToImmediately)
return;
this->motor->move(neutralAuthority);
this->motor->move_velocity(neutralAuthority);
break;
}

Expand Down
35 changes: 21 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool preDriverTasksDone = false;

/**
* @brief Runs during auton period before auton
*
*
*/
int preAutonRun() {
// Drivetrain
Expand All @@ -69,13 +69,13 @@ int leftAwpRight() {
startingPosition->setTheta(90);

tankDrivetrain.setStartingPosition(startingPosition);

// Move to left goal
tankDrivetrain.setTargetPosition(new Position(35, 11.5));
tankDrivetrain.waitForStop();

// Pick up left goal
frontFlipperMotor.move_absolute(20*6, 200);
frontFlipperMotor.move_absolute(20 * 6, 200);

// Move to line
tankDrivetrain.setTargetPosition(new Position(33.5, 33.5, -1));
Expand Down Expand Up @@ -107,7 +107,7 @@ int leftAwpRight() {
tankDrivetrain.waitForStop();

// Pick up goal
frontFlipperMotor.move_absolute(20*6, 200);
frontFlipperMotor.move_absolute(20 * 6, 200);

// Move off AWP
tankDrivetrain.setTargetPosition(new Position(114, 23.2, -1));
Expand All @@ -124,7 +124,7 @@ int leftAwpRight() {

/**
* @brief Right Awp Left
*
*
* @return Status - needed for AutonSelector
*/
int rightAwpLeft() {
Expand Down Expand Up @@ -166,7 +166,7 @@ int rightStealRight() {

/**
* @brief Test auton
*
*
* @return 0
*/
int testAuton() {
Expand Down Expand Up @@ -293,7 +293,7 @@ void initSelector() {
(char*)"" };

autonomousSel = new autonSelector(btnm_map, lv_scr_act());

// Set pre and post run
autonomousSel->setPreRun(nullAutonFunc);
autonomousSel->setPostAuton(postAuton);
Expand Down Expand Up @@ -321,7 +321,7 @@ void initLogger() {

void initDrivetrain() {
pros::Task tankDriveTask(tankDriveThread);

tankDrivetrain.getTankOdom()->getLeftPivot()->setTuningFactor(1.0);
tankDrivetrain.getTankOdom()->getRightPivot()->setTuningFactor(1.0);

Expand All @@ -345,7 +345,7 @@ double filterAxis(pros::Controller controller, pros::controller_analog_e_t contr

// Apply quadratic function
// f(x) = controllerFilter / 127.0 ^ 3 * 127.0
double quadraticFilter = pow(controllerFilter / 127.0, 3) * 127.0;
double quadraticFilter = pow(controllerFilter / 127.0, 3) * 200;

// Return solution
return quadraticFilter;
Expand Down Expand Up @@ -426,7 +426,7 @@ void autonomous() {
* Runs during operator/teleop control
*/
void opcontrol() {

if (!preDriverTasksDone) {
preDriver();
}
Expand All @@ -452,10 +452,17 @@ void opcontrol() {
int rightWheelMag = filterAxis(master, ANALOG_RIGHT_Y);

// Send variables to motors
frontLeftMotor.move(leftWheelMag);
backLeftMotor.move(leftWheelMag);
frontRightMotor.move(rightWheelMag);
backRightMotor.move(rightWheelMag);
frontLeftMotor.move_velocity(leftWheelMag);
backLeftMotor.move_velocity(leftWheelMag);
frontRightMotor.move_velocity(rightWheelMag);
backRightMotor.move_velocity(rightWheelMag);


if (leftWheelMag == 0) {
frontLeftMotor.move_velocity(0.0);
backLeftMotor.move_velocity(0.0);
}


// Used to test odom on the robot currently
if (driveOdomEnabled) {
Expand Down

0 comments on commit 3e7574d

Please sign in to comment.