Skip to content

Commit

Permalink
✨ Added get_temperature to motor groups. (#540)
Browse files Browse the repository at this point in the history
* Added get_temperature

* Fix compl issue

* Fix compl again

* notha one this time (for reals)
  • Loading branch information
WillXuCodes authored Mar 8, 2023
1 parent a541ce2 commit 908c972
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/pros/motors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,19 @@ class Motor_Group {
* E_MOTOR_ENCODER_INVALID if the operation failed.
*/
std::vector<pros::motor_encoder_units_e_t> get_encoder_units(void);

/**
* Gets the encoder units that were set for each motor.
*
* This function uses the following values of errno when an error state is
* reached:
* ENODEV - The port cannot be configured as a motor
* EACCESS - The Motor group mutex can't be taken or given
*
* \return The vector filled with motors' temperature in degrees Celsius or PROS_ERR_F if the
* operation failed, setting errno.
*/
virtual std::vector<double> get_temperatures(void);

private:
std::vector<Motor> _motors;
Expand Down
10 changes: 10 additions & 0 deletions src/devices/vdml_motors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,16 @@ std::int32_t Motor_Group::set_reversed(const bool reversed) {
return out;
}

std::vector<double> Motor_Group::get_temperatures(void) {
std::vector<double> out;
claim_mg_mutex_vector(PROS_ERR_F);
for (Motor motor : _motors) {
out.push_back(motor.get_temperature());
}
give_mg_mutex_vector(PROS_ERR_F);
return out;
}

std::int32_t Motor_Group::set_voltage_limit(const std::int32_t limit) {
claim_mg_mutex(PROS_ERR);
std::int32_t out = PROS_SUCCESS;
Expand Down

0 comments on commit 908c972

Please sign in to comment.