Skip to content

Commit

Permalink
Added reverse motor using negative port param.
Browse files Browse the repository at this point in the history
Changed Motor constructors' port param from uint8_t to int8_t
  • Loading branch information
R11G committed Oct 12, 2022
1 parent 95709d7 commit 5bfc575
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 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
24 changes: 18 additions & 6 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

0 comments on commit 5bfc575

Please sign in to comment.