Skip to content

Commit

Permalink
Merge pull request #443 from purduesigbots/feature/reverse-motors
Browse files Browse the repository at this point in the history
✨ Add Reverseable Motors to Default API
  • Loading branch information
Richard-Stump authored Oct 14, 2022
2 parents 0cb363e + 084fde2 commit 4e6f841
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
10 changes: 5 additions & 5 deletions include/pros/motors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ class Motor {
* \param encoder_units
* The motor's encoder units
*/
explicit Motor(const std::uint8_t port, const motor_gearset_e_t gearset, const bool reverse,
explicit Motor(const std::int8_t port, const motor_gearset_e_t gearset, const bool reverse,
const motor_encoder_units_e_t encoder_units);

explicit Motor(const std::uint8_t port, const motor_gearset_e_t gearset, const bool reverse);
explicit Motor(const std::int8_t port, const motor_gearset_e_t gearset, const bool reverse);

explicit Motor(const std::uint8_t port, const motor_gearset_e_t gearset);
explicit Motor(const std::int8_t port, const motor_gearset_e_t gearset);

explicit Motor(const std::uint8_t port, const bool reverse);
explicit Motor(const std::int8_t port, const bool reverse);

explicit Motor(const std::uint8_t port);
explicit Motor(const std::int8_t port);

/****************************************************************************/
/** Motor movement functions **/
Expand Down
27 changes: 19 additions & 8 deletions src/devices/vdml_motors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <stdint.h>
#include <vector>

#include "kapi.h"
Expand Down Expand Up @@ -77,28 +78,39 @@
namespace pros {
using namespace pros::c;

Motor::Motor(const std::uint8_t port, const motor_gearset_e_t gearset, const bool reverse,
Motor::Motor(const std::int8_t port, const motor_gearset_e_t gearset, const bool reverse,
const motor_encoder_units_e_t encoder_units)
: _port(port) {
: _port(abs(port)) {
set_gearing(gearset);
set_reversed(reverse);
set_encoder_units(encoder_units);
if (port < 0)
set_reversed(true);
}

Motor::Motor(const std::uint8_t port, const motor_gearset_e_t gearset, const bool reverse) : _port(port) {
Motor::Motor(const std::int8_t port, const motor_gearset_e_t gearset, const bool reverse) : _port(abs(port)) {
set_gearing(gearset);
set_reversed(reverse);
if (port < 0)
set_reversed(true);
}

Motor::Motor(const std::uint8_t port, const motor_gearset_e_t gearset) : _port(port) {
Motor::Motor(const std::int8_t port, const motor_gearset_e_t gearset) : _port(abs(port)) {
set_gearing(gearset);
if (port < 0)
set_reversed(true);
}

Motor::Motor(const std::uint8_t port, const bool reverse) : _port(port) {
Motor::Motor(const std::int8_t port, const bool reverse) : _port(abs(port)) {
set_reversed(reverse);
if (port < 0)
set_reversed(true);
}

Motor::Motor(const std::uint8_t port) : _port(port) {}
Motor::Motor(const std::int8_t port) : _port(abs(port)) {
if (port < 0)
set_reversed(true);
}

std::int32_t Motor::operator=(std::int32_t voltage) const {
return motor_move(_port, voltage);
Expand Down Expand Up @@ -327,8 +339,7 @@ Motor_Group::Motor_Group(const std::initializer_list<Motor> motors)
Motor_Group::Motor_Group(const std::vector<std::int8_t> motor_ports)
: _motor_group_mutex(pros::Mutex()), _motor_count(motor_ports.size()) {
for (std::uint8_t i = 0; i < _motor_count; ++i) {
_motors.push_back(Motor(std::abs(motor_ports[i]), (motor_ports[i] < 0)));
// std::cout << "Motor " << motor_ports[i] << "Reversed: " << (bool)(motor_ports[i] < 0) << std::endl;
_motors.push_back(Motor(motor_ports[i]));
}
}

Expand Down

0 comments on commit 4e6f841

Please sign in to comment.