From 5bfc5751ab46cddfc8e236a96fb5cb91d5f6f110 Mon Sep 17 00:00:00 2001 From: R11G Date: Wed, 12 Oct 2022 14:45:51 -0400 Subject: [PATCH] Added reverse motor using negative port param. Changed Motor constructors' port param from uint8_t to int8_t --- include/pros/motors.hpp | 10 +++++----- src/devices/vdml_motors.cpp | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/include/pros/motors.hpp b/include/pros/motors.hpp index 5c41474ec..77abcc84f 100644 --- a/include/pros/motors.hpp +++ b/include/pros/motors.hpp @@ -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 **/ diff --git a/src/devices/vdml_motors.cpp b/src/devices/vdml_motors.cpp index 1f4382d3a..0743da5ab 100644 --- a/src/devices/vdml_motors.cpp +++ b/src/devices/vdml_motors.cpp @@ -10,6 +10,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include #include #include "kapi.h" @@ -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);