Skip to content

Commit

Permalink
Converts to encoder ticks for setLimitSwitchLimits
Browse files Browse the repository at this point in the history
  • Loading branch information
Geeoon committed Nov 2, 2024
1 parent 76d5d47 commit 1991da1
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/TunePID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ bool initMotor(motorid_t motor) {
robot::encparams_t enc_params = robot::encMotors.at(motor);
can::motor::initEncoder(serial, enc_params.isInverted, true, enc_params.ppjr,
robot::TELEM_PERIOD);
can::motor::setLimitSwitchLimits(serial, enc_params.limitSwitchLow,
enc_params.limitSwitchHigh);

auto mDegToPulses = [&](int32_t mdeg) {
return static_cast<int32_t>(static_cast<double>(mdeg) / 360000.0 *
enc_params.ppjr);
};
can::motor::setLimitSwitchLimits(serial, mDegToPulses(enc_params.limitSwitchLow),
mDegToPulses(enc_params.limitSwitchHigh));
} else {
std::cerr << "The given motor is not a pot or enc motor!\n";
return false;
Expand Down Expand Up @@ -133,13 +138,14 @@ int main(int argc, char** argv) {
std::getline(std::cin, str);
int d_coeff = std::stoi(str);

can::motor::setMotorMode(serial, can::motor::motormode_t::pid);
can::motor::setMotorPIDConstants(serial, p_coeff, i_coeff, d_coeff);

// TODO: set the motor pid max power
can::motor::setMotorMode(serial, can::motor::motormode_t::pid);
double period = 8.0;

// TODO: remove and replace with a loop
std::this_thread::sleep_for(300ms); // wait for encoder position data to arrive
int32_t starting_angle = can::motor::getMotorPosition(serial);
int32_t starting_angle = can::motor::getMotorPosition(serial).getData();
int32_t angle_target = starting_angle;
double acc_error = 0.0;
int total_steps = 0;
Expand Down

0 comments on commit 1991da1

Please sign in to comment.