Initial commit - test serial
This commit is contained in:
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* 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 "okapi/api/chassis/controller/chassisController.hpp"
|
||||
#include "okapi/api/control/async/asyncLinearMotionProfileController.hpp"
|
||||
#include "okapi/api/control/async/asyncMotionProfileController.hpp"
|
||||
#include "okapi/api/util/logging.hpp"
|
||||
#include "okapi/impl/device/motor/motor.hpp"
|
||||
#include "okapi/impl/device/motor/motorGroup.hpp"
|
||||
#include "okapi/impl/util/timeUtilFactory.hpp"
|
||||
|
||||
namespace okapi {
|
||||
class AsyncMotionProfileControllerBuilder {
|
||||
public:
|
||||
/**
|
||||
* A builder that creates async motion profile controllers. Use this to build an
|
||||
* AsyncMotionProfileController or an AsyncLinearMotionProfileController.
|
||||
*
|
||||
* @param ilogger The logger this instance will log to.
|
||||
*/
|
||||
explicit AsyncMotionProfileControllerBuilder(
|
||||
const std::shared_ptr<Logger> &ilogger = Logger::getDefaultLogger());
|
||||
|
||||
/**
|
||||
* Sets the output. This must be used with buildLinearMotionProfileController().
|
||||
*
|
||||
* @param ioutput The output.
|
||||
* @param idiameter The diameter of the mechanical part the motor spins.
|
||||
* @param ipair The gearset.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncMotionProfileControllerBuilder &withOutput(const Motor &ioutput,
|
||||
const QLength &idiameter,
|
||||
const AbstractMotor::GearsetRatioPair &ipair);
|
||||
|
||||
/**
|
||||
* Sets the output. This must be used with buildLinearMotionProfileController().
|
||||
*
|
||||
* @param ioutput The output.
|
||||
* @param idiameter The diameter of the mechanical part the motor spins.
|
||||
* @param ipair The gearset.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncMotionProfileControllerBuilder &withOutput(const MotorGroup &ioutput,
|
||||
const QLength &idiameter,
|
||||
const AbstractMotor::GearsetRatioPair &ipair);
|
||||
|
||||
/**
|
||||
* Sets the output. This must be used with buildLinearMotionProfileController().
|
||||
*
|
||||
* @param ioutput The output.
|
||||
* @param idiameter The diameter of the mechanical part the motor spins.
|
||||
* @param ipair The gearset.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncMotionProfileControllerBuilder &
|
||||
withOutput(const std::shared_ptr<ControllerOutput<double>> &ioutput,
|
||||
const QLength &idiameter,
|
||||
const AbstractMotor::GearsetRatioPair &ipair);
|
||||
|
||||
/**
|
||||
* Sets the output. This must be used with buildMotionProfileController().
|
||||
*
|
||||
* @param icontroller The chassis controller to use.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncMotionProfileControllerBuilder &withOutput(ChassisController &icontroller);
|
||||
|
||||
/**
|
||||
* Sets the output. This must be used with buildMotionProfileController().
|
||||
*
|
||||
* @param icontroller The chassis controller to use.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncMotionProfileControllerBuilder &
|
||||
withOutput(const std::shared_ptr<ChassisController> &icontroller);
|
||||
|
||||
/**
|
||||
* Sets the output. This must be used with buildMotionProfileController().
|
||||
*
|
||||
* @param imodel The chassis model to use.
|
||||
* @param iscales The chassis dimensions.
|
||||
* @param ipair The gearset.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncMotionProfileControllerBuilder &withOutput(const std::shared_ptr<ChassisModel> &imodel,
|
||||
const ChassisScales &iscales,
|
||||
const AbstractMotor::GearsetRatioPair &ipair);
|
||||
|
||||
/**
|
||||
* Sets the limits.
|
||||
*
|
||||
* @param ilimits The limits.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncMotionProfileControllerBuilder &withLimits(const PathfinderLimits &ilimits);
|
||||
|
||||
/**
|
||||
* Sets the TimeUtilFactory used when building the controller. The default is the static
|
||||
* TimeUtilFactory.
|
||||
*
|
||||
* @param itimeUtilFactory The TimeUtilFactory.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncMotionProfileControllerBuilder &withTimeUtilFactory(const TimeUtilFactory &itimeUtilFactory);
|
||||
|
||||
/**
|
||||
* Sets the logger.
|
||||
*
|
||||
* @param ilogger The logger.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncMotionProfileControllerBuilder &withLogger(const std::shared_ptr<Logger> &ilogger);
|
||||
|
||||
/**
|
||||
* Parents the internal tasks started by this builder to the current task, meaning they will be
|
||||
* deleted once the current task is deleted. The `initialize` and `competition_initialize` tasks
|
||||
* are never parented to. This is the default behavior.
|
||||
*
|
||||
* Read more about this in the [builders and tasks tutorial]
|
||||
* (docs/tutorials/concepts/builders-and-tasks.md).
|
||||
*
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncMotionProfileControllerBuilder &parentedToCurrentTask();
|
||||
|
||||
/**
|
||||
* Prevents parenting the internal tasks started by this builder to the current task, meaning they
|
||||
* will not be deleted once the current task is deleted. This can cause runaway tasks, but is
|
||||
* sometimes the desired behavior (e.x., if you want to use this builder once in `autonomous` and
|
||||
* then again in `opcontrol`).
|
||||
*
|
||||
* Read more about this in the [builders and tasks tutorial]
|
||||
* (docs/tutorials/concepts/builders-and-tasks.md).
|
||||
*
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncMotionProfileControllerBuilder ¬ParentedToCurrentTask();
|
||||
|
||||
/**
|
||||
* Builds the AsyncLinearMotionProfileController.
|
||||
*
|
||||
* @return A fully built AsyncLinearMotionProfileController.
|
||||
*/
|
||||
std::shared_ptr<AsyncLinearMotionProfileController> buildLinearMotionProfileController();
|
||||
|
||||
/**
|
||||
* Builds the AsyncMotionProfileController.
|
||||
*
|
||||
* @return A fully built AsyncMotionProfileController.
|
||||
*/
|
||||
std::shared_ptr<AsyncMotionProfileController> buildMotionProfileController();
|
||||
|
||||
private:
|
||||
std::shared_ptr<Logger> logger;
|
||||
|
||||
bool hasLimits{false};
|
||||
PathfinderLimits limits;
|
||||
|
||||
bool hasOutput{false};
|
||||
std::shared_ptr<ControllerOutput<double>> output;
|
||||
QLength diameter;
|
||||
|
||||
bool hasModel{false};
|
||||
std::shared_ptr<ChassisModel> model;
|
||||
ChassisScales scales{{1, 1}, imev5GreenTPR};
|
||||
AbstractMotor::GearsetRatioPair pair{AbstractMotor::gearset::invalid};
|
||||
TimeUtilFactory timeUtilFactory = TimeUtilFactory();
|
||||
std::shared_ptr<Logger> controllerLogger = Logger::getDefaultLogger();
|
||||
|
||||
bool isParentedToCurrentTask{true};
|
||||
};
|
||||
} // namespace okapi
|
@ -0,0 +1,190 @@
|
||||
/*
|
||||
* 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 "okapi/api/control/async/asyncPosIntegratedController.hpp"
|
||||
#include "okapi/api/control/async/asyncPosPidController.hpp"
|
||||
#include "okapi/api/control/async/asyncPositionController.hpp"
|
||||
#include "okapi/api/util/logging.hpp"
|
||||
#include "okapi/impl/device/motor/motor.hpp"
|
||||
#include "okapi/impl/device/motor/motorGroup.hpp"
|
||||
#include "okapi/impl/device/rotarysensor/adiEncoder.hpp"
|
||||
#include "okapi/impl/device/rotarysensor/integratedEncoder.hpp"
|
||||
#include "okapi/impl/util/timeUtilFactory.hpp"
|
||||
|
||||
namespace okapi {
|
||||
class AsyncPosControllerBuilder {
|
||||
public:
|
||||
/**
|
||||
* A builder that creates async position controllers. Use this to create an
|
||||
* AsyncPosIntegratedController or an AsyncPosPIDController.
|
||||
*
|
||||
* @param ilogger The logger this instance will log to.
|
||||
*/
|
||||
explicit AsyncPosControllerBuilder(
|
||||
const std::shared_ptr<Logger> &ilogger = Logger::getDefaultLogger());
|
||||
|
||||
/**
|
||||
* Sets the motor.
|
||||
*
|
||||
* @param imotor The motor.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncPosControllerBuilder &withMotor(const Motor &imotor);
|
||||
|
||||
/**
|
||||
* Sets the motor.
|
||||
*
|
||||
* @param imotor The motor.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncPosControllerBuilder &withMotor(const MotorGroup &imotor);
|
||||
|
||||
/**
|
||||
* Sets the motor.
|
||||
*
|
||||
* @param imotor The motor.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncPosControllerBuilder &withMotor(const std::shared_ptr<AbstractMotor> &imotor);
|
||||
|
||||
/**
|
||||
* Sets the sensor. The default sensor is the motor's integrated encoder.
|
||||
*
|
||||
* @param isensor The sensor.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncPosControllerBuilder &withSensor(const ADIEncoder &isensor);
|
||||
|
||||
/**
|
||||
* Sets the sensor. The default sensor is the motor's integrated encoder.
|
||||
*
|
||||
* @param isensor The sensor.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncPosControllerBuilder &withSensor(const IntegratedEncoder &isensor);
|
||||
|
||||
/**
|
||||
* Sets the sensor. The default sensor is the motor's integrated encoder.
|
||||
*
|
||||
* @param isensor The sensor.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncPosControllerBuilder &withSensor(const std::shared_ptr<RotarySensor> &isensor);
|
||||
|
||||
/**
|
||||
* Sets the controller gains, causing the builder to generate an AsyncPosPIDController. This does
|
||||
* not set the integrated control's gains.
|
||||
*
|
||||
* @param igains The gains.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncPosControllerBuilder &withGains(const IterativePosPIDController::Gains &igains);
|
||||
|
||||
/**
|
||||
* Sets the derivative filter which filters the derivative term before it is scaled by kD. The
|
||||
* filter is ignored when using integrated control. The default derivative filter is a
|
||||
* PassthroughFilter.
|
||||
*
|
||||
* @param iderivativeFilter The derivative filter.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncPosControllerBuilder &withDerivativeFilter(std::unique_ptr<Filter> iderivativeFilter);
|
||||
|
||||
/**
|
||||
* Sets the gearset. The default gearset is derived from the motor's.
|
||||
*
|
||||
* @param igearset The gearset.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncPosControllerBuilder &withGearset(const AbstractMotor::GearsetRatioPair &igearset);
|
||||
|
||||
/**
|
||||
* Sets the maximum velocity. The default maximum velocity is derived from the motor's gearset.
|
||||
* This parameter is ignored when using an AsyncPosPIDController.
|
||||
*
|
||||
* @param imaxVelocity The maximum velocity.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncPosControllerBuilder &withMaxVelocity(double imaxVelocity);
|
||||
|
||||
/**
|
||||
* Sets the TimeUtilFactory used when building the controller. The default is the static
|
||||
* TimeUtilFactory.
|
||||
*
|
||||
* @param itimeUtilFactory The TimeUtilFactory.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncPosControllerBuilder &withTimeUtilFactory(const TimeUtilFactory &itimeUtilFactory);
|
||||
|
||||
/**
|
||||
* Sets the logger.
|
||||
*
|
||||
* @param ilogger The logger.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncPosControllerBuilder &withLogger(const std::shared_ptr<Logger> &ilogger);
|
||||
|
||||
/**
|
||||
* Parents the internal tasks started by this builder to the current task, meaning they will be
|
||||
* deleted once the current task is deleted. The `initialize` and `competition_initialize` tasks
|
||||
* are never parented to. This is the default behavior.
|
||||
*
|
||||
* Read more about this in the [builders and tasks tutorial]
|
||||
* (docs/tutorials/concepts/builders-and-tasks.md).
|
||||
*
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncPosControllerBuilder &parentedToCurrentTask();
|
||||
|
||||
/**
|
||||
* Prevents parenting the internal tasks started by this builder to the current task, meaning they
|
||||
* will not be deleted once the current task is deleted. This can cause runaway tasks, but is
|
||||
* sometimes the desired behavior (e.x., if you want to use this builder once in `autonomous` and
|
||||
* then again in `opcontrol`).
|
||||
*
|
||||
* Read more about this in the [builders and tasks tutorial]
|
||||
* (docs/tutorials/concepts/builders-and-tasks.md).
|
||||
*
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncPosControllerBuilder ¬ParentedToCurrentTask();
|
||||
|
||||
/**
|
||||
* Builds the AsyncPositionController. Throws a std::runtime_exception is no motors were set.
|
||||
*
|
||||
* @return A fully built AsyncPositionController.
|
||||
*/
|
||||
std::shared_ptr<AsyncPositionController<double, double>> build();
|
||||
|
||||
private:
|
||||
std::shared_ptr<Logger> logger;
|
||||
|
||||
bool hasMotors{false}; // Used to verify motors were passed
|
||||
std::shared_ptr<AbstractMotor> motor;
|
||||
|
||||
bool sensorsSetByUser{false}; // Used so motors don't overwrite sensors set manually
|
||||
std::shared_ptr<RotarySensor> sensor;
|
||||
|
||||
bool hasGains{false}; // Whether gains were passed, no gains means integrated control
|
||||
IterativePosPIDController::Gains gains;
|
||||
std::unique_ptr<Filter> derivativeFilter = std::make_unique<PassthroughFilter>();
|
||||
|
||||
bool gearsetSetByUser{false}; // Used so motor's don't overwrite a gearset set manually
|
||||
AbstractMotor::GearsetRatioPair pair{AbstractMotor::gearset::invalid};
|
||||
|
||||
bool maxVelSetByUser{false}; // Used so motors don't overwrite maxVelocity
|
||||
double maxVelocity{600};
|
||||
|
||||
TimeUtilFactory timeUtilFactory = TimeUtilFactory();
|
||||
std::shared_ptr<Logger> controllerLogger = Logger::getDefaultLogger();
|
||||
|
||||
bool isParentedToCurrentTask{true};
|
||||
|
||||
std::shared_ptr<AsyncPosIntegratedController> buildAPIC();
|
||||
std::shared_ptr<AsyncPosPIDController> buildAPPC();
|
||||
};
|
||||
} // namespace okapi
|
@ -0,0 +1,203 @@
|
||||
/*
|
||||
* 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 "okapi/api/control/async/asyncVelIntegratedController.hpp"
|
||||
#include "okapi/api/control/async/asyncVelPidController.hpp"
|
||||
#include "okapi/api/control/async/asyncVelocityController.hpp"
|
||||
#include "okapi/api/util/logging.hpp"
|
||||
#include "okapi/impl/device/motor/motor.hpp"
|
||||
#include "okapi/impl/device/motor/motorGroup.hpp"
|
||||
#include "okapi/impl/device/rotarysensor/adiEncoder.hpp"
|
||||
#include "okapi/impl/device/rotarysensor/integratedEncoder.hpp"
|
||||
#include "okapi/impl/util/timeUtilFactory.hpp"
|
||||
|
||||
namespace okapi {
|
||||
class AsyncVelControllerBuilder {
|
||||
public:
|
||||
/**
|
||||
* A builder that creates async velocity controllers. Use this to create an
|
||||
* AsyncVelIntegratedController or an AsyncVelPIDController.
|
||||
*
|
||||
* @param ilogger The logger this instance will log to.
|
||||
*/
|
||||
explicit AsyncVelControllerBuilder(
|
||||
const std::shared_ptr<Logger> &ilogger = Logger::getDefaultLogger());
|
||||
|
||||
/**
|
||||
* Sets the motor.
|
||||
*
|
||||
* @param imotor The motor.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder &withMotor(const Motor &imotor);
|
||||
|
||||
/**
|
||||
* Sets the motor.
|
||||
*
|
||||
* @param imotor The motor.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder &withMotor(const MotorGroup &imotor);
|
||||
|
||||
/**
|
||||
* Sets the motor.
|
||||
*
|
||||
* @param imotor The motor.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder &withMotor(const std::shared_ptr<AbstractMotor> &imotor);
|
||||
|
||||
/**
|
||||
* Sets the sensor. The default sensor is the motor's integrated encoder.
|
||||
*
|
||||
* @param isensor The sensor.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder &withSensor(const ADIEncoder &isensor);
|
||||
|
||||
/**
|
||||
* Sets the sensor. The default sensor is the motor's integrated encoder.
|
||||
*
|
||||
* @param isensor The sensor.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder &withSensor(const IntegratedEncoder &isensor);
|
||||
|
||||
/**
|
||||
* Sets the sensor. The default sensor is the motor's integrated encoder.
|
||||
*
|
||||
* @param isensor The sensor.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder &withSensor(const std::shared_ptr<RotarySensor> &isensor);
|
||||
|
||||
/**
|
||||
* Sets the controller gains, causing the builder to generate an AsyncVelPIDController. This does
|
||||
* not set the integrated control's gains.
|
||||
*
|
||||
* @param igains The gains.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder &withGains(const IterativeVelPIDController::Gains &igains);
|
||||
|
||||
/**
|
||||
* Sets the VelMath which calculates and filters velocity. This is ignored when using integrated
|
||||
* controller. If using a PID controller (by setting the gains), this is required.
|
||||
*
|
||||
* @param ivelMath The VelMath.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder &withVelMath(std::unique_ptr<VelMath> ivelMath);
|
||||
|
||||
/**
|
||||
* Sets the derivative filter which filters the derivative term before it is scaled by kD. The
|
||||
* filter is ignored when using integrated control. The default derivative filter is a
|
||||
* PassthroughFilter.
|
||||
*
|
||||
* @param iderivativeFilter The derivative filter.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder &withDerivativeFilter(std::unique_ptr<Filter> iderivativeFilter);
|
||||
|
||||
/**
|
||||
* Sets the gearset. The default gearset is derived from the motor's.
|
||||
*
|
||||
* @param igearset The gearset.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder &withGearset(const AbstractMotor::GearsetRatioPair &igearset);
|
||||
|
||||
/**
|
||||
* Sets the maximum velocity. The default maximum velocity is derived from the motor's gearset.
|
||||
* This parameter is ignored when using an AsyncVelPIDController.
|
||||
*
|
||||
* @param imaxVelocity The maximum velocity.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder &withMaxVelocity(double imaxVelocity);
|
||||
|
||||
/**
|
||||
* Sets the TimeUtilFactory used when building the controller. The default is the static
|
||||
* TimeUtilFactory.
|
||||
*
|
||||
* @param itimeUtilFactory The TimeUtilFactory.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder &withTimeUtilFactory(const TimeUtilFactory &itimeUtilFactory);
|
||||
|
||||
/**
|
||||
* Sets the logger.
|
||||
*
|
||||
* @param ilogger The logger.
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder &withLogger(const std::shared_ptr<Logger> &ilogger);
|
||||
|
||||
/**
|
||||
* Parents the internal tasks started by this builder to the current task, meaning they will be
|
||||
* deleted once the current task is deleted. The `initialize` and `competition_initialize` tasks
|
||||
* are never parented to. This is the default behavior.
|
||||
*
|
||||
* Read more about this in the [builders and tasks tutorial]
|
||||
* (docs/tutorials/concepts/builders-and-tasks.md).
|
||||
*
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder &parentedToCurrentTask();
|
||||
|
||||
/**
|
||||
* Prevents parenting the internal tasks started by this builder to the current task, meaning they
|
||||
* will not be deleted once the current task is deleted. This can cause runaway tasks, but is
|
||||
* sometimes the desired behavior (e.x., if you want to use this builder once in `autonomous` and
|
||||
* then again in `opcontrol`).
|
||||
*
|
||||
* Read more about this in the [builders and tasks tutorial]
|
||||
* (docs/tutorials/concepts/builders-and-tasks.md).
|
||||
*
|
||||
* @return An ongoing builder.
|
||||
*/
|
||||
AsyncVelControllerBuilder ¬ParentedToCurrentTask();
|
||||
|
||||
/**
|
||||
* Builds the AsyncVelocityController. Throws a std::runtime_exception is no motors were set.
|
||||
*
|
||||
* @return A fully built AsyncVelocityController.
|
||||
*/
|
||||
std::shared_ptr<AsyncVelocityController<double, double>> build();
|
||||
|
||||
private:
|
||||
std::shared_ptr<Logger> logger;
|
||||
|
||||
bool hasMotors{false}; // Used to verify motors were passed
|
||||
std::shared_ptr<AbstractMotor> motor;
|
||||
|
||||
bool sensorsSetByUser{false}; // Used so motors don't overwrite sensors set manually
|
||||
std::shared_ptr<RotarySensor> sensor;
|
||||
|
||||
bool hasGains{false}; // Whether gains were passed, no gains means integrated control
|
||||
IterativeVelPIDController::Gains gains;
|
||||
|
||||
bool hasVelMath{false}; // Used to verify velMath was passed
|
||||
std::unique_ptr<VelMath> velMath;
|
||||
|
||||
std::unique_ptr<Filter> derivativeFilter = std::make_unique<PassthroughFilter>();
|
||||
|
||||
bool gearsetSetByUser{false}; // Used so motor's don't overwrite a gearset set manually
|
||||
AbstractMotor::GearsetRatioPair pair{AbstractMotor::gearset::invalid};
|
||||
|
||||
bool maxVelSetByUser{false}; // Used so motors don't overwrite maxVelocity
|
||||
double maxVelocity{600};
|
||||
|
||||
TimeUtilFactory timeUtilFactory = TimeUtilFactory();
|
||||
std::shared_ptr<Logger> controllerLogger = Logger::getDefaultLogger();
|
||||
|
||||
bool isParentedToCurrentTask{true};
|
||||
|
||||
std::shared_ptr<AsyncVelIntegratedController> buildAVIC();
|
||||
std::shared_ptr<AsyncVelPIDController> buildAVPC();
|
||||
};
|
||||
} // namespace okapi
|
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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 "okapi/api/control/iterative/iterativeMotorVelocityController.hpp"
|
||||
#include "okapi/api/control/iterative/iterativePosPidController.hpp"
|
||||
#include "okapi/api/control/iterative/iterativeVelPidController.hpp"
|
||||
#include "okapi/api/util/mathUtil.hpp"
|
||||
#include "okapi/impl/device/motor/motor.hpp"
|
||||
#include "okapi/impl/device/motor/motorGroup.hpp"
|
||||
#include "okapi/impl/filter/velMathFactory.hpp"
|
||||
|
||||
namespace okapi {
|
||||
class IterativeControllerFactory {
|
||||
public:
|
||||
/**
|
||||
* Position PID controller.
|
||||
*
|
||||
* @param ikP proportional gain
|
||||
* @param ikI integral gain
|
||||
* @param ikD derivative gain
|
||||
* @param ikBias controller bias (constant offset added to the output)
|
||||
* @param iderivativeFilter A filter for filtering the derivative term.
|
||||
* @param ilogger The logger this instance will log to.
|
||||
*/
|
||||
static IterativePosPIDController
|
||||
posPID(double ikP,
|
||||
double ikI,
|
||||
double ikD,
|
||||
double ikBias = 0,
|
||||
std::unique_ptr<Filter> iderivativeFilter = std::make_unique<PassthroughFilter>(),
|
||||
const std::shared_ptr<Logger> &ilogger = Logger::getDefaultLogger());
|
||||
|
||||
/**
|
||||
* Velocity PD controller.
|
||||
*
|
||||
* @param ikP proportional gain
|
||||
* @param ikD derivative gain
|
||||
* @param ikF feed-forward gain
|
||||
* @param ikSF a feed-forward gain to counteract static friction
|
||||
* @param iderivativeFilter A filter for filtering the derivative term.
|
||||
* @param ilogger The logger this instance will log to.
|
||||
*/
|
||||
static IterativeVelPIDController
|
||||
velPID(double ikP,
|
||||
double ikD,
|
||||
double ikF = 0,
|
||||
double ikSF = 0,
|
||||
std::unique_ptr<VelMath> ivelMath = VelMathFactory::createPtr(imev5GreenTPR),
|
||||
std::unique_ptr<Filter> iderivativeFilter = std::make_unique<PassthroughFilter>(),
|
||||
const std::shared_ptr<Logger> &ilogger = Logger::getDefaultLogger());
|
||||
|
||||
/**
|
||||
* Velocity PD controller that automatically writes to the motor.
|
||||
*
|
||||
* @param imotor output motor
|
||||
* @param ikP proportional gain
|
||||
* @param ikD derivative gain
|
||||
* @param ikF feed-forward gain
|
||||
* @param ikSF a feed-forward gain to counteract static friction
|
||||
* @param ivelMath The VelMath.
|
||||
* @param iderivativeFilter A filter for filtering the derivative term.
|
||||
* @param ilogger The logger this instance will log to.
|
||||
*/
|
||||
static IterativeMotorVelocityController
|
||||
motorVelocity(Motor imotor,
|
||||
double ikP,
|
||||
double ikD,
|
||||
double ikF = 0,
|
||||
double ikSF = 0,
|
||||
std::unique_ptr<VelMath> ivelMath = VelMathFactory::createPtr(imev5GreenTPR),
|
||||
std::unique_ptr<Filter> iderivativeFilter = std::make_unique<PassthroughFilter>(),
|
||||
const std::shared_ptr<Logger> &ilogger = Logger::getDefaultLogger());
|
||||
|
||||
/**
|
||||
* Velocity PD controller that automatically writes to the motor.
|
||||
*
|
||||
* @param imotor output motor
|
||||
* @param ikP proportional gain
|
||||
* @param ikD derivative gain
|
||||
* @param ikF feed-forward gain
|
||||
* @param ikSF a feed-forward gain to counteract static friction
|
||||
* @param ivelMath The VelMath.
|
||||
* @param iderivativeFilter A filter for filtering the derivative term.
|
||||
* @param ilogger The logger this instance will log to.
|
||||
*/
|
||||
static IterativeMotorVelocityController
|
||||
motorVelocity(MotorGroup imotor,
|
||||
double ikP,
|
||||
double ikD,
|
||||
double ikF = 0,
|
||||
double ikSF = 0,
|
||||
std::unique_ptr<VelMath> ivelMath = VelMathFactory::createPtr(imev5GreenTPR),
|
||||
std::unique_ptr<Filter> iderivativeFilter = std::make_unique<PassthroughFilter>(),
|
||||
const std::shared_ptr<Logger> &ilogger = Logger::getDefaultLogger());
|
||||
|
||||
/**
|
||||
* Velocity PD controller that automatically writes to the motor.
|
||||
*
|
||||
* @param imotor output motor
|
||||
* @param icontroller controller to use
|
||||
*/
|
||||
static IterativeMotorVelocityController
|
||||
motorVelocity(Motor imotor,
|
||||
std::shared_ptr<IterativeVelocityController<double, double>> icontroller);
|
||||
|
||||
/**
|
||||
* Velocity PD controller that automatically writes to the motor.
|
||||
*
|
||||
* @param imotor output motor
|
||||
* @param icontroller controller to use
|
||||
*/
|
||||
static IterativeMotorVelocityController
|
||||
motorVelocity(MotorGroup imotor,
|
||||
std::shared_ptr<IterativeVelocityController<double, double>> icontroller);
|
||||
};
|
||||
} // namespace okapi
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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 "okapi/api/control/util/controllerRunner.hpp"
|
||||
#include "okapi/impl/util/timeUtilFactory.hpp"
|
||||
|
||||
namespace okapi {
|
||||
template <typename Input, typename Output> class ControllerRunnerFactory {
|
||||
public:
|
||||
/**
|
||||
* A utility class that runs a closed-loop controller.
|
||||
*
|
||||
* @param ilogger The logger this instance will log to.
|
||||
* @return
|
||||
*/
|
||||
static ControllerRunner<Input, Output>
|
||||
create(const std::shared_ptr<Logger> &ilogger = Logger::getDefaultLogger()) {
|
||||
return ControllerRunner<Input, Output>(TimeUtilFactory::createDefault(), ilogger);
|
||||
}
|
||||
};
|
||||
} // namespace okapi
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 "okapi/api/control/util/pidTuner.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace okapi {
|
||||
class PIDTunerFactory {
|
||||
public:
|
||||
static PIDTuner create(const std::shared_ptr<ControllerInput<double>> &iinput,
|
||||
const std::shared_ptr<ControllerOutput<double>> &ioutput,
|
||||
QTime itimeout,
|
||||
std::int32_t igoal,
|
||||
double ikPMin,
|
||||
double ikPMax,
|
||||
double ikIMin,
|
||||
double ikIMax,
|
||||
double ikDMin,
|
||||
double ikDMax,
|
||||
std::int32_t inumIterations = 5,
|
||||
std::int32_t inumParticles = 16,
|
||||
double ikSettle = 1,
|
||||
double ikITAE = 2,
|
||||
const std::shared_ptr<Logger> &ilogger = Logger::getDefaultLogger());
|
||||
|
||||
static std::unique_ptr<PIDTuner>
|
||||
createPtr(const std::shared_ptr<ControllerInput<double>> &iinput,
|
||||
const std::shared_ptr<ControllerOutput<double>> &ioutput,
|
||||
QTime itimeout,
|
||||
std::int32_t igoal,
|
||||
double ikPMin,
|
||||
double ikPMax,
|
||||
double ikIMin,
|
||||
double ikIMax,
|
||||
double ikDMin,
|
||||
double ikDMax,
|
||||
std::int32_t inumIterations = 5,
|
||||
std::int32_t inumParticles = 16,
|
||||
double ikSettle = 1,
|
||||
double ikITAE = 2,
|
||||
const std::shared_ptr<Logger> &ilogger = Logger::getDefaultLogger());
|
||||
};
|
||||
} // namespace okapi
|
Reference in New Issue
Block a user