Skip to content

Commit

Permalink
🐛Motor and motor group bug fixes (#602)
Browse files Browse the repository at this point in the history
* changed emplace_back to push_back, bug fixes

* Move the fixes to motors
  • Loading branch information
noam987 authored Oct 5, 2023
1 parent 696be0f commit 943a943
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 56 deletions.
62 changes: 30 additions & 32 deletions src/devices/vdml_motorgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using namespace pros::c;
#define empty_MotorGroup_check_vector(error, vector) \
if (_ports.size() <= 0) { \
errno = EDOM; \
vector.emplace_back(error); \
vector.push_back(error); \
return vector; \
}

Expand Down Expand Up @@ -137,7 +137,7 @@ std::vector<double> MotorGroup::get_actual_velocity_all(void) const {
empty_MotorGroup_check_vector(PROS_ERR_F, return_vector);

for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_actual_velocity(*it));
return_vector.push_back(motor_get_actual_velocity(*it));
}
return return_vector;
}
Expand All @@ -154,7 +154,7 @@ std::vector<pros::v5::MotorBrake> MotorGroup::get_brake_mode_all(void) const {
empty_MotorGroup_check_vector(pros::v5::MotorBrake::invalid, return_vector);

for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(static_cast<pros::v5::MotorBrake>(motor_get_brake_mode(*it)));
return_vector.push_back(static_cast<pros::v5::MotorBrake>(motor_get_brake_mode(*it)));
}
return return_vector;
}
Expand All @@ -170,7 +170,7 @@ std::vector<std::int32_t> MotorGroup::get_current_draw_all(void) const {
empty_MotorGroup_check_vector(PROS_ERR, return_vector);

for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_current_draw(*it));
return_vector.push_back(motor_get_current_draw(*it));
}
return return_vector;
}
Expand All @@ -187,7 +187,7 @@ std::vector<std::int32_t> MotorGroup::get_current_limit_all(void) const {
empty_MotorGroup_check_vector(PROS_ERR, return_vector);

for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_current_limit(*it));
return_vector.push_back(motor_get_current_limit(*it));
}
return return_vector;
}
Expand All @@ -202,22 +202,26 @@ std::vector<std::int32_t> MotorGroup::is_over_current_all(void) const {
std::vector<std::int32_t> return_vector;
empty_MotorGroup_check_vector(PROS_ERR, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_is_over_current(*it));
return_vector.push_back(motor_is_over_current(*it));
}
return return_vector;
}

std::int32_t MotorGroup::get_direction(const std::uint8_t index) const {
empty_MotorGroup_check(PROS_ERR);
MotorGroup_index_check(PROS_ERR, index);
return motor_get_direction(_ports[index]);
int ret = motor_get_direction(_ports[index]);
ret = _ports[index] >= 0 ? ret : ret * -1;
return ret;
}

