Initial commit - test serial

This commit is contained in:
Cole A. Deck
2024-03-24 22:20:00 -05:00
commit a4b1c1b7ed
273 changed files with 43716 additions and 0 deletions

View File

@ -0,0 +1,109 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "api.h"
#include "okapi/api/control/controllerInput.hpp"
#include "okapi/api/device/rotarysensor/continuousRotarySensor.hpp"
namespace okapi {
enum class IMUAxes {
z, ///< Yaw Axis
y, ///< Pitch Axis
x ///< Roll Axis
};
class IMU : public ContinuousRotarySensor {
public:
/**
* An inertial sensor on the given port. The IMU returns an angle about the selected axis in
* degrees.
*
* ```cpp
* auto imuZ = IMU(1);
* auto imuX = IMU(1, IMUAxes::x);
* ```
*
* @param iport The port number in the range ``[1, 21]``.
* @param iaxis The axis of the inertial sensor to measure, default `IMUAxes::z`.
*/
IMU(std::uint8_t iport, IMUAxes iaxis = IMUAxes::z);
/**
* Get the current rotation about the configured axis.
*
* @return The current sensor value or ``PROS_ERR``.
*/
double get() const override;
/**
* Get the current sensor value remapped into the target range (``[-1800, 1800]`` by default).
*
* @param iupperBound The upper bound of the range.
* @param ilowerBound The lower bound of the range.
* @return The remapped sensor value.
*/
double getRemapped(double iupperBound = 1800, double ilowerBound = -1800) const;
/**
* Get the current acceleration along the configured axis.
*
* @return The current sensor value or ``PROS_ERR``.
*/
double getAcceleration() const;
/**
* Reset the rotation value to zero.
*
* @return ``1`` or ``PROS_ERR``.
*/
std::int32_t reset() override;
/**
* Resets rotation value to desired value
* For example, ``reset(0)`` will reset the sensor to zero.
* But ``reset(90)`` will reset the sensor to 90 degrees.
*
* @param inewAngle desired reset value
* @return ``1`` or ``PROS_ERR``.
*/
std::int32_t reset(double inewAngle);
/**
* Calibrate the IMU. Resets the rotation value to zero. Calibration is expected to take two
* seconds, but is bounded to five seconds.
*
* @return ``1`` or ``PROS_ERR``.
*/
std::int32_t calibrate();
/**
* Get the sensor value for use in a control loop. This method might be automatically called in
* another thread by the controller.
*
* @return The current sensor value or ``PROS_ERR``.
*/
double controllerGet() override;
/**
* @return Whether the IMU is calibrating.
*/
bool isCalibrating() const;
protected:
std::uint8_t port;
IMUAxes axis;
double offset = 0;
/**
* Get the current rotation about the configured axis. The internal offset is not accounted for
* or modified. This just reads from the sensor.
*
* @return The current sensor value or ``PROS_ERR``.
*/
double readAngle() const;
};
} // namespace okapi

View File