std::vector<std::int32_t> MotorGroup::get_direction_all(void) const {
std::vector<std::int32_t> return_vector;
empty_MotorGroup_check_vector(PROS_ERR, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_direction(*it));
int ret = motor_get_direction(*it);
ret = *it >= 0 ? ret : ret * -1;
return_vector.push_back(ret);
}
return return_vector;
}
Expand All @@ -232,7 +236,7 @@ std::vector<double> MotorGroup::get_efficiency_all(void) const {
std::vector<double> return_vector;
empty_MotorGroup_check_vector(PROS_ERR_F, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_efficiency(*it));
return_vector.push_back(motor_get_efficiency(*it));
}
return return_vector;
}
Expand All @@ -247,7 +251,7 @@ std::vector<pros::v5::MotorUnits> MotorGroup::get_encoder_units_all(void) const
std::vector<pros::v5::MotorUnits> return_vector;
empty_MotorGroup_check_vector(pros::v5::MotorUnits::invalid, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(static_cast<pros::v5::MotorUnits>(motor_get_encoder_units(*it)));
return_vector.push_back(static_cast<pros::v5::MotorUnits>(motor_get_encoder_units(*it)));
}
return return_vector;
}
Expand All @@ -262,7 +266,7 @@ std::vector<std::uint32_t> MotorGroup::get_faults_all(void) const {
std::vector<std::uint32_t> return_vector;
empty_MotorGroup_check_vector(PROS_ERR, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_faults(*it));
return_vector.push_back(motor_get_faults(*it));
}
return return_vector;
}
Expand All @@ -277,7 +281,7 @@ std::vector<std::uint32_t> MotorGroup::get_flags_all(void) const {
std::vector<std::uint32_t> return_vector;
empty_MotorGroup_check_vector(PROS_ERR, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_flags(*it));
return_vector.push_back(motor_get_flags(*it));
}
return return_vector;
}
Expand All @@ -292,7 +296,7 @@ std::vector<pros::v5::MotorGears> MotorGroup::get_gearing_all(void) const {
std::vector<pros::v5::MotorGears> return_vector;
empty_MotorGroup_check_vector(pros::v5::MotorGears::invalid, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(static_cast<pros::v5::MotorGears>(motor_get_gearing(*it)));
return_vector.push_back(static_cast<pros::v5::MotorGears>(motor_get_gearing(*it)));
}
return return_vector;
}
Expand All @@ -307,7 +311,7 @@ std::vector<std::int32_t> MotorGroup::get_raw_position_all(std::uint32_t* const
std::vector<std::int32_t> return_vector;
empty_MotorGroup_check_vector(PROS_ERR, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_raw_position(*it, timestamp));
return_vector.push_back(motor_get_raw_position(*it, timestamp));
}
return return_vector;
}
Expand All @@ -322,7 +326,7 @@ std::vector<std::int32_t> MotorGroup::is_over_temp_all(void) const {
std::vector<std::int32_t> return_vector;
empty_MotorGroup_check_vector(PROS_ERR, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_is_over_temp(*it));
return_vector.push_back(motor_is_over_temp(*it));
}
return return_vector;
}
Expand All @@ -337,7 +341,7 @@ std::vector<double> MotorGroup::get_position_all(void) const {
std::vector<double> return_vector;
empty_MotorGroup_check_vector(PROS_ERR_F, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_position(*it));
return_vector.push_back(motor_get_position(*it));
}
return return_vector;
}
Expand All @@ -352,7 +356,7 @@ std::vector<double> MotorGroup::get_power_all(void) const {
std::vector<double> return_vector;
empty_MotorGroup_check_vector(PROS_ERR_F, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_power(*it));
return_vector.push_back(motor_get_power(*it));
}
return return_vector;
}
Expand All @@ -367,7 +371,7 @@ std::vector<std::int32_t> MotorGroup::is_reversed_all(void) const {
std::vector<std::int32_t> return_vector;
empty_MotorGroup_check_vector(PROS_ERR, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_is_reversed(*it));
return_vector.push_back(motor_is_reversed(*it));
}
return return_vector;
}
Expand All @@ -382,7 +386,7 @@ std::vector<double> MotorGroup::get_temperature_all(void) const {
std::vector<double> return_vector;
empty_MotorGroup_check_vector(PROS_ERR_F, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_temperature(*it));
return_vector.push_back(motor_get_temperature(*it));
}
return return_vector;
}
Expand All @@ -397,7 +401,7 @@ std::vector<double> MotorGroup::get_target_position_all(void) const {
std::vector<double> return_vector;
empty_MotorGroup_check_vector(PROS_ERR_F, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_target_position(*it));
return_vector.push_back(motor_get_target_position(*it));
}
return return_vector;
}
Expand All @@ -412,7 +416,7 @@ std::vector<double> MotorGroup::get_torque_all(void) const {
std::vector<double> return_vector;
empty_MotorGroup_check_vector(PROS_ERR_F, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_torque(*it));
return_vector.push_back(motor_get_torque(*it));
}
return return_vector;
}
Expand All @@ -427,7 +431,7 @@ std::vector<std::int32_t> MotorGroup::get_target_velocity_all(void) const {
std::vector<std::int32_t> return_vector;
empty_MotorGroup_check_vector(PROS_ERR, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_target_velocity(*it));
return_vector.push_back(motor_get_target_velocity(*it));
}
return return_vector;
}
Expand All @@ -441,7 +445,7 @@ std::vector<std::int32_t> MotorGroup::get_voltage_all(void) const {
std::vector<std::int32_t> return_vector;
empty_MotorGroup_check_vector(PROS_ERR, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_voltage(*it));
return_vector.push_back(motor_get_voltage(*it));
}
return return_vector;
}
Expand All @@ -456,7 +460,7 @@ std::vector<std::int32_t> MotorGroup::get_voltage_limit_all(void) const {
std::vector<std::int32_t> return_vector;
empty_MotorGroup_check_vector(PROS_ERR, return_vector);
for (auto it = _ports.begin(); it < _ports.end(); it++) {
return_vector.emplace_back(motor_get_voltage_limit(*it));
return_vector.push_back(motor_get_voltage_limit(*it));
}
return return_vector;
}
Expand Down Expand Up @@ -488,9 +492,6 @@ std::int32_t MotorGroup::tare_position_all(void) const {
std::int32_t MotorGroup::set_brake_mode(const pros::motor_brake_mode_e_t mode, const std::uint8_t index) const {
empty_MotorGroup_check(PROS_ERR);
MotorGroup_index_check(PROS_ERR, index);
for (auto it = _ports.begin() + 1; it < _ports.end(); it++) {
motor_set_brake_mode(*it, mode);
}
return motor_set_brake_mode(_ports[index], mode);
}

Expand Down Expand Up @@ -552,10 +553,7 @@ std::int32_t MotorGroup::set_encoder_units(const pros::motor_encoder_units_e_t u
std::int32_t MotorGroup::set_encoder_units(const pros::v5::MotorUnits units, const std::uint8_t index) const {
empty_MotorGroup_check(PROS_ERR);
MotorGroup_index_check(PROS_ERR, index);
for (auto it = _ports.begin() + 1; it < _ports.end(); it++) {
motor_set_encoder_units(*it, static_cast<motor_encoder_units_e_t>(units));
}
return motor_set_encoder_units(_ports[0], static_cast<motor_encoder_units_e_t>(units));
return motor_set_encoder_units(_ports[index], static_cast<motor_encoder_units_e_t>(units));
}

std::int32_t MotorGroup::set_gearing(const motor_gearset_e_t gearset, const std::uint8_t index) const {
Expand Down Expand Up @@ -640,7 +638,7 @@ std::int8_t MotorGroup::size() const {

void MotorGroup::operator+=(MotorGroup& other) {
for (auto it = other._ports.begin(); it < other._ports.end(); it++) {
_ports.emplace_back(*it);
_ports.push_back(*it);
}
}

Expand Down
Loading

0 comments on commit 943a943

Please sign in to comment.