@ -0,0 +1,73 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "api.h"
#include "okapi/api/device/rotarysensor/continuousRotarySensor.hpp"
namespace okapi {
class ADIEncoder : public ContinuousRotarySensor {
public:
/**
* An encoder in an ADI port.
*
* ```cpp
* auto enc = ADIEncoder('A', 'B', false);
* auto reversedEnc = ADIEncoder('A', 'B', true);
* ```
*
* @param iportTop The "top" wire from the encoder with the removable cover side up. This must be
* in port ``1``, ``3``, ``5``, or ``7`` (``A``, ``C``, ``E``, or ``G``).
* @param iportBottom The "bottom" wire from the encoder. This must be in port ``2``, ``4``,
* ``6``, or ``8`` (``B``, ``D``, ``F``, or ``H``).
* @param ireversed Whether the encoder is reversed.
*/
ADIEncoder(std::uint8_t iportTop, std::uint8_t iportBottom, bool ireversed = false);
/**
* An encoder in an ADI port.
*
* ```cpp
* auto enc = ADIEncoder({1, 'A', 'B'}, false);
* auto reversedEnc = ADIEncoder({1, 'A', 'B'}, true);
* ```
*
* @param iports The ports the encoder is plugged in to in the order ``{smart port, top port,
* bottom port}``. The smart port is the smart port number (``[1, 21]``). The top port is the
* "top" wire from the encoder with the removable cover side up. This must be in port ``1``,
* ``3``, ``5``, or
* ``7`` (``A``, ``C``, ``E``, or ``G``). The bottom port is the "bottom" wire from the encoder.
* This must be in port ``2``, ``4``, ``6``, or ``8`` (``B``, ``D``, ``F``, or ``H``).
* @param ireversed Whether the encoder is reversed.
*/
ADIEncoder(std::tuple<std::uint8_t, std::uint8_t, std::uint8_t> iports, bool ireversed = false);
/**
* Get the current sensor value.
*
* @return the current sensor value, or `PROS_ERR` on a failure.
*/
virtual double get() const override;
/**
* Reset the sensor to zero.
*
* @return `1` on success, `PROS_ERR` on fail
*/
virtual std::int32_t reset() override;
/**
* Get the sensor value for use in a control loop. This method might be automatically called in
* another thread by the controller.
*
* @return the current sensor value, or `PROS_ERR` on a failure.
*/
virtual double controllerGet() override;
protected:
pros::c::ext_adi_encoder_t enc;
};
} // namespace okapi

View File

@ -0,0 +1,82 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "api.h"
#include "okapi/api/control/controllerInput.hpp"
#include "okapi/api/device/rotarysensor/continuousRotarySensor.hpp"
namespace okapi {
class ADIGyro : public ContinuousRotarySensor {
public:
/**
* A gyroscope on the given ADI port. If the port has not previously been configured as a gyro,
* then the constructor will block for 1 second for calibration. The gyro measures in tenths of a
* degree, so there are ``3600`` measurement points per revolution.
*
* ```cpp
* auto gyro = ADIGyro('A');
* ```
*
* @param iport The ADI port number (``[1, 8]``, ``[a, h]``, ``[A, H]``).
* @param imultiplier A value multiplied by the gyro heading value.
*/
ADIGyro(std::uint8_t iport, double imultiplier = 1);
/**
* A gyroscope on the given ADI port. If the port has not previously been configured as a gyro,
* then the constructor will block for 1 second for calibration. The gyro measures in tenths of a
* degree, so there are 3600 measurement points per revolution.
*
* ```cpp
* auto gyro = ADIGyro({1, 'A'}, 1);
* ```
*
* Note to developers: Keep the default value on imultiplier so that users get an error if they do
* ADIGyro({1, 'A'}). Without it, this calls the non-ext-adi constructor.
*
* @param iports The ports the gyro is plugged in to in the order ``{smart port, gyro port}``. The
* smart port is the smart port number (``[1, 21]``). The gyro port is the ADI port number (``[1,
* 8]``, ``[a, h]``, ``[A, H]``).
* @param imultiplier A value multiplied by the gyro heading value.
*/
ADIGyro(std::pair<std::uint8_t, std::uint8_t> iports, double imultiplier = 1);
/**
* Get the current sensor value.
*
* @return the current sensor value, or ``PROS_ERR`` on a failure.
*/
double get() const override;
/**
* Get the current sensor value remapped into the target range (``[-1800, 1800]`` by default).
*
* @param iupperBound the upper bound of the range.
* @param ilowerBound the lower bound of the range.
* @return the remapped sensor value.
*/
double getRemapped(double iupperBound = 1800, double ilowerBound = -1800) const;
/**
* Reset the sensor to zero.
*
* @return `1` on success, `PROS_ERR` on fail
*/
std::int32_t reset() override;
/**
* Get the sensor value for use in a control loop. This method might be automatically called in
* another thread by the controller.
*
* @return the current sensor value, or ``PROS_ERR`` on a failure.
*/
double controllerGet() override;
protected:
pros::c::ext_adi_gyro_t gyro;
};
} // namespace okapi

View File

@ -0,0 +1,56 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "api.h"
#include "okapi/api/device/rotarysensor/continuousRotarySensor.hpp"
#include "okapi/impl/device/motor/motor.hpp"
namespace okapi {
class IntegratedEncoder : public ContinuousRotarySensor {
public:
/**
* Integrated motor encoder. Uses the encoder inside the V5 motor.
*
* @param imotor The motor to use the encoder from.
*/
IntegratedEncoder(const okapi::Motor &imotor);
/**
* Integrated motor encoder. Uses the encoder inside the V5 motor.
*
* @param iport The motor's port number in the range [1, 21].
* @param ireversed Whether the encoder is reversed.
*/
IntegratedEncoder(std::int8_t iport, bool ireversed = false);
/**
* Get the current sensor value.
*
* @return the current sensor value, or ``PROS_ERR`` on a failure.
*/
virtual double get() const override;
/**
* Reset the sensor to zero.
*
* @return `1` on success, `PROS_ERR` on fail
*/
virtual std::int32_t reset() override;
/**
* Get the sensor value for use in a control loop. This method might be automatically called in
* another thread by the controller.
*
* @return the current sensor value, or ``PROS_ERR`` on a failure.
*/
virtual double controllerGet() override;
protected:
std::uint8_t port;
std::int8_t reversed{1};
};
} // namespace okapi

View File

@ -0,0 +1,57 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "api.h"
#include "okapi/api/device/rotarysensor/rotarySensor.hpp"
namespace okapi {
class Potentiometer : public RotarySensor {
public:
/**
* A potentiometer in an ADI port.
*
* ```cpp
* auto pot = Potentiometer('A');
* ```
*
* @param iport The ADI port number (``[1, 8]``, ``[a, h]``, ``[A, H]``).
*/
Potentiometer(std::uint8_t iport);
/**
* A potentiometer in an ADI port.
*
* ```cpp
* auto pot = Potentiometer({1, 'A'});
* ```
*
* @param iports The ports the potentiometer is plugged in to in the order ``{smart port,
* potentiometer port}``. The smart port is the smart port number (``[1, 21]``). The potentiometer
* port is the ADI port number (``[1, 8]``, ``[a, h]``, ``[A, H]``).
*/
Potentiometer(std::pair<std::uint8_t, std::uint8_t> iports);
/**
* Get the current sensor value.
*
* @return the current sensor value, or ``PROS_ERR`` on a failure.
*/
virtual double get() const override;
/**
* Get the sensor value for use in a control loop. This method might be automatically called in
* another thread by the controller.
*
* @return the current sensor value, or ``PROS_ERR`` on a failure.
*/
virtual double controllerGet() override;
protected:
std::uint8_t smartPort;
std::uint8_t port;
};
} // namespace okapi

View File

@ -0,0 +1,64 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "api.h"
#include "okapi/api/device/rotarysensor/continuousRotarySensor.hpp"
namespace okapi {
class RotationSensor : public ContinuousRotarySensor {
public:
/**
* A rotation sensor in a V5 port.
*
* ```cpp
* auto r = RotationSensor(1);
* auto reversedR = RotationSensor(1, true);
* ```
*
* @param iport The V5 port the device uses.
* @param ireversed Whether the sensor is reversed. This will set the reversed state in the
* kernel.
*/
RotationSensor(std::uint8_t iport, bool ireversed = false);
/**
* Get the current rotation in degrees.
*
* @return The current rotation in degrees or ``PROS_ERR_F`` if the operation failed, setting
* ``errno``.
*/
double get() const override;
/**
* Reset the sensor to zero.
*
* @return ``1`` if the operation was successful or ``PROS_ERR`` if the operation failed, setting
* ``errno``.
*/
std::int32_t reset() override;
/**
* Get the sensor value for use in a control loop. This method might be automatically called in
* another thread by the controller.
*
* @return The same as [get](@ref okapi::RotationSensor::get).
*/
double controllerGet() override;
/**
* Get the current rotational velocity estimate in degrees per second.
*
* @return The current rotational velocity estimate in degrees per second or ``PROS_ERR_F`` if the
* operation failed, setting ``errno``.
*/
double getVelocity() const;
protected:
std::uint8_t port;
std::int8_t reversed{1};
};
} // namespace okapi