├── src ├── autonomous.cpp ├── initialize.cpp └── opcontrol.cpp ├── Example.png ├── Field.png ├── firmware ├── libpros.a ├── okapilib.a └── v5-common.ld ├── .gitignore ├── include ├── display │ ├── lv_hal │ │ ├── lv_hal.mk │ │ ├── lv_hal.h │ │ └── lv_hal_tick.h │ ├── lv_draw │ │ ├── lv_draw.mk │ │ ├── lv_draw_vbasic.h │ │ └── lv_draw_rbasic.h │ ├── lv_core │ │ ├── lv_core.mk │ │ ├── lv_vdb.h │ │ ├── lv_refr.h │ │ └── lv_indev.h │ ├── lv_themes │ │ ├── lv_themes.mk │ │ ├── lv_theme_alien.h │ │ └── lv_theme_templ.h │ ├── lv_misc │ │ ├── lv_misc.mk │ │ ├── lv_fonts │ │ │ └── lv_fonts.mk │ │ ├── lv_templ.h │ │ ├── lv_trigo.h │ │ ├── lv_math.h │ │ ├── lv_circ.h │ │ ├── lv_mem.h │ │ ├── lv_task.h │ │ ├── lv_anim.h │ │ └── lv_ll.h │ ├── lv_objx │ │ ├── lv_objx.mk │ │ ├── lv_led.h │ │ ├── lv_objx_templ.h │ │ ├── lv_bar.h │ │ ├── lv_sw.h │ │ ├── lv_cont.h │ │ ├── lv_lmeter.h │ │ └── lv_line.h │ ├── licence.txt │ ├── lvgl.h │ └── README.md ├── okapi │ ├── pathfinder │ │ └── include │ │ │ ├── pathfinder │ │ │ ├── lib.h │ │ │ ├── modifiers │ │ │ │ ├── tank.h │ │ │ │ └── swerve.h │ │ │ ├── mathutil.h │ │ │ ├── fit.h │ │ │ ├── followers │ │ │ │ ├── distance.h │ │ │ │ └── encoder.h │ │ │ ├── spline.h │ │ │ ├── trajectory.h │ │ │ ├── io.h │ │ │ └── structs.h │ │ │ └── pathfinder.h │ ├── impl │ │ ├── device │ │ │ ├── vision.hpp │ │ │ ├── button │ │ │ │ ├── adiButton.hpp │ │ │ │ └── controllerButton.hpp │ │ │ ├── rotarysensor │ │ │ │ ├── potentiometer.hpp │ │ │ │ ├── adiEncoder.hpp │ │ │ │ ├── integratedEncoder.hpp │ │ │ │ └── adiGyro.hpp │ │ │ ├── motor │ │ │ │ └── adiMotor.hpp │ │ │ ├── controllerUtil.hpp │ │ │ └── adiUltrasonic.hpp │ │ ├── util │ │ │ ├── timer.hpp │ │ │ ├── timeUtilFactory.hpp │ │ │ └── rate.hpp │ │ ├── control │ │ │ ├── util │ │ │ │ ├── controllerRunnerFactory.hpp │ │ │ │ ├── settledUtilFactory.hpp │ │ │ │ └── pidTunerFactory.hpp │ │ │ └── iterative │ │ │ │ └── iterativeControllerFactory.hpp │ │ └── filter │ │ │ └── velMathFactory.hpp │ └── api │ │ ├── control │ │ ├── iterative │ │ │ ├── iterativePositionController.hpp │ │ │ ├── iterativeVelocityController.hpp │ │ │ ├── iterativeController.hpp │ │ │ └── iterativeMotorVelocityController.hpp │ │ ├── async │ │ │ ├── asyncPositionController.hpp │ │ │ ├── asyncVelocityController.hpp │ │ │ ├── asyncController.hpp │ │ │ ├── asyncPosPidController.hpp │ │ │ ├── asyncVelPidController.hpp │ │ │ └── asyncVelIntegratedController.hpp │ │ ├── controllerInput.hpp │ │ ├── controllerOutput.hpp │ │ ├── util │ │ │ ├── settledUtil.hpp │ │ │ └── pidTuner.hpp │ │ └── closedLoopController.hpp │ │ ├── device │ │ ├── rotarysensor │ │ │ ├── continuousRotarySensor.hpp │ │ │ └── rotarySensor.hpp │ │ └── button │ │ │ ├── buttonBase.hpp │ │ │ └── abstractButton.hpp │ │ ├── units │ │ ├── QAngularJerk.hpp │ │ ├── QAngularAcceleration.hpp │ │ ├── QJerk.hpp │ │ ├── QFrequency.hpp │ │ ├── QArea.hpp │ │ ├── QAngularSpeed.hpp │ │ ├── QVolume.hpp │ │ ├── QAngle.hpp │ │ ├── QAcceleration.hpp │ │ ├── QForce.hpp │ │ ├── QSpeed.hpp │ │ ├── QTorque.hpp │ │ ├── QPressure.hpp │ │ ├── QTime.hpp │ │ ├── QMass.hpp │ │ └── QLength.hpp │ │ ├── filter │ │ ├── filter.hpp │ │ ├── passthroughFilter.hpp │ │ ├── emaFilter.hpp │ │ ├── demaFilter.hpp │ │ ├── averageFilter.hpp │ │ ├── filteredControllerInput.hpp │ │ ├── composableFilter.hpp │ │ ├── medianFilter.hpp │ │ ├── ekfFilter.hpp │ │ └── velMath.hpp │ │ ├── util │ │ ├── supplier.hpp │ │ ├── timeUtil.hpp │ │ ├── abstractRate.hpp │ │ ├── logging.hpp │ │ └── abstractTimer.hpp │ │ ├── chassis │ │ ├── model │ │ │ ├── readOnlyChassisModel.hpp │ │ │ └── threeEncoderSkidSteerModel.hpp │ │ └── controller │ │ │ └── chassisScales.hpp │ │ └── coreProsAPI.hpp ├── api.h ├── main.h ├── screen │ └── resources.hpp └── pros │ └── api_legacy.h ├── .clang-format ├── LICENSE └── Makefile /src/autonomous.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | void autonomous() {} 4 | -------------------------------------------------------------------------------- /Example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jm-spencer/screenlib/HEAD/Example.png -------------------------------------------------------------------------------- /Field.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jm-spencer/screenlib/HEAD/Field.png -------------------------------------------------------------------------------- /firmware/libpros.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jm-spencer/screenlib/HEAD/firmware/libpros.a -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | 3 | bin/ 4 | 5 | compile_commands.json 6 | temp.log 7 | 8 | *.zip 9 | -------------------------------------------------------------------------------- /firmware/okapilib.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jm-spencer/screenlib/HEAD/firmware/okapilib.a -------------------------------------------------------------------------------- /include/display/lv_hal/lv_hal.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_hal_disp.c 2 | CSRCS += lv_hal_indev.c 3 | CSRCS += lv_hal_tick.c 4 | 5 | DEPPATH += --dep-path lvgl/lv_hal 6 | VPATH += :lvgl/lv_hal 7 | 8 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_hal" 9 | -------------------------------------------------------------------------------- /include/display/lv_draw/lv_draw.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_draw_vbasic.c 2 | CSRCS += lv_draw.c 3 | CSRCS += lv_draw_rbasic.c 4 | 5 | DEPPATH += --dep-path lvgl/lv_draw 6 | VPATH += :lvgl/lv_draw 7 | 8 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_draw" 9 | -------------------------------------------------------------------------------- /src/initialize.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "screen/resources.hpp" 3 | 4 | void initialize() 5 | { 6 | // this is very important 7 | screen::initializeStyles(); 8 | } 9 | 10 | void disabled() {} 11 | 12 | void competition_initialize() {} 13 | -------------------------------------------------------------------------------- /include/display/lv_core/lv_core.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_group.c 2 | CSRCS += lv_indev.c 3 | CSRCS += lv_obj.c 4 | CSRCS += lv_refr.c 5 | CSRCS += lv_style.c 6 | CSRCS += lv_vdb.c 7 | 8 | DEPPATH += --dep-path lvgl/lv_core 9 | VPATH += :lvgl/lv_core 10 | 11 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_core" 12 | -------------------------------------------------------------------------------- /include/okapi/pathfinder/include/pathfinder/lib.h: -------------------------------------------------------------------------------- 1 | #ifndef PATHFINDER_LIB_H_DEF 2 | #define PATHFINDER_LIB_H_DEF 3 | 4 | #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) 5 | #define CAPI __declspec(dllexport) 6 | #else 7 | #define CAPI 8 | #endif 9 | 10 | #endif -------------------------------------------------------------------------------- /firmware/v5-common.ld: -------------------------------------------------------------------------------- 1 | _HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x02E00000; /* ~48 MB */ 2 | 3 | MEMORY 4 | { 5 | /* user code 72M */ 6 | COLD_MEMORY : ORIGIN = 0x03800000, LENGTH = 0x04800000 /* Just under 19 MB */ 7 | HEAP : ORIGIN = 0x04A00000, LENGTH = _HEAP_SIZE 8 | HOT_MEMORY : ORIGIN = 0x07800000, LENGTH = 0x00800000 /* Just over 8 MB */ 9 | } 10 | -------------------------------------------------------------------------------- /include/display/lv_themes/lv_themes.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_theme_alien.c 2 | CSRCS += lv_theme.c 3 | CSRCS += lv_theme_default.c 4 | CSRCS += lv_theme_night.c 5 | CSRCS += lv_theme_templ.c 6 | CSRCS += lv_theme_zen.c 7 | CSRCS += lv_theme_material.c 8 | 9 | 10 | DEPPATH += --dep-path lvgl/lv_themes 11 | VPATH += :lvgl/lv_themes 12 | 13 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_themes" 14 | -------------------------------------------------------------------------------- /include/okapi/pathfinder/include/pathfinder/modifiers/tank.h: -------------------------------------------------------------------------------- 1 | #ifndef PATHFINDER_MOD_TANK_H_DEF 2 | #define PATHFINDER_MOD_TANK_H_DEF 3 | 4 | #include "okapi/pathfinder/include/pathfinder/lib.h" 5 | #include "okapi/pathfinder/include/pathfinder/structs.h" 6 | 7 | CAPI void pathfinder_modify_tank(Segment *original, int length, Segment *left, Segment *right, double wheelbase_width); 8 | 9 | #endif -------------------------------------------------------------------------------- /include/okapi/impl/device/vision.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "api.h" 11 | 12 | namespace okapi { 13 | using pros::Vision; 14 | } // namespace okapi 15 | -------------------------------------------------------------------------------- /include/display/lv_misc/lv_misc.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_font.c 2 | CSRCS += lv_circ.c 3 | CSRCS += lv_area.c 4 | CSRCS += lv_task.c 5 | CSRCS += lv_fs.c 6 | CSRCS += lv_anim.c 7 | CSRCS += lv_mem.c 8 | CSRCS += lv_ll.c 9 | CSRCS += lv_color.c 10 | CSRCS += lv_txt.c 11 | CSRCS += lv_ufs.c 12 | CSRCS += lv_trigo.c 13 | CSRCS += lv_math.c 14 | 15 | DEPPATH += --dep-path lvgl/lv_misc 16 | VPATH += :lvgl/lv_misc 17 | 18 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_misc" 19 | -------------------------------------------------------------------------------- /include/okapi/pathfinder/include/pathfinder/mathutil.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef PATHFINDER_MATH_UTIL_H_DEF 4 | #define PATHFINDER_MATH_UTIL_H_DEF 5 | 6 | #include "okapi/pathfinder/include/pathfinder/lib.h" 7 | 8 | #define PI 3.14159265358979323846 9 | #define TAU PI*2 10 | 11 | #define MIN(a,b) (((a)<(b))?(a):(b)) 12 | #define MAX(a,b) (((a)>(b))?(a):(b)) 13 | 14 | CAPI double bound_radians(double angle); 15 | 16 | CAPI double r2d(double angleInRads); 17 | 18 | CAPI double d2r(double angleInDegrees); 19 | 20 | #endif -------------------------------------------------------------------------------- /include/okapi/pathfinder/include/pathfinder/fit.h: -------------------------------------------------------------------------------- 1 | #ifndef PATHFINDER_FIT_H_DEF 2 | #define PATHFINDER_FIT_H_DEF 3 | 4 | #include "okapi/pathfinder/include/pathfinder/lib.h" 5 | #include "okapi/pathfinder/include/pathfinder/structs.h" 6 | 7 | CAPI void pf_fit_hermite_pre(Waypoint a, Waypoint b, Spline *s); 8 | CAPI void pf_fit_hermite_cubic(Waypoint a, Waypoint b, Spline *s); 9 | CAPI void pf_fit_hermite_quintic(Waypoint a, Waypoint b, Spline *s); 10 | 11 | #define FIT_HERMITE_CUBIC &pf_fit_hermite_cubic 12 | #define FIT_HERMITE_QUINTIC &pf_fit_hermite_quintic 13 | 14 | #endif -------------------------------------------------------------------------------- /include/okapi/pathfinder/include/pathfinder/modifiers/swerve.h: -------------------------------------------------------------------------------- 1 | #ifndef PATHFINDER_MOD_SWERVE_H_DEF 2 | #define PATHFINDER_MOD_SWERVE_H_DEF 3 | 4 | #include "okapi/pathfinder/include/pathfinder/lib.h" 5 | #include "okapi/pathfinder/include/pathfinder/structs.h" 6 | 7 | CAPI typedef enum { 8 | SWERVE_DEFAULT 9 | } SWERVE_MODE; 10 | 11 | CAPI void pathfinder_modify_swerve(Segment *original, int length, Segment *front_left, Segment *front_right, 12 | Segment *back_left, Segment *back_right, double wheelbase_width, double wheelbase_depth, SWERVE_MODE mode); 13 | 14 | #endif -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Google 2 | AlignConsecutiveAssignments: true 3 | AlignTrailingComments: true 4 | AllowShortCaseLabelsOnASingleLine: false 5 | AllowShortFunctionsOnASingleLine: Empty 6 | AllowShortIfStatementsOnASingleLine: false 7 | AllowShortLoopsOnASingleLine: true 8 | AlwaysBreakTemplateDeclarations: Yes 9 | BreakBeforeBraces: Custom 10 | BraceWrapping: 11 | AfterClass: false 12 | AfterControlStatement: false 13 | AfterEnum: false 14 | AfterFunction: true 15 | AfterNamespace: false 16 | ColumnLimit: 100 17 | DerivePointerAlignment: false 18 | PointerAlignment: Right 19 | -------------------------------------------------------------------------------- /include/okapi/api/control/iterative/iterativePositionController.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/iterative/iterativeController.hpp" 11 | 12 | namespace okapi { 13 | template 14 | class IterativePositionController : public IterativeController {}; 15 | } // namespace okapi 16 | -------------------------------------------------------------------------------- /include/okapi/api/control/iterative/iterativeVelocityController.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/iterative/iterativeController.hpp" 11 | 12 | namespace okapi { 13 | template 14 | class IterativeVelocityController : public IterativeController {}; 15 | } // namespace okapi 16 | -------------------------------------------------------------------------------- /include/okapi/api/control/async/asyncPositionController.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/async/asyncController.hpp" 11 | #include 12 | 13 | namespace okapi { 14 | template 15 | class AsyncPositionController : virtual public AsyncController {}; 16 | } // namespace okapi 17 | -------------------------------------------------------------------------------- /include/okapi/api/control/async/asyncVelocityController.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/async/asyncController.hpp" 11 | #include 12 | 13 | namespace okapi { 14 | template 15 | class AsyncVelocityController : virtual public AsyncController {}; 16 | } // namespace okapi 17 | -------------------------------------------------------------------------------- /include/okapi/impl/util/timer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/util/abstractTimer.hpp" 11 | 12 | namespace okapi { 13 | class Timer : public AbstractTimer { 14 | public: 15 | Timer(); 16 | 17 | /** 18 | * Returns the current time in units of QTime. 19 | * 20 | * @return the current time 21 | */ 22 | QTime millis() const override; 23 | }; 24 | } // namespace okapi 25 | -------------------------------------------------------------------------------- /include/display/lv_objx/lv_objx.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_bar.c 2 | CSRCS += lv_cb.c 3 | CSRCS += lv_ddlist.c 4 | CSRCS += lv_kb.c 5 | CSRCS += lv_line.c 6 | CSRCS += lv_mbox.c 7 | CSRCS += lv_roller.c 8 | CSRCS += lv_tabview.c 9 | CSRCS += lv_btn.c 10 | CSRCS += lv_chart.c 11 | CSRCS += lv_gauge.c 12 | CSRCS += lv_label.c 13 | CSRCS += lv_list.c 14 | CSRCS += lv_slider.c 15 | CSRCS += lv_ta.c 16 | CSRCS += lv_btnm.c 17 | CSRCS += lv_cont.c 18 | CSRCS += lv_img.c 19 | CSRCS += lv_led.c 20 | CSRCS += lv_lmeter.c 21 | CSRCS += lv_page.c 22 | CSRCS += lv_sw.c 23 | CSRCS += lv_win.c 24 | 25 | DEPPATH += --dep-path lvgl/lv_objx 26 | VPATH += :lvgl/lv_objx 27 | 28 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_objx" 29 | -------------------------------------------------------------------------------- /include/okapi/api/device/rotarysensor/continuousRotarySensor.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/device/rotarysensor/rotarySensor.hpp" 11 | 12 | namespace okapi { 13 | class ContinuousRotarySensor : public RotarySensor { 14 | public: 15 | /** 16 | * Reset the sensor to zero. 17 | * 18 | * @return 1 on success, PROS_ERR on fail 19 | */ 20 | virtual std::int32_t reset() = 0; 21 | }; 22 | } // namespace okapi 23 | -------------------------------------------------------------------------------- /include/okapi/impl/device/button/adiButton.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "api.h" 11 | #include "okapi/api/device/button/buttonBase.hpp" 12 | 13 | namespace okapi { 14 | class ADIButton : public ButtonBase { 15 | public: 16 | ADIButton(std::uint8_t iport, bool iinverted = false); 17 | 18 | protected: 19 | pros::ADIButton btn; 20 | std::uint8_t port; 21 | 22 | virtual bool currentlyPressed() override; 23 | }; 24 | } // namespace okapi 25 | -------------------------------------------------------------------------------- /include/okapi/api/control/controllerInput.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | namespace okapi { 11 | template class ControllerInput { 12 | public: 13 | /** 14 | * Get the sensor value for use in a control loop. This method might be automatically called in 15 | * another thread by the controller. 16 | * 17 | * @return the current sensor value, or ``PROS_ERR`` on a failure. 18 | */ 19 | virtual T controllerGet() = 0; 20 | }; 21 | } // namespace okapi 22 | -------------------------------------------------------------------------------- /include/okapi/api/units/QAngularJerk.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/RQuantity.hpp" 17 | 18 | namespace okapi { 19 | QUANTITY_TYPE(0, 0, -3, 1, QAngularJerk) 20 | } 21 | -------------------------------------------------------------------------------- /include/okapi/impl/control/util/controllerRunnerFactory.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/util/controllerRunner.hpp" 11 | #include "okapi/impl/util/rate.hpp" 12 | 13 | namespace okapi { 14 | template class ControllerRunnerFactory { 15 | public: 16 | static ControllerRunner create() { 17 | return ControllerRunner(std::make_unique()); 18 | } 19 | }; 20 | } // namespace okapi 21 | -------------------------------------------------------------------------------- /include/okapi/api/units/QAngularAcceleration.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/RQuantity.hpp" 17 | 18 | namespace okapi { 19 | QUANTITY_TYPE(0, 0, -2, 1, QAngularAcceleration) 20 | } 21 | -------------------------------------------------------------------------------- /include/display/lv_hal/lv_hal.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file hal.h 3 | * 4 | */ 5 | 6 | #ifndef HAL_H 7 | #define HAL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_hal_disp.h" 17 | #include "lv_hal_indev.h" 18 | #include "lv_hal_tick.h" 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /********************** 29 | * GLOBAL PROTOTYPES 30 | **********************/ 31 | 32 | /********************** 33 | * MACROS 34 | **********************/ 35 | 36 | #ifdef __cplusplus 37 | } /* extern "C" */ 38 | #endif 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /include/okapi/pathfinder/include/pathfinder.h: -------------------------------------------------------------------------------- 1 | #ifndef PATHFINDER_H_DEF 2 | #define PATHFINDER_H_DEF 3 | 4 | #include "okapi/pathfinder/include/pathfinder/mathutil.h" 5 | #include "okapi/pathfinder/include/pathfinder/structs.h" 6 | 7 | #include "okapi/pathfinder/include/pathfinder/fit.h" 8 | #include "okapi/pathfinder/include/pathfinder/spline.h" 9 | #include "okapi/pathfinder/include/pathfinder/trajectory.h" 10 | 11 | #include "okapi/pathfinder/include/pathfinder/modifiers/tank.h" 12 | #include "okapi/pathfinder/include/pathfinder/modifiers/swerve.h" 13 | 14 | #include "okapi/pathfinder/include/pathfinder/followers/encoder.h" 15 | #include "okapi/pathfinder/include/pathfinder/followers/distance.h" 16 | 17 | #include "okapi/pathfinder/include/pathfinder/io.h" 18 | 19 | #endif -------------------------------------------------------------------------------- /include/display/lv_misc/lv_fonts/lv_fonts.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_font_dejavu_10.c 2 | CSRCS += lv_font_dejavu_20.c 3 | CSRCS += lv_font_dejavu_30.c 4 | CSRCS += lv_font_dejavu_40.c 5 | CSRCS += lv_font_dejavu_10_cyrillic.c 6 | CSRCS += lv_font_dejavu_20_cyrillic.c 7 | CSRCS += lv_font_dejavu_30_cyrillic.c 8 | CSRCS += lv_font_dejavu_40_cyrillic.c 9 | CSRCS += lv_font_dejavu_10_latin_sup.c 10 | CSRCS += lv_font_dejavu_20_latin_sup.c 11 | CSRCS += lv_font_dejavu_30_latin_sup.c 12 | CSRCS += lv_font_dejavu_40_latin_sup.c 13 | CSRCS += lv_font_symbol_10.c 14 | CSRCS += lv_font_symbol_20.c 15 | CSRCS += lv_font_symbol_30.c 16 | CSRCS += lv_font_symbol_40.c 17 | 18 | DEPPATH += --dep-path lvgl/lv_misc/lv_fonts 19 | VPATH += :lvgl/lv_misc/lv_fonts 20 | 21 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_misc/lv_fonts" 22 | -------------------------------------------------------------------------------- /include/okapi/api/device/rotarysensor/rotarySensor.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/controllerInput.hpp" 11 | #include "okapi/api/coreProsAPI.hpp" 12 | 13 | namespace okapi { 14 | class RotarySensor : public ControllerInput { 15 | public: 16 | virtual ~RotarySensor(); 17 | 18 | /** 19 | * Get the current sensor value. 20 | * 21 | * @return the current sensor value, or ``PROS_ERR`` on a failure. 22 | */ 23 | virtual double get() const = 0; 24 | }; 25 | } // namespace okapi 26 | -------------------------------------------------------------------------------- /include/okapi/api/control/controllerOutput.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | namespace okapi { 11 | template class ControllerOutput { 12 | public: 13 | /** 14 | * Writes the value of the controller output. This method might be automatically called in another 15 | * thread by the controller. The range of input values is expected to be [-1, 1]. 16 | * 17 | * @param ivalue the controller's output in the range [-1, 1] 18 | */ 19 | virtual void controllerSet(T ivalue) = 0; 20 | }; 21 | } // namespace okapi 22 | -------------------------------------------------------------------------------- /include/okapi/pathfinder/include/pathfinder/followers/distance.h: -------------------------------------------------------------------------------- 1 | #ifndef PATHFINDER_FOL_DISTANCE_H_DEF 2 | #define PATHFINDER_FOL_DISTANCE_H_DEF 3 | 4 | #include "okapi/pathfinder/include/pathfinder/lib.h" 5 | #include "okapi/pathfinder/include/pathfinder/structs.h" 6 | 7 | CAPI typedef struct { 8 | double kp, ki, kd, kv, ka; 9 | } FollowerConfig; 10 | 11 | CAPI typedef struct { 12 | double last_error, heading, output; 13 | int segment, finished; 14 | } DistanceFollower; 15 | 16 | CAPI double pathfinder_follow_distance(FollowerConfig c, DistanceFollower *follower, Segment *trajectory, int trajectory_length, double distance); 17 | 18 | CAPI double pathfinder_follow_distance2(FollowerConfig c, DistanceFollower *follower, Segment segment, int trajectory_length, double distance); 19 | 20 | #endif -------------------------------------------------------------------------------- /include/okapi/pathfinder/include/pathfinder/followers/encoder.h: -------------------------------------------------------------------------------- 1 | #ifndef PATHFINDER_FOL_ENCODER_H_DEF 2 | #define PATHFINDER_FOL_ENCODER_H_DEF 3 | 4 | #include "okapi/pathfinder/include/pathfinder/structs.h" 5 | 6 | typedef struct { 7 | int initial_position, ticks_per_revolution; 8 | double wheel_circumference; 9 | double kp, ki, kd, kv, ka; 10 | } EncoderConfig; 11 | 12 | typedef struct { 13 | double last_error, heading, output; 14 | int segment, finished; 15 | } EncoderFollower; 16 | 17 | double pathfinder_follow_encoder(EncoderConfig c, EncoderFollower *follower, Segment *trajectory, int trajectory_length, int encoder_tick); 18 | 19 | double pathfinder_follow_encoder2(EncoderConfig c, EncoderFollower *follower, Segment segment, int trajectory_length, int encoder_tick); 20 | 21 | #endif -------------------------------------------------------------------------------- /include/okapi/api/units/QJerk.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/QLength.hpp" 17 | #include "okapi/api/units/QTime.hpp" 18 | #include "okapi/api/units/RQuantity.hpp" 19 | 20 | namespace okapi { 21 | QUANTITY_TYPE(0, 1, -3, 0, QJerk) 22 | } 23 | -------------------------------------------------------------------------------- /include/display/lv_misc/lv_templ.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.h 3 | * 4 | */ 5 | 6 | #pragma GCC diagnostic push 7 | #pragma GCC diagnostic ignored "-Wpedantic" 8 | 9 | #ifndef LV_TEMPL_H 10 | #define LV_TEMPL_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /********************* 17 | * INCLUDES 18 | *********************/ 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /********************** 29 | * GLOBAL PROTOTYPES 30 | **********************/ 31 | 32 | /********************** 33 | * MACROS 34 | **********************/ 35 | 36 | #ifdef __cplusplus 37 | } /* extern "C" */ 38 | #endif 39 | 40 | #endif /*LV_TEMPL_H*/ 41 | 42 | #pragma GCC diagnostic pop 43 | -------------------------------------------------------------------------------- /include/okapi/api/filter/filter.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | namespace okapi { 11 | class Filter { 12 | public: 13 | virtual ~Filter(); 14 | 15 | /** 16 | * Filters a value, like a sensor reading. 17 | * 18 | * @param ireading new measurement 19 | * @return filtered result 20 | */ 21 | virtual double filter(double ireading) = 0; 22 | 23 | /** 24 | * Returns the previous output from filter. 25 | * 26 | * @return the previous output from filter 27 | */ 28 | virtual double getOutput() const = 0; 29 | }; 30 | } // namespace okapi 31 | -------------------------------------------------------------------------------- /include/okapi/pathfinder/include/pathfinder/spline.h: -------------------------------------------------------------------------------- 1 | #ifndef PATHFINDER_SPLINE_H_DEF 2 | #define PATHFINDER_SPLINE_H_DEF 3 | 4 | #include "okapi/pathfinder/include/pathfinder/lib.h" 5 | #include "okapi/pathfinder/include/pathfinder/structs.h" 6 | 7 | #define PATHFINDER_SAMPLES_FAST (int)1000 8 | #define PATHFINDER_SAMPLES_LOW (int)PATHFINDER_SAMPLES_FAST*10 9 | #define PATHFINDER_SAMPLES_HIGH (int)PATHFINDER_SAMPLES_LOW*10 10 | 11 | CAPI Coord pf_spline_coords(Spline s, double percentage); 12 | CAPI double pf_spline_deriv(Spline s, double percentage); 13 | CAPI double pf_spline_deriv_2(double a, double b, double c, double d, double e, double k, double p); 14 | CAPI double pf_spline_angle(Spline s, double percentage); 15 | 16 | CAPI double pf_spline_distance(Spline *s, int sample_count); 17 | CAPI double pf_spline_progress_for_distance(Spline s, double distance, int sample_count); 18 | 19 | #endif -------------------------------------------------------------------------------- /include/okapi/impl/util/timeUtilFactory.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/util/timeUtil.hpp" 11 | 12 | namespace okapi { 13 | class TimeUtilFactory { 14 | public: 15 | /** 16 | * Creates a default TimeUtil. 17 | */ 18 | static TimeUtil create(); 19 | 20 | /** 21 | * Creates a TimeUtil with custom SettledUtil params. See SettledUtil docs. 22 | */ 23 | static TimeUtil withSettledUtilParams(double iatTargetError = 50, 24 | double iatTargetDerivative = 5, 25 | QTime iatTargetTime = 250_ms); 26 | }; 27 | } // namespace okapi 28 | -------------------------------------------------------------------------------- /include/okapi/impl/device/button/controllerButton.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "api.h" 11 | #include "okapi/api/device/button/buttonBase.hpp" 12 | #include "okapi/impl/device/controllerUtil.hpp" 13 | 14 | namespace okapi { 15 | class ControllerButton : public ButtonBase { 16 | public: 17 | ControllerButton(ControllerDigital ibtn, bool iinverted = false); 18 | 19 | ControllerButton(ControllerId icontroller, ControllerDigital ibtn, bool iinverted = false); 20 | 21 | protected: 22 | pros::Controller controller; 23 | const ControllerDigital btn; 24 | 25 | virtual bool currentlyPressed() override; 26 | }; 27 | } // namespace okapi 28 | -------------------------------------------------------------------------------- /include/okapi/api/control/async/asyncController.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/closedLoopController.hpp" 11 | 12 | namespace okapi { 13 | /** 14 | * Closed-loop controller that steps on its own in another thread and automatically writes to the 15 | * output. 16 | */ 17 | template 18 | class AsyncController : public ClosedLoopController { 19 | public: 20 | /** 21 | * Blocks the current task until the controller has settled. Determining what settling means is 22 | * implementation-dependent. 23 | */ 24 | virtual void waitUntilSettled() = 0; 25 | }; 26 | } // namespace okapi 27 | -------------------------------------------------------------------------------- /include/okapi/api/util/supplier.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include 11 | 12 | namespace okapi { 13 | /** 14 | * A supplier of instances of T. 15 | * 16 | * @tparam T the type to supply 17 | */ 18 | template class Supplier { 19 | public: 20 | explicit Supplier(std::function ifunc) : func(ifunc) { 21 | } 22 | 23 | virtual ~Supplier() = default; 24 | 25 | /** 26 | * Get an instance of type T. This is usually a new instance, but it does not have to be. 27 | * @return an instance of T 28 | */ 29 | T get() const { 30 | return func(); 31 | } 32 | 33 | protected: 34 | std::function func; 35 | }; 36 | } // namespace okapi 37 | -------------------------------------------------------------------------------- /include/okapi/pathfinder/include/pathfinder/trajectory.h: -------------------------------------------------------------------------------- 1 | #ifndef PATHFINDER_TRAJECTORY_H_DEF 2 | #define PATHFINDER_TRAJECTORY_H_DEF 3 | 4 | #include "okapi/pathfinder/include/pathfinder/lib.h" 5 | #include "okapi/pathfinder/include/pathfinder/structs.h" 6 | 7 | CAPI int pathfinder_prepare(Waypoint *path, int path_length, void (*fit)(Waypoint,Waypoint,Spline*), int sample_count, double dt, 8 | double max_velocity, double max_acceleration, double max_jerk, TrajectoryCandidate *cand); 9 | CAPI int pathfinder_generate(TrajectoryCandidate *c, Segment *segments); 10 | 11 | CAPI void pf_trajectory_copy(Segment *src, Segment *dest, int length); 12 | 13 | CAPI TrajectoryInfo pf_trajectory_prepare(TrajectoryConfig c); 14 | CAPI int pf_trajectory_create(TrajectoryInfo info, TrajectoryConfig c, Segment *seg); 15 | CAPI int pf_trajectory_fromSecondOrderFilter(int filter_1_l, int filter_2_l, 16 | double dt, double u, double v, double impulse, int len, Segment *t); 17 | 18 | #endif -------------------------------------------------------------------------------- /include/okapi/api/chassis/model/readOnlyChassisModel.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/coreProsAPI.hpp" 11 | #include 12 | 13 | namespace okapi { 14 | /** 15 | * A version of the ChassisModel that only supports read methods, such as querying sensor values. 16 | * This class does not let you write to motors, so it supports having multiple owners and as a 17 | * result copying is enabled. 18 | */ 19 | class ReadOnlyChassisModel { 20 | public: 21 | virtual ~ReadOnlyChassisModel(); 22 | 23 | /** 24 | * Read the sensors. 25 | * 26 | * @return sensor readings (format is implementation dependent) 27 | */ 28 | virtual std::valarray getSensorVals() const = 0; 29 | }; 30 | } // namespace okapi 31 | -------------------------------------------------------------------------------- /include/display/lv_misc/lv_trigo.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_trig.h 3 | * Basic trigonometric integer functions 4 | */ 5 | 6 | #ifndef LV_TRIGO_H 7 | #define LV_TRIGO_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | #define LV_TRIGO_SIN_MAX 32767 22 | #define LV_TRIGO_SHIFT 15 /* >> LV_TRIGO_SHIFT to normalize*/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /********************** 29 | * GLOBAL PROTOTYPES 30 | **********************/ 31 | 32 | /** 33 | * Return with sinus of an angle 34 | * @param angle 35 | * @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767 36 | */ 37 | int16_t lv_trigo_sin(int16_t angle); 38 | 39 | /********************** 40 | * MACROS 41 | **********************/ 42 | 43 | #ifdef __cplusplus 44 | } /* extern "C" */ 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /include/okapi/api/filter/passthroughFilter.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/filter/filter.hpp" 11 | 12 | namespace okapi { 13 | class PassthroughFilter : public Filter { 14 | public: 15 | /** 16 | * A simple filter that does no filtering and just passes the input through. 17 | */ 18 | PassthroughFilter(); 19 | 20 | /** 21 | * Filters a value, like a sensor reading. 22 | * 23 | * @param ireading new measurement 24 | * @return filtered result 25 | */ 26 | double filter(double ireading) override; 27 | 28 | /** 29 | * Returns the previous output from filter. 30 | * 31 | * @return the previous output from filter 32 | */ 33 | double getOutput() const override; 34 | 35 | protected: 36 | double lastOutput = 0; 37 | }; 38 | } // namespace okapi 39 | -------------------------------------------------------------------------------- /include/okapi/api/units/QFrequency.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/RQuantity.hpp" 17 | 18 | namespace okapi { 19 | QUANTITY_TYPE(0, 0, -1, 0, QFrequency) 20 | 21 | constexpr QFrequency Hz(1.0); 22 | 23 | inline namespace literals { 24 | constexpr QFrequency operator"" _Hz(long double x) { 25 | return QFrequency(x); 26 | } 27 | constexpr QFrequency operator"" _Hz(unsigned long long int x) { 28 | return QFrequency(static_cast(x)); 29 | } 30 | } // namespace literals 31 | } // namespace okapi 32 | -------------------------------------------------------------------------------- /include/display/licence.txt: -------------------------------------------------------------------------------- 1 | MIT licence 2 | Copyright (c) 2016 Gábor Kiss-Vámosi 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /include/okapi/pathfinder/include/pathfinder/io.h: -------------------------------------------------------------------------------- 1 | #ifndef PATHFINDER_IO_H_DEF 2 | #define PATHFINDER_IO_H_DEF 3 | 4 | #include 5 | #include 6 | #include "okapi/pathfinder/include/pathfinder/structs.h" 7 | #include 8 | #include "okapi/pathfinder/include/pathfinder/lib.h" 9 | 10 | #define CSV_LEADING_STRING "dt,x,y,position,velocity,acceleration,jerk,heading\n" 11 | 12 | CAPI void intToBytes(int n, char *bytes); 13 | CAPI int bytesToInt(char *bytes); 14 | CAPI void longToBytes(unsigned long long n, char *bytes); 15 | CAPI unsigned long long bytesToLong(char *bytes); 16 | CAPI double longToDouble(unsigned long long l); 17 | CAPI unsigned long long doubleToLong(double d); 18 | CAPI void doubleToBytes(double n, char *bytes); 19 | CAPI double bytesToDouble(char *bytes); 20 | 21 | CAPI void pathfinder_serialize(FILE *fp, Segment *trajectory, int trajectory_length); 22 | CAPI int pathfinder_deserialize(FILE *fp, Segment *target); 23 | 24 | CAPI void pathfinder_serialize_csv(FILE *fp, Segment *trajectory, int trajectory_length); 25 | CAPI int pathfinder_deserialize_csv(FILE *fp, Segment *target); 26 | 27 | #endif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Joseph Spencer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /include/display/lv_misc/lv_math.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file math_base.h 3 | * 4 | */ 5 | 6 | #ifndef LV_MATH_H 7 | #define LV_MATH_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | #define LV_MATH_MIN(a, b) (a < b ? a : b) 23 | #define LV_MATH_MAX(a, b) (a > b ? a : b) 24 | #define LV_MATH_ABS(x) ((x) > 0 ? (x) : (-(x))) 25 | 26 | /********************** 27 | * TYPEDEFS 28 | **********************/ 29 | 30 | /********************** 31 | * GLOBAL PROTOTYPES 32 | **********************/ 33 | /** 34 | * Convert a number to string 35 | * @param num a number 36 | * @param buf pointer to a `char` buffer. The result will be stored here (max 10 37 | * elements) 38 | * @return same as `buf` (just for convenience) 39 | */ 40 | char *lv_math_num_to_str(int32_t num, char *buf); 41 | 42 | /********************** 43 | * MACROS 44 | **********************/ 45 | 46 | #ifdef __cplusplus 47 | } /* extern "C" */ 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /include/okapi/pathfinder/include/pathfinder/structs.h: -------------------------------------------------------------------------------- 1 | #ifndef PATHFINDER_STRUCT_H_DEF 2 | #define PATHFINDER_STRUCT_H_DEF 3 | 4 | #include "okapi/pathfinder/include/pathfinder/lib.h" 5 | 6 | CAPI typedef struct { 7 | double x, y, angle; 8 | } Waypoint; 9 | 10 | CAPI typedef struct { 11 | double a, b, c, d, e; 12 | double x_offset, y_offset, angle_offset, knot_distance, arc_length; 13 | } Spline; 14 | 15 | CAPI typedef struct { 16 | double x, y; 17 | } Coord; 18 | 19 | CAPI typedef struct { 20 | double dt, x, y, position, velocity, acceleration, jerk, heading; 21 | } Segment; 22 | 23 | CAPI typedef struct { 24 | double dt, max_v, max_a, max_j, src_v, src_theta, dest_pos, dest_v, dest_theta; 25 | int sample_count; 26 | } TrajectoryConfig; 27 | 28 | CAPI typedef struct { 29 | int filter1, filter2, length; 30 | double dt, u, v, impulse; 31 | } TrajectoryInfo; 32 | 33 | CAPI typedef struct { 34 | Spline *saptr; 35 | double *laptr; 36 | double totalLength; 37 | int length; 38 | int path_length; 39 | TrajectoryInfo info; 40 | TrajectoryConfig config; 41 | } TrajectoryCandidate; 42 | 43 | #endif -------------------------------------------------------------------------------- /include/okapi/impl/device/rotarysensor/potentiometer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "api.h" 11 | #include "okapi/api/device/rotarysensor/rotarySensor.hpp" 12 | 13 | namespace okapi { 14 | class Potentiometer : public RotarySensor { 15 | public: 16 | Potentiometer(std::uint8_t iport); 17 | 18 | virtual ~Potentiometer(); 19 | 20 | /** 21 | * Get the current sensor value. 22 | * 23 | * @return the current sensor value, or ``PROS_ERR`` on a failure. 24 | */ 25 | virtual double get() const override; 26 | 27 | /** 28 | * Get the sensor value for use in a control loop. This method might be automatically called in 29 | * another thread by the controller. 30 | * 31 | * @return the current sensor value, or ``PROS_ERR`` on a failure. 32 | */ 33 | virtual double controllerGet() override; 34 | 35 | protected: 36 | pros::ADIPotentiometer pot; 37 | }; 38 | } // namespace okapi 39 | -------------------------------------------------------------------------------- /include/okapi/api/units/QArea.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/QLength.hpp" 17 | #include "okapi/api/units/RQuantity.hpp" 18 | 19 | namespace okapi { 20 | QUANTITY_TYPE(0, 2, 0, 0, QArea) 21 | 22 | constexpr QArea kilometer2 = kilometer * kilometer; 23 | constexpr QArea meter2 = meter * meter; 24 | constexpr QArea decimeter2 = decimeter * decimeter; 25 | constexpr QArea centimeter2 = centimeter * centimeter; 26 | constexpr QArea millimeter2 = millimeter * millimeter; 27 | constexpr QArea inch2 = inch * inch; 28 | constexpr QArea foot2 = foot * foot; 29 | constexpr QArea mile2 = mile * mile; 30 | } // namespace okapi 31 | -------------------------------------------------------------------------------- /include/okapi/impl/device/motor/adiMotor.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "api.h" 11 | #include "okapi/api/control/controllerOutput.hpp" 12 | 13 | namespace okapi { 14 | class ADIMotor : public ControllerOutput { 15 | public: 16 | ADIMotor(std::uint8_t iport, bool ireverse = false); 17 | 18 | /** 19 | * Set the voltage to the motor. 20 | * 21 | * @param ivoltage voltage 22 | */ 23 | virtual void moveVoltage(std::int32_t ivoltage) const; 24 | 25 | /** 26 | * Writes the value of the controller output. This method might be automatically called in another 27 | * thread by the controller. The range of input values is expected to be [-1, 1]. 28 | * 29 | * @param ivalue the controller's output in the range [-1, 1] 30 | */ 31 | virtual void controllerSet(double ivalue) override; 32 | 33 | protected: 34 | const pros::ADIMotor motor; 35 | const std::int8_t reversed; 36 | }; 37 | } // namespace okapi 38 | -------------------------------------------------------------------------------- /include/okapi/api/units/QAngularSpeed.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/QAngle.hpp" 17 | #include "okapi/api/units/QTime.hpp" 18 | #include "okapi/api/units/RQuantity.hpp" 19 | 20 | namespace okapi { 21 | QUANTITY_TYPE(0, 0, -1, 1, QAngularSpeed) 22 | 23 | constexpr QAngularSpeed radps = radian / second; 24 | constexpr QAngularSpeed rpm = (360 * degree) / minute; 25 | 26 | inline namespace literals { 27 | constexpr QAngularSpeed operator"" _rpm(long double x) { 28 | return x * rpm; 29 | } 30 | constexpr QAngularSpeed operator"" _rpm(unsigned long long int x) { 31 | return static_cast(x) * rpm; 32 | } 33 | } // namespace literals 34 | } // namespace okapi 35 | -------------------------------------------------------------------------------- /include/okapi/api/filter/emaFilter.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/filter/filter.hpp" 11 | 12 | namespace okapi { 13 | class EmaFilter : public Filter { 14 | public: 15 | /** 16 | * Exponential moving average filter. 17 | * 18 | * @param ialpha alpha gain 19 | */ 20 | explicit EmaFilter(double ialpha); 21 | 22 | /** 23 | * Filters a value, like a sensor reading. 24 | * 25 | * @param reading new measurement 26 | * @return filtered result 27 | */ 28 | double filter(double ireading) override; 29 | 30 | /** 31 | * Returns the previous output from filter. 32 | * 33 | * @return the previous output from filter 34 | */ 35 | double getOutput() const override; 36 | 37 | /** 38 | * Set filter gains. 39 | * 40 | * @param ialpha alpha gain 41 | */ 42 | virtual void setGains(double ialpha); 43 | 44 | protected: 45 | double alpha; 46 | double output = 0; 47 | double lastOutput = 0; 48 | }; 49 | } // namespace okapi 50 | -------------------------------------------------------------------------------- /include/display/lv_themes/lv_theme_alien.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_theme_alien.h 3 | * 4 | */ 5 | 6 | #ifndef LV_THEME_ALIEN_H 7 | #define LV_THEME_ALIEN_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "display/lv_conf.h" 17 | 18 | #if USE_LV_THEME_ALIEN 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /********************** 29 | * GLOBAL PROTOTYPES 30 | **********************/ 31 | 32 | /** 33 | * Initialize the alien theme 34 | * @param hue [0..360] hue value from HSV color space to define the theme's base 35 | * color 36 | * @param font pointer to a font (NULL to use the default) 37 | * @return pointer to the initialized theme 38 | */ 39 | lv_theme_t *lv_theme_alien_init(uint16_t hue, lv_font_t *font); 40 | /** 41 | * Get a pointer to the theme 42 | * @return pointer to the theme 43 | */ 44 | lv_theme_t *lv_theme_get_alien(void); 45 | 46 | /********************** 47 | * MACROS 48 | **********************/ 49 | 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | } /* extern "C" */ 54 | #endif 55 | 56 | #endif /*LV_THEME_ALIEN_H*/ 57 | -------------------------------------------------------------------------------- /include/display/lv_themes/lv_theme_templ.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_theme_templ.h 3 | * 4 | */ 5 | 6 | #ifndef LV_THEME_TEMPL_H 7 | #define LV_THEME_TEMPL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "display/lv_conf.h" 17 | 18 | #if USE_LV_THEME_TEMPL 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /********************** 29 | * GLOBAL PROTOTYPES 30 | **********************/ 31 | 32 | /** 33 | * Initialize the templ theme 34 | * @param hue [0..360] hue value from HSV color space to define the theme's base 35 | * color 36 | * @param font pointer to a font (NULL to use the default) 37 | * @return pointer to the initialized theme 38 | */ 39 | lv_theme_t *lv_theme_templ_init(uint16_t hue, lv_font_t *font); 40 | 41 | /** 42 | * Get a pointer to the theme 43 | * @return pointer to the theme 44 | */ 45 | lv_theme_t *lv_theme_get_templ(void); 46 | 47 | /********************** 48 | * MACROS 49 | **********************/ 50 | 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } /* extern "C" */ 55 | #endif 56 | 57 | #endif /*LV_THEME_TEMPL_H*/ 58 | -------------------------------------------------------------------------------- /include/okapi/api/units/QVolume.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/QArea.hpp" 17 | #include "okapi/api/units/QLength.hpp" 18 | #include "okapi/api/units/RQuantity.hpp" 19 | 20 | namespace okapi { 21 | QUANTITY_TYPE(0, 3, 0, 0, QVolume) 22 | 23 | constexpr QVolume kilometer3 = kilometer2 * kilometer; 24 | constexpr QVolume meter3 = meter2 * meter; 25 | constexpr QVolume decimeter3 = decimeter2 * decimeter; 26 | constexpr QVolume centimeter3 = centimeter2 * centimeter; 27 | constexpr QVolume millimeter3 = millimeter2 * millimeter; 28 | constexpr QVolume inch3 = inch2 * inch; 29 | constexpr QVolume foot3 = foot2 * foot; 30 | constexpr QVolume mile3 = mile2 * mile; 31 | constexpr QVolume litre = decimeter3; 32 | } // namespace okapi 33 | -------------------------------------------------------------------------------- /include/okapi/api/control/async/asyncPosPidController.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/async/asyncPositionController.hpp" 11 | #include "okapi/api/control/async/asyncWrapper.hpp" 12 | #include "okapi/api/control/controllerInput.hpp" 13 | #include "okapi/api/control/controllerOutput.hpp" 14 | #include "okapi/api/control/iterative/iterativePosPidController.hpp" 15 | #include "okapi/api/util/timeUtil.hpp" 16 | #include 17 | 18 | namespace okapi { 19 | class AsyncPosPIDController : public AsyncWrapper, 20 | public AsyncPositionController { 21 | public: 22 | AsyncPosPIDController( 23 | const std::shared_ptr> &iinput, 24 | const std::shared_ptr> &ioutput, 25 | const TimeUtil &itimeUtil, 26 | double ikP, 27 | double ikI, 28 | double ikD, 29 | double ikBias = 0, 30 | std::unique_ptr iderivativeFilter = std::make_unique()); 31 | }; 32 | } // namespace okapi 33 | -------------------------------------------------------------------------------- /include/okapi/impl/control/util/settledUtilFactory.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/util/settledUtil.hpp" 11 | #include 12 | 13 | namespace okapi { 14 | class SettledUtilFactory { 15 | public: 16 | /** 17 | * A utility class to determine if a control loop has settled based on error. A control loop is 18 | * settled if the error is within atTargetError for atTargetTime. 19 | * 20 | * @param iatTargetError minimum error to be considered settled 21 | * @param iatTargetDerivative minimum error derivative to be considered settled 22 | * @param iatTargetTime minimum time within atTargetError to be considered settled 23 | */ 24 | static SettledUtil 25 | create(double iatTargetError = 50, double iatTargetDerivative = 5, QTime iatTargetTime = 250_ms); 26 | static std::unique_ptr createPtr(double iatTargetError = 50, 27 | double iatTargetDerivative = 5, 28 | QTime iatTargetTime = 250_ms); 29 | }; 30 | } // namespace okapi 31 | -------------------------------------------------------------------------------- /include/okapi/api/control/async/asyncVelPidController.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/async/asyncVelocityController.hpp" 11 | #include "okapi/api/control/async/asyncWrapper.hpp" 12 | #include "okapi/api/control/controllerInput.hpp" 13 | #include "okapi/api/control/controllerOutput.hpp" 14 | #include "okapi/api/control/iterative/iterativeVelPidController.hpp" 15 | #include "okapi/api/util/timeUtil.hpp" 16 | #include 17 | 18 | namespace okapi { 19 | class AsyncVelPIDController : public AsyncWrapper, 20 | public AsyncVelocityController { 21 | public: 22 | AsyncVelPIDController( 23 | const std::shared_ptr> &iinput, 24 | const std::shared_ptr> &ioutput, 25 | const TimeUtil &itimeUtil, 26 | double ikP, 27 | double ikD, 28 | double ikF, 29 | double ikSF, 30 | std::unique_ptr ivelMath, 31 | std::unique_ptr iderivativeFilter = std::make_unique()); 32 | }; 33 | } // namespace okapi 34 | -------------------------------------------------------------------------------- /include/okapi/impl/device/rotarysensor/adiEncoder.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "api.h" 11 | #include "okapi/api/device/rotarysensor/continuousRotarySensor.hpp" 12 | 13 | namespace okapi { 14 | class ADIEncoder : public ContinuousRotarySensor { 15 | public: 16 | ADIEncoder(std::uint8_t iportTop, std::uint8_t iportBottom, bool ireversed = false); 17 | 18 | /** 19 | * Get the current sensor value. 20 | * 21 | * @return the current sensor value, or ``PROS_ERR`` on a failure. 22 | */ 23 | virtual double get() const override; 24 | 25 | /** 26 | * Reset the sensor to zero. 27 | * 28 | * @return 1 on success, PROS_ERR on fail 29 | */ 30 | virtual std::int32_t reset() override; 31 | 32 | /** 33 | * Get the sensor value for use in a control loop. This method might be automatically called in 34 | * another thread by the controller. 35 | * 36 | * @return the current sensor value, or ``PROS_ERR`` on a failure. 37 | */ 38 | virtual double controllerGet() override; 39 | 40 | protected: 41 | pros::ADIEncoder enc; 42 | }; 43 | } // namespace okapi 44 | -------------------------------------------------------------------------------- /include/okapi/api/units/QAngle.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/RQuantity.hpp" 17 | #include 18 | 19 | namespace okapi { 20 | QUANTITY_TYPE(0, 0, 0, 1, QAngle) 21 | 22 | constexpr QAngle radian(1.0); 23 | constexpr QAngle degree = static_cast(2_pi / 360.0) * radian; 24 | 25 | inline namespace literals { 26 | constexpr QAngle operator"" _rad(long double x) { 27 | return QAngle(x); 28 | } 29 | constexpr QAngle operator"" _rad(unsigned long long int x) { 30 | return QAngle(static_cast(x)); 31 | } 32 | constexpr QAngle operator"" _deg(long double x) { 33 | return static_cast(x) * degree; 34 | } 35 | constexpr QAngle operator"" _deg(unsigned long long int x) { 36 | return static_cast(x) * degree; 37 | } 38 | } // namespace literals 39 | } // namespace okapi 40 | -------------------------------------------------------------------------------- /include/okapi/api/coreProsAPI.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #ifdef THREADS_STD 19 | #include 20 | #define CROSSPLATFORM_THREAD_T std::thread 21 | #else 22 | #include "api.h" 23 | #define CROSSPLATFORM_THREAD_T pros::task_t 24 | #endif 25 | 26 | class CrossplatformThread { 27 | public: 28 | CrossplatformThread(void (*ptr)(void *), void *params) 29 | : 30 | #ifdef THREADS_STD 31 | thread(ptr, params) 32 | #else 33 | thread(pros::c::task_create(ptr, 34 | params, 35 | TASK_PRIORITY_DEFAULT, 36 | TASK_STACK_DEPTH_DEFAULT, 37 | "OkapiLibCrossplatformTask")) 38 | #endif 39 | { 40 | } 41 | 42 | ~CrossplatformThread() { 43 | #ifdef THREADS_STD 44 | thread.join(); 45 | #else 46 | pros::c::task_delete(thread); 47 | #endif 48 | } 49 | 50 | protected: 51 | CROSSPLATFORM_THREAD_T thread; 52 | }; 53 | -------------------------------------------------------------------------------- /include/okapi/api/filter/demaFilter.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/filter/filter.hpp" 11 | #include 12 | 13 | namespace okapi { 14 | class DemaFilter : public Filter { 15 | public: 16 | /** 17 | * Double exponential moving average filter. 18 | * 19 | * @param ialpha alpha gain 20 | * @param ibeta beta gain 21 | */ 22 | DemaFilter(double ialpha, double ibeta); 23 | 24 | /** 25 | * Filters a value, like a sensor reading. 26 | * 27 | * @param reading new measurement 28 | * @return filtered result 29 | */ 30 | double filter(double ireading) override; 31 | 32 | /** 33 | * Returns the previous output from filter. 34 | * 35 | * @return the previous output from filter 36 | */ 37 | double getOutput() const override; 38 | 39 | /** 40 | * Set filter gains. 41 | * 42 | * @param ialpha alpha gain 43 | * @param ibeta beta gain 44 | */ 45 | virtual void setGains(double ialpha, double ibeta); 46 | 47 | protected: 48 | double alpha, beta; 49 | double outputS = 0; 50 | double lastOutputS = 0; 51 | double outputB = 0; 52 | double lastOutputB = 0; 53 | }; 54 | } // namespace okapi 55 | -------------------------------------------------------------------------------- /include/okapi/impl/device/controllerUtil.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "api.h" 11 | 12 | namespace okapi { 13 | /** 14 | * Which controller role this has. 15 | */ 16 | enum class ControllerId { master = 0, partner = 1 }; 17 | 18 | /** 19 | * The analog sticks. 20 | */ 21 | enum class ControllerAnalog { leftX = 0, leftY = 1, rightX = 2, rightY = 3 }; 22 | 23 | /** 24 | * Various buttons. 25 | */ 26 | enum class ControllerDigital { 27 | L1 = 6, 28 | L2 = 7, 29 | R1 = 8, 30 | R2 = 9, 31 | up = 10, 32 | down = 11, 33 | left = 12, 34 | right = 13, 35 | X = 14, 36 | B = 15, 37 | Y = 16, 38 | A = 17 39 | }; 40 | 41 | class ControllerUtil { 42 | public: 43 | /** 44 | * Maps an `id` to the PROS enum equivalent. 45 | */ 46 | static pros::controller_id_e_t idToProsEnum(ControllerId in); 47 | 48 | /** 49 | * Maps an `analog` to the PROS enum equivalent. 50 | */ 51 | static pros::controller_analog_e_t analogToProsEnum(ControllerAnalog in); 52 | 53 | /** 54 | * Maps a `digital` to the PROS enum equivalent. 55 | */ 56 | static pros::controller_digital_e_t digitalToProsEnum(ControllerDigital in); 57 | }; 58 | } // namespace okapi 59 | -------------------------------------------------------------------------------- /include/okapi/api/units/QAcceleration.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/QLength.hpp" 17 | #include "okapi/api/units/QTime.hpp" 18 | #include "okapi/api/units/RQuantity.hpp" 19 | 20 | namespace okapi { 21 | QUANTITY_TYPE(0, 1, -2, 0, QAcceleration) 22 | 23 | constexpr QAcceleration mps2 = meter / (second * second); 24 | constexpr QAcceleration G = 9.80665 * mps2; 25 | 26 | inline namespace literals { 27 | constexpr QAcceleration operator"" _mps2(long double x) { 28 | return QAcceleration(x); 29 | } 30 | constexpr QAcceleration operator"" _mps2(unsigned long long int x) { 31 | return QAcceleration(static_cast(x)); 32 | } 33 | constexpr QAcceleration operator"" _G(long double x) { 34 | return static_cast(x) * G; 35 | } 36 | constexpr QAcceleration operator"" _G(unsigned long long int x) { 37 | return static_cast(x) * G; 38 | } 39 | } // namespace literals 40 | } // namespace okapi 41 | -------------------------------------------------------------------------------- /include/display/lv_core/lv_vdb.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_vdb.h 3 | * 4 | */ 5 | 6 | #ifndef LV_VDB_H 7 | #define LV_VDB_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "display/lv_conf.h" 17 | 18 | #if LV_VDB_SIZE != 0 19 | 20 | #include "display/lv_misc/lv_area.h" 21 | #include "display/lv_misc/lv_color.h" 22 | 23 | /********************* 24 | * DEFINES 25 | *********************/ 26 | 27 | /********************** 28 | * TYPEDEFS 29 | **********************/ 30 | 31 | typedef struct { 32 | lv_area_t area; 33 | lv_color_t *buf; 34 | } lv_vdb_t; 35 | 36 | /********************** 37 | * GLOBAL PROTOTYPES 38 | **********************/ 39 | 40 | /** 41 | * Get the 'vdb' variable or allocate one in LV_VDB_DOUBLE mode 42 | * @return pointer to a 'vdb' variable 43 | */ 44 | lv_vdb_t *lv_vdb_get(void); 45 | 46 | /** 47 | * Flush the content of the vdb 48 | */ 49 | void lv_vdb_flush(void); 50 | 51 | /** 52 | * In 'LV_VDB_DOUBLE' mode has to be called when 'disp_map()' 53 | * is ready with copying the map to a frame buffer. 54 | */ 55 | void lv_flush_ready(void); 56 | 57 | /********************** 58 | * MACROS 59 | **********************/ 60 | 61 | #else /*LV_VDB_SIZE != 0*/ 62 | 63 | /*Just for compatibility*/ 64 | void lv_flush_ready(void); 65 | #endif 66 | 67 | #ifdef __cplusplus 68 | } /* extern "C" */ 69 | #endif 70 | 71 | #endif /*LV_VDB_H*/ 72 | -------------------------------------------------------------------------------- /include/okapi/api/device/button/buttonBase.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/device/button/abstractButton.hpp" 11 | 12 | namespace okapi { 13 | class ButtonBase : public AbstractButton { 14 | public: 15 | explicit ButtonBase(bool iinverted = false); 16 | 17 | /** 18 | * Return whether the button is currently pressed. 19 | **/ 20 | bool isPressed() override; 21 | 22 | /** 23 | * Return whether the state of the button changed since the last time this method was called. 24 | **/ 25 | bool changed() override; 26 | 27 | /** 28 | * Return whether the state of the button changed to pressed since the last time this method was 29 | *called. 30 | **/ 31 | bool changedToPressed() override; 32 | 33 | /** 34 | * Return whether the state of the button to not pressed since the last time this method was 35 | *called. 36 | **/ 37 | bool changedToReleased() override; 38 | 39 | protected: 40 | bool inverted{false}; 41 | bool wasPressedLast_c{false}; 42 | bool wasPressedLast_ctp{false}; 43 | bool wasPressedLast_ctr{false}; 44 | 45 | virtual bool currentlyPressed() = 0; 46 | 47 | private: 48 | bool changedImpl(bool &prevState); 49 | }; 50 | } // namespace okapi 51 | -------------------------------------------------------------------------------- /include/display/lv_hal/lv_hal_tick.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_hal_tick.h 3 | * Provide access to the system tick with 1 millisecond resolution 4 | */ 5 | 6 | #ifndef LV_HAL_TICK_H 7 | #define LV_HAL_TICK_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include 17 | #include 18 | 19 | /********************* 20 | * DEFINES 21 | *********************/ 22 | #ifndef LV_ATTRIBUTE_TICK_INC 23 | #define LV_ATTRIBUTE_TICK_INC 24 | #endif 25 | 26 | /********************** 27 | * TYPEDEFS 28 | **********************/ 29 | 30 | /********************** 31 | * GLOBAL PROTOTYPES 32 | **********************/ 33 | 34 | /** 35 | * You have to call this function periodically 36 | * @param tick_period the call period of this function in milliseconds 37 | */ 38 | LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period); 39 | 40 | /** 41 | * Get the elapsed milliseconds since start up 42 | * @return the elapsed milliseconds 43 | */ 44 | uint32_t lv_tick_get(void); 45 | 46 | /** 47 | * Get the elapsed milliseconds science a previous time stamp 48 | * @param prev_tick a previous time stamp (return value of systick_get() ) 49 | * @return the elapsed milliseconds since 'prev_tick' 50 | */ 51 | uint32_t lv_tick_elaps(uint32_t prev_tick); 52 | 53 | /********************** 54 | * MACROS 55 | **********************/ 56 | 57 | #ifdef __cplusplus 58 | } /* extern "C" */ 59 | #endif 60 | 61 | #endif /*LV_HAL_TICK_H*/ 62 | -------------------------------------------------------------------------------- /include/okapi/api/device/button/abstractButton.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/controllerInput.hpp" 11 | 12 | namespace okapi { 13 | class AbstractButton : public ControllerInput { 14 | public: 15 | virtual ~AbstractButton(); 16 | 17 | /** 18 | * Return whether the button is currently pressed. 19 | **/ 20 | virtual bool isPressed() = 0; 21 | 22 | /** 23 | * Return whether the state of the button changed since the last time this method was 24 | * called. 25 | **/ 26 | virtual bool changed() = 0; 27 | 28 | /** 29 | * Return whether the state of the button changed to being pressed since the last time this method 30 | * was called. 31 | **/ 32 | virtual bool changedToPressed() = 0; 33 | 34 | /** 35 | * Return whether the state of the button to being not pressed changed since the last time this 36 | * method was called. 37 | **/ 38 | virtual bool changedToReleased() = 0; 39 | 40 | /** 41 | * Get the sensor value for use in a control loop. This method might be automatically called in 42 | * another thread by the controller. 43 | * 44 | * @return the current sensor value. This is the same as the output of the pressed() method. 45 | */ 46 | virtual bool controllerGet() override; 47 | }; 48 | } // namespace okapi 49 | -------------------------------------------------------------------------------- /include/okapi/api/filter/averageFilter.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/filter/filter.hpp" 11 | #include 12 | #include 13 | 14 | namespace okapi { 15 | /** 16 | * A filter which returns the average of a list of values. 17 | * 18 | * @tparam n number of taps in the filter 19 | */ 20 | template class AverageFilter : public Filter { 21 | public: 22 | /** 23 | * Averaging filter. 24 | */ 25 | AverageFilter() = default; 26 | 27 | /** 28 | * Filters a value, like a sensor reading. 29 | * 30 | * @param ireading new measurement 31 | * @return filtered result 32 | */ 33 | double filter(const double ireading) override { 34 | data[index++] = ireading; 35 | if (index >= n) { 36 | index = 0; 37 | } 38 | 39 | output = 0.0; 40 | for (size_t i = 0; i < n; i++) 41 | output += data[i]; 42 | output /= (double)n; 43 | 44 | return output; 45 | } 46 | 47 | /** 48 | * Returns the previous output from filter. 49 | * 50 | * @return the previous output from filter 51 | */ 52 | double getOutput() const override { 53 | return output; 54 | } 55 | 56 | protected: 57 | std::array data{0}; 58 | std::size_t index = 0; 59 | double output = 0; 60 | }; 61 | } // namespace okapi 62 | -------------------------------------------------------------------------------- /include/okapi/impl/filter/velMathFactory.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/filter/velMath.hpp" 11 | #include 12 | 13 | namespace okapi { 14 | class VelMathFactory { 15 | public: 16 | /** 17 | * Velocity math helper. Calculates filtered velocity. Throws a std::invalid_argument exception 18 | * if iticksPerRev is zero. Averages the last two readings. 19 | * 20 | * @param iticksPerRev number of ticks per revolution (or whatever units you are using) 21 | */ 22 | static VelMath create(double iticksPerRev, QTime isampleTime = 0_ms); 23 | 24 | static std::unique_ptr createPtr(double iticksPerRev, QTime isampleTime = 0_ms); 25 | 26 | /** 27 | * Velocity math helper. Calculates filtered velocity. Throws a std::invalid_argument exception 28 | * if iticksPerRev is zero. 29 | * 30 | * @param iticksPerRev number of ticks per revolution (or whatever units you are using) 31 | * @param ifilter filter used for filtering the calculated velocity 32 | */ 33 | static VelMath 34 | create(double iticksPerRev, std::shared_ptr ifilter, QTime isampleTime = 0_ms); 35 | 36 | static std::unique_ptr 37 | createPtr(double iticksPerRev, std::shared_ptr ifilter, QTime isampleTime = 0_ms); 38 | 39 | static std::unique_ptr createPtr(const VelMathArgs &ivelMathArgs); 40 | }; 41 | } // namespace okapi 42 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | ######################### User configurable parameters ######################### 3 | # filename extensions 4 | CEXTS:=c 5 | ASMEXTS:=s S 6 | CXXEXTS:=cpp c++ cc 7 | 8 | # probably shouldn't modify these, but you may need them below 9 | ROOT=. 10 | FWDIR:=$(ROOT)/firmware 11 | BINDIR=$(ROOT)/bin 12 | SRCDIR=$(ROOT)/src 13 | INCDIR=$(ROOT)/include 14 | 15 | WARNFLAGS+= 16 | EXTRA_CFLAGS= 17 | EXTRA_CXXFLAGS= 18 | 19 | # Set to 1 to enable hot/cold linking 20 | USE_PACKAGE:=0 21 | 22 | # Set this to 1 to add additional rules to compile your project as a PROS library template 23 | IS_LIBRARY:=1 24 | # TODO: CHANGE THIS! 25 | LIBNAME:=screenlib 26 | VERSION:=1.0.1 27 | # EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/unpublishedfile.c 28 | # this line excludes opcontrol.c and similar files 29 | EXCLUDE_SRC_FROM_LIB+=$(foreach file, $(SRCDIR)/opcontrol $(SRCDIR)/initialize $(SRCDIR)/autonomous,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext))) 30 | 31 | # files that get distributed to every user (beyond your source archive) - add 32 | # whatever files you want here. This line is configured to add all header files 33 | # that are in the the include directory get exported 34 | TEMPLATE_FILES=$(INCDIR)/screen/**/*.h $(INCDIR)/screen/**/*.hpp 35 | 36 | .DEFAULT_GOAL=quick 37 | 38 | ################################################################################ 39 | ################################################################################ 40 | ########## Nothing below this line should be edited by typical users ########### 41 | -include ./common.mk 42 | -------------------------------------------------------------------------------- /include/okapi/api/util/timeUtil.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/util/settledUtil.hpp" 11 | #include "okapi/api/util/abstractRate.hpp" 12 | #include "okapi/api/util/abstractTimer.hpp" 13 | #include "okapi/api/util/supplier.hpp" 14 | 15 | namespace okapi { 16 | /** 17 | * Utility class for holding an AbstractTimer, AbstractRate, and SettledUtil together in one 18 | * class since they are commonly used together. 19 | */ 20 | class TimeUtil { 21 | public: 22 | TimeUtil(const Supplier> &itimerSupplier, 23 | const Supplier> &irateSupplier, 24 | const Supplier> &isettledUtilSupplier); 25 | 26 | std::unique_ptr getTimer() const; 27 | 28 | std::unique_ptr getRate() const; 29 | 30 | std::unique_ptr getSettledUtil() const; 31 | 32 | const Supplier> getTimerSupplier() const; 33 | 34 | const Supplier> getRateSupplier() const; 35 | 36 | const Supplier> getSettledUtilSupplier() const; 37 | 38 | protected: 39 | Supplier> timerSupplier; 40 | Supplier> rateSupplier; 41 | Supplier> settledUtilSupplier; 42 | }; 43 | } // namespace okapi 44 | -------------------------------------------------------------------------------- /include/okapi/api/units/QForce.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/QAcceleration.hpp" 17 | #include "okapi/api/units/QMass.hpp" 18 | #include "okapi/api/units/RQuantity.hpp" 19 | 20 | namespace okapi { 21 | QUANTITY_TYPE(1, 1, -2, 0, QForce) 22 | 23 | constexpr QForce newton = (kg * meter) / (second * second); 24 | constexpr QForce poundforce = pound * G; 25 | constexpr QForce kilopond = kg * G; 26 | 27 | inline namespace literals { 28 | constexpr QForce operator"" _n(long double x) { 29 | return QForce(x); 30 | } 31 | constexpr QForce operator"" _n(unsigned long long int x) { 32 | return QForce(static_cast(x)); 33 | } 34 | constexpr QForce operator"" _lbf(long double x) { 35 | return static_cast(x) * poundforce; 36 | } 37 | constexpr QForce operator"" _lbf(unsigned long long int x) { 38 | return static_cast(x) * poundforce; 39 | } 40 | constexpr QForce operator"" _kp(long double x) { 41 | return static_cast(x) * kilopond; 42 | } 43 | constexpr QForce operator"" _kp(unsigned long long int x) { 44 | return static_cast(x) * kilopond; 45 | } 46 | } // namespace literals 47 | } // namespace okapi 48 | -------------------------------------------------------------------------------- /include/okapi/impl/util/rate.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/util/abstractRate.hpp" 11 | 12 | namespace okapi { 13 | class Rate : public AbstractRate { 14 | public: 15 | Rate(); 16 | 17 | /** 18 | * Delay the current task such that it runs at the given frequency. The first delay will run for 19 | * 1000/(ihz). Subsequent delays will adjust according to the previous runtime of the task. 20 | * 21 | * @param ihz the frequency 22 | */ 23 | void delay(QFrequency ihz) override; 24 | 25 | /** 26 | * Delay the current task such that it runs every ihz ms. The first delay will run for 27 | * 1000/(ihz). Subsequent delays will adjust according to the previous runtime of the task. 28 | * 29 | * @param ihz the frequency in ms 30 | */ 31 | void delay(int ihz) override; 32 | 33 | /** 34 | * Delay the current task until itime has passed. This method can be used by periodic tasks to 35 | * ensure a consistent execution frequency. 36 | * 37 | * @param itime the time period 38 | */ 39 | void delayUntil(QTime itime) override; 40 | 41 | /** 42 | * Delay the current task until ims milliseconds have passed. This method can be used by 43 | * periodic tasks to ensure a consistent execution frequency. 44 | * 45 | * @param ims the time period 46 | */ 47 | void delayUntil(uint32_t ims) override; 48 | 49 | protected: 50 | std::uint32_t lastTime{0}; 51 | }; 52 | } // namespace okapi 53 | -------------------------------------------------------------------------------- /include/okapi/api/units/QSpeed.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/QLength.hpp" 17 | #include "okapi/api/units/QTime.hpp" 18 | #include "okapi/api/units/RQuantity.hpp" 19 | 20 | namespace okapi { 21 | QUANTITY_TYPE(0, 1, -1, 0, QSpeed) 22 | 23 | constexpr QSpeed mps = meter / second; 24 | constexpr QSpeed miph = mile / hour; 25 | constexpr QSpeed kmph = kilometer / hour; 26 | 27 | inline namespace literals { 28 | constexpr QSpeed operator"" _mps(long double x) { 29 | return static_cast(x) * mps; 30 | } 31 | constexpr QSpeed operator"" _miph(long double x) { 32 | return static_cast(x) * mile / hour; 33 | } 34 | constexpr QSpeed operator"" _kmph(long double x) { 35 | return static_cast(x) * kilometer / hour; 36 | } 37 | constexpr QSpeed operator"" _mps(unsigned long long int x) { 38 | return static_cast(x) * mps; 39 | } 40 | constexpr QSpeed operator"" _miph(unsigned long long int x) { 41 | return static_cast(x) * mile / hour; 42 | } 43 | constexpr QSpeed operator"" _kmph(unsigned long long int x) { 44 | return static_cast(x) * kilometer / hour; 45 | } 46 | } // namespace literals 47 | } // namespace okapi 48 | -------------------------------------------------------------------------------- /include/okapi/impl/device/adiUltrasonic.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "api.h" 11 | #include "okapi/api/control/controllerInput.hpp" 12 | #include "okapi/api/filter/medianFilter.hpp" 13 | #include 14 | 15 | namespace okapi { 16 | class ADIUltrasonic : public ControllerInput { 17 | public: 18 | /** 19 | * An ultrasonic sensor in the ADI (3-wire) ports. Uses a 5-tap MedianFilter by default. 20 | * 21 | * @param iportTop top port 22 | * @param iportBottom bottom port 23 | */ 24 | ADIUltrasonic(std::uint8_t iportTop, std::uint8_t iportBottom); 25 | 26 | /** 27 | * An ultrasonic sensor in the ADI (3-wire) ports. 28 | * 29 | * @param iportTop top port 30 | * @param iportBottom bottom port 31 | * @param ifilter the filter to use for filtering measurements 32 | */ 33 | ADIUltrasonic(std::uint8_t iportTop, std::uint8_t iportBottom, std::unique_ptr ifilter); 34 | 35 | virtual ~ADIUltrasonic(); 36 | 37 | /** 38 | * Returns the current filtered sensor value. 39 | * 40 | * @return current value 41 | */ 42 | virtual double get(); 43 | 44 | /** 45 | * Get the sensor value for use in a control loop. This method might be automatically called in 46 | * another thread by the controller. Calls get(). 47 | */ 48 | virtual double controllerGet() override; 49 | 50 | protected: 51 | pros::ADIUltrasonic ultra; 52 | std::unique_ptr filter; 53 | }; 54 | } // namespace okapi 55 | -------------------------------------------------------------------------------- /include/okapi/api/units/QTorque.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/QForce.hpp" 17 | #include "okapi/api/units/QLength.hpp" 18 | #include "okapi/api/units/RQuantity.hpp" 19 | 20 | namespace okapi { 21 | QUANTITY_TYPE(1, 2, -2, 0, QTorque) 22 | 23 | constexpr QTorque newtonMeter = newton * meter; 24 | constexpr QTorque footPound = 1.355817948 * newtonMeter; 25 | constexpr QTorque inchPound = 0.083333333 * footPound; 26 | 27 | inline namespace literals { 28 | constexpr QTorque operator"" _nM(long double x) { 29 | return QTorque(x); 30 | } 31 | constexpr QTorque operator"" _nM(unsigned long long int x) { 32 | return QTorque(static_cast(x)); 33 | } 34 | constexpr QTorque operator"" _inLb(long double x) { 35 | return static_cast(x) * inchPound; 36 | } 37 | constexpr QTorque operator"" _inLb(unsigned long long int x) { 38 | return static_cast(x) * inchPound; 39 | } 40 | constexpr QTorque operator"" _ftLb(long double x) { 41 | return static_cast(x) * footPound; 42 | } 43 | constexpr QTorque operator"" _ftLb(unsigned long long int x) { 44 | return static_cast(x) * footPound; 45 | } 46 | } // namespace literals 47 | } // namespace okapi 48 | -------------------------------------------------------------------------------- /include/okapi/api/units/QPressure.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/QAcceleration.hpp" 17 | #include "okapi/api/units/QArea.hpp" 18 | #include "okapi/api/units/QMass.hpp" 19 | #include "okapi/api/units/RQuantity.hpp" 20 | 21 | namespace okapi { 22 | QUANTITY_TYPE(1, -1, -2, 0, QPressure) 23 | 24 | constexpr QPressure pascal(1.0); 25 | constexpr QPressure bar = 100000 * pascal; 26 | constexpr QPressure psi = pound * G / inch2; 27 | 28 | inline namespace literals { 29 | constexpr QPressure operator"" _Pa(long double x) { 30 | return QPressure(x); 31 | } 32 | constexpr QPressure operator"" _Pa(unsigned long long int x) { 33 | return QPressure(static_cast(x)); 34 | } 35 | constexpr QPressure operator"" _bar(long double x) { 36 | return static_cast(x) * bar; 37 | } 38 | constexpr QPressure operator"" _bar(unsigned long long int x) { 39 | return static_cast(x) * bar; 40 | } 41 | constexpr QPressure operator"" _psi(long double x) { 42 | return static_cast(x) * psi; 43 | } 44 | constexpr QPressure operator"" _psi(unsigned long long int x) { 45 | return static_cast(x) * psi; 46 | } 47 | } // namespace literals 48 | } // namespace okapi 49 | -------------------------------------------------------------------------------- /include/okapi/api/util/abstractRate.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/coreProsAPI.hpp" 11 | #include "okapi/api/units/QFrequency.hpp" 12 | #include "okapi/api/units/QTime.hpp" 13 | 14 | namespace okapi { 15 | class AbstractRate { 16 | public: 17 | virtual ~AbstractRate(); 18 | 19 | /** 20 | * Delay the current task such that it runs at the given frequency. The first delay will run for 21 | * 1000/(ihz). Subsequent delays will adjust according to the previous runtime of the task. 22 | * 23 | * @param ihz the frequency 24 | */ 25 | virtual void delay(QFrequency ihz) = 0; 26 | 27 | /** 28 | * Delay the current task such that it runs every ihz ms. The first delay will run for 29 | * 1000/(ihz). Subsequent delays will adjust according to the previous runtime of the task. 30 | * 31 | * @param ihz the frequency in ms 32 | */ 33 | virtual void delay(int ihz) = 0; 34 | 35 | /** 36 | * Delay the current task until itime has passed. This method can be used by periodic tasks to 37 | * ensure a consistent execution frequency. 38 | * 39 | * @param itime the time period 40 | */ 41 | virtual void delayUntil(QTime itime) = 0; 42 | 43 | /** 44 | * Delay the current task until ims milliseconds have passed. This method can be used by 45 | * periodic tasks to ensure a consistent execution frequency. 46 | * 47 | * @param ims the time period 48 | */ 49 | virtual void delayUntil(uint32_t ims) = 0; 50 | }; 51 | } // namespace okapi 52 | -------------------------------------------------------------------------------- /include/okapi/impl/device/rotarysensor/integratedEncoder.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "api.h" 11 | #include "okapi/api/device/rotarysensor/continuousRotarySensor.hpp" 12 | #include "okapi/impl/device/motor/motor.hpp" 13 | 14 | namespace okapi { 15 | class IntegratedEncoder : public ContinuousRotarySensor { 16 | public: 17 | /** 18 | * Integrated motor encoder. Uses the encoder inside the V5 motor. 19 | * 20 | * @param imotor the motor to use the encoder from. 21 | */ 22 | explicit IntegratedEncoder(const pros::Motor &imotor); 23 | 24 | /** 25 | * Integrated motor encoder. Uses the encoder inside the V5 motor. 26 | * 27 | * @param imotor the motor to use the encoder from. 28 | */ 29 | explicit IntegratedEncoder(const okapi::Motor &imotor); 30 | 31 | /** 32 | * Get the current sensor value. 33 | * 34 | * @return the current sensor value, or ``PROS_ERR`` on a failure. 35 | */ 36 | virtual double get() const override; 37 | 38 | /** 39 | * Reset the sensor to zero. 40 | * 41 | * @return 1 on success, PROS_ERR on fail 42 | */ 43 | virtual std::int32_t reset() override; 44 | 45 | /** 46 | * Get the sensor value for use in a control loop. This method might be automatically called in 47 | * another thread by the controller. 48 | * 49 | * @return the current sensor value, or ``PROS_ERR`` on a failure. 50 | */ 51 | virtual double controllerGet() override; 52 | 53 | protected: 54 | pros::Motor motor; 55 | }; 56 | } // namespace okapi 57 | -------------------------------------------------------------------------------- /include/okapi/api/filter/filteredControllerInput.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/controllerInput.hpp" 11 | #include "okapi/api/filter/filter.hpp" 12 | #include 13 | 14 | namespace okapi { 15 | /** 16 | * A ControllerInput with a filter built in. 17 | * 18 | * @tparam InputType the type of the ControllerInput 19 | * @tparam FilterType the type of the Filter 20 | */ 21 | template 22 | class FilteredControllerInput : public ControllerInput { 23 | public: 24 | /** 25 | * A filtered controller input. Applies a filter to the controller input. Useful if you want to 26 | * place a filter between a control input and a control loop. 27 | * 28 | * @param iinput ControllerInput type 29 | * @param ifilter Filter type 30 | */ 31 | FilteredControllerInput(std::unique_ptr> iinput, 32 | std::unique_ptr ifilter) 33 | : input(std::move(iinput)), filter(std::move(ifilter)) { 34 | } 35 | 36 | /** 37 | * Gets the sensor value for use in a control loop. This method might be automatically called in 38 | * another thread by the controller. 39 | * 40 | * @return the current filtered sensor value. 41 | */ 42 | double controllerGet() override { 43 | return filter->filter(input->controllerGet()); 44 | } 45 | 46 | protected: 47 | std::unique_ptr> input; 48 | std::unique_ptr filter; 49 | }; 50 | } // namespace okapi 51 | -------------------------------------------------------------------------------- /include/okapi/api/control/util/settledUtil.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/units/QTime.hpp" 11 | #include "okapi/api/util/abstractTimer.hpp" 12 | #include 13 | 14 | namespace okapi { 15 | class SettledUtil { 16 | public: 17 | /** 18 | * A utility class to determine if a control loop has settled based on error. A control loop is 19 | * settled if the error is within atTargetError and atTargetDerivative for atTargetTime. 20 | * 21 | * @param iatTargetError minimum error to be considered settled 22 | * @param iatTargetDerivative minimum error derivative to be considered settled 23 | * @param iatTargetTime minimum time within atTargetError to be considered settled 24 | */ 25 | explicit SettledUtil(std::unique_ptr iatTargetTimer, 26 | double iatTargetError = 50, 27 | double iatTargetDerivative = 5, 28 | QTime iatTargetTime = 250_ms); 29 | 30 | virtual ~SettledUtil(); 31 | 32 | /** 33 | * Returns whether the controller is settled. 34 | * 35 | * @param ierror current error 36 | * @return whether the controller is settled 37 | */ 38 | virtual bool isSettled(double ierror); 39 | 40 | /** 41 | * Resets the "at target" timer. 42 | */ 43 | virtual void reset(); 44 | 45 | protected: 46 | double atTargetError = 50; 47 | double atTargetDerivative = 5; 48 | QTime atTargetTime = 250_ms; 49 | std::unique_ptr atTargetTimer; 50 | double lastError = 0; 51 | }; 52 | } // namespace okapi 53 | -------------------------------------------------------------------------------- /include/api.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file api.h 3 | * 4 | * PROS API header provides high-level user functionality 5 | * 6 | * Contains declarations for use by typical VEX programmers using PROS. 7 | * 8 | * This file should not be modified by users, since it gets replaced whenever 9 | * a kernel upgrade occurs. 10 | * 11 | * Copyright (c) 2017-2018, Purdue University ACM SIGBots. 12 | * All rights reserved. 13 | * 14 | * This Source Code Form is subject to the terms of the Mozilla Public 15 | * License, v. 2.0. If a copy of the MPL was not distributed with this 16 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 17 | */ 18 | 19 | #ifndef _PROS_API_H_ 20 | #define _PROS_API_H_ 21 | 22 | #ifdef __cplusplus 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #else /* (not) __cplusplus */ 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #endif /* __cplusplus */ 41 | 42 | #define PROS_VERSION_MAJOR 3 43 | #define PROS_VERSION_MINOR 1 44 | #define PROS_VERSION_PATCH 6 45 | #define PROS_VERSION_STRING "3.1.6" 46 | 47 | #define PROS_ERR (INT32_MAX) 48 | #define PROS_ERR_F (INFINITY) 49 | 50 | #include "pros/adi.h" 51 | #include "pros/colors.h" 52 | #include "pros/llemu.h" 53 | #include "pros/misc.h" 54 | #include "pros/motors.h" 55 | #include "pros/rtos.h" 56 | #include "pros/vision.h" 57 | 58 | #ifdef __cplusplus 59 | #include "pros/adi.hpp" 60 | #include "pros/llemu.hpp" 61 | #include "pros/misc.hpp" 62 | #include "pros/motors.hpp" 63 | #include "pros/rtos.hpp" 64 | #include "pros/vision.hpp" 65 | #endif 66 | 67 | #endif // _PROS_API_H_ 68 | -------------------------------------------------------------------------------- /include/okapi/api/filter/composableFilter.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/filter/filter.hpp" 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace okapi { 17 | class ComposableFilter : public Filter { 18 | public: 19 | /** 20 | * A composable filter is a filter that consists of other filters. The input signal is passed 21 | * through each filter in sequence. The final output of this filter is the output of the last 22 | * filter. 23 | */ 24 | ComposableFilter(); 25 | 26 | /** 27 | * A composable filter is a filter that consists of other filters. The input signal is passed 28 | * through each filter in sequence. The final output of this filter is the output of the last 29 | * filter. 30 | * 31 | * @param ilist the filters to use in sequence 32 | */ 33 | ComposableFilter(const std::initializer_list> &ilist); 34 | 35 | /** 36 | * Filters a value, like a sensor reading. 37 | * 38 | * @param ireading new measurement 39 | * @return filtered result 40 | */ 41 | double filter(double ireading) override; 42 | 43 | /** 44 | * Returns the previous output from filter. 45 | * 46 | * @return the previous output from filter 47 | */ 48 | double getOutput() const override; 49 | 50 | /** 51 | * Adds a filter to the end of the sequence. 52 | * 53 | * @param ifilter the filter to add 54 | */ 55 | virtual void addFilter(const std::shared_ptr &ifilter); 56 | 57 | protected: 58 | std::vector> filters; 59 | double output = 0; 60 | }; 61 | } // namespace okapi 62 | -------------------------------------------------------------------------------- /include/okapi/impl/control/util/pidTunerFactory.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Jonathan Bayless, Team BLRS 3 | * @author Ryan Benasutti, WPI 4 | * 5 | * This Source Code Form is subject to the terms of the Mozilla Public 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 | */ 9 | #pragma once 10 | 11 | #include "okapi/api/control/util/pidTuner.hpp" 12 | #include 13 | 14 | namespace okapi { 15 | class PIDTunerFactory { 16 | public: 17 | static PIDTuner create(const std::shared_ptr> &iinput, 18 | const std::shared_ptr> &ioutput, 19 | QTime itimeout, 20 | std::int32_t igoal, 21 | double ikPMin, 22 | double ikPMax, 23 | double ikIMin, 24 | double ikIMax, 25 | double ikDMin, 26 | double ikDMax, 27 | std::int32_t inumIterations = 5, 28 | std::int32_t inumParticles = 16, 29 | double ikSettle = 1, 30 | double ikITAE = 2); 31 | 32 | static std::unique_ptr 33 | createPtr(const std::shared_ptr> &iinput, 34 | const std::shared_ptr> &ioutput, 35 | QTime itimeout, 36 | std::int32_t igoal, 37 | double ikPMin, 38 | double ikPMax, 39 | double ikIMin, 40 | double ikIMax, 41 | double ikDMin, 42 | double ikDMax, 43 | std::int32_t inumIterations = 5, 44 | std::int32_t inumParticles = 16, 45 | double ikSettle = 1, 46 | double ikITAE = 2); 47 | }; 48 | } // namespace okapi 49 | -------------------------------------------------------------------------------- /include/okapi/api/chassis/model/threeEncoderSkidSteerModel.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/chassis/model/skidSteerModel.hpp" 11 | 12 | namespace okapi { 13 | class ThreeEncoderSkidSteerModel : public SkidSteerModel { 14 | public: 15 | /** 16 | * Model for a skid steer drive (wheels parallel with robot's direction of motion). When all 17 | * motors are powered +100%, the robot should move forward in a straight line. 18 | * 19 | * @param ileftSideMotor left side motor 20 | * @param irightSideMotor right side motor 21 | * @param ileftEnc left side encoder 22 | * @param imiddleEnc middle encoder (mounted perpendicular to the left and right side encoders) 23 | * @param irightEnc right side encoder 24 | */ 25 | ThreeEncoderSkidSteerModel(const std::shared_ptr &ileftSideMotor, 26 | const std::shared_ptr &irightSideMotor, 27 | const std::shared_ptr &ileftEnc, 28 | const std::shared_ptr &imiddleEnc, 29 | const std::shared_ptr &irightEnc, 30 | double imaxVelocity, 31 | double imaxVoltage = 12000); 32 | 33 | /** 34 | * Read the sensors. 35 | * 36 | * @return sensor readings in the format {left, right, middle} 37 | */ 38 | std::valarray getSensorVals() const override; 39 | 40 | /** 41 | * Reset the sensors to their zero point. 42 | */ 43 | void resetSensors() const override; 44 | 45 | protected: 46 | std::shared_ptr middleSensor; 47 | }; 48 | } // namespace okapi 49 | -------------------------------------------------------------------------------- /include/display/lvgl.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lvgl.h 3 | * Include all LittleV GL related headers 4 | */ 5 | 6 | #ifndef LVGL_H 7 | #define LVGL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | #pragma GCC diagnostic push 18 | #pragma GCC diagnostic ignored "-Wpedantic" 19 | /*Test misc. module version*/ 20 | #include "lv_misc/lv_task.h" 21 | 22 | #include "lv_hal/lv_hal.h" 23 | 24 | #include "lv_core/lv_group.h" 25 | #include "lv_core/lv_obj.h" 26 | #include "lv_core/lv_vdb.h" 27 | 28 | #include "lv_themes/lv_theme.h" 29 | 30 | #include "lv_objx/lv_bar.h" 31 | #include "lv_objx/lv_btn.h" 32 | #include "lv_objx/lv_btnm.h" 33 | #include "lv_objx/lv_cb.h" 34 | #include "lv_objx/lv_chart.h" 35 | #include "lv_objx/lv_cont.h" 36 | #include "lv_objx/lv_ddlist.h" 37 | #include "lv_objx/lv_gauge.h" 38 | #include "lv_objx/lv_img.h" 39 | #include "lv_objx/lv_kb.h" 40 | #include "lv_objx/lv_label.h" 41 | #include "lv_objx/lv_led.h" 42 | #include "lv_objx/lv_line.h" 43 | #include "lv_objx/lv_list.h" 44 | #include "lv_objx/lv_lmeter.h" 45 | #include "lv_objx/lv_mbox.h" 46 | #include "lv_objx/lv_page.h" 47 | #include "lv_objx/lv_roller.h" 48 | #include "lv_objx/lv_slider.h" 49 | #include "lv_objx/lv_sw.h" 50 | #include "lv_objx/lv_ta.h" 51 | #include "lv_objx/lv_tabview.h" 52 | #include "lv_objx/lv_win.h" 53 | #pragma GCC diagnostic pop 54 | 55 | /********************* 56 | * DEFINES 57 | *********************/ 58 | /*Current version of LittlevGL*/ 59 | #define LVGL_VERSION_MAJOR 5 60 | #define LVGL_VERSION_MINOR 1 61 | #define LVGL_VERSION_PATCH 0 62 | #define LVGL_VERSION_INFO "" 63 | 64 | /********************** 65 | * TYPEDEFS 66 | **********************/ 67 | 68 | /********************** 69 | * GLOBAL PROTOTYPES 70 | **********************/ 71 | 72 | /********************** 73 | * MACROS 74 | **********************/ 75 | 76 | #ifdef __cplusplus 77 | } 78 | #endif 79 | 80 | #endif /*LVGL_H*/ 81 | -------------------------------------------------------------------------------- /include/okapi/api/control/iterative/iterativeController.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/closedLoopController.hpp" 11 | #include "okapi/api/units/QTime.hpp" 12 | 13 | namespace okapi { 14 | /** 15 | * Closed-loop controller that steps iteratively using the step method below. 16 | * 17 | * ControllerOutput::controllerSet() should set the controller's target to the input scaled by the 18 | * output bounds. 19 | */ 20 | template 21 | class IterativeController : public ClosedLoopController { 22 | public: 23 | /** 24 | * Do one iteration of the controller. 25 | * 26 | * @param inewReading new measurement 27 | * @return controller output 28 | */ 29 | virtual Output step(Input ireading) = 0; 30 | 31 | /** 32 | * Returns the last calculated output of the controller. 33 | */ 34 | virtual Output getOutput() const = 0; 35 | 36 | /** 37 | * Set controller output bounds. 38 | * 39 | * @param imax max output 40 | * @param imin min output 41 | */ 42 | virtual void setOutputLimits(Output imax, Output imin) = 0; 43 | 44 | /** 45 | * Get the upper output bound. 46 | * 47 | * @return the upper output bound 48 | */ 49 | virtual Output getMaxOutput() = 0; 50 | 51 | /** 52 | * Get the lower output bound. 53 | * 54 | * @return the lower output bound 55 | */ 56 | virtual Output getMinOutput() = 0; 57 | 58 | /** 59 | * Set time between loops. 60 | * 61 | * @param isampleTime time between loops 62 | */ 63 | virtual void setSampleTime(QTime isampleTime) = 0; 64 | 65 | /** 66 | * Get the last set sample time. 67 | * 68 | * @return sample time 69 | */ 70 | virtual QTime getSampleTime() const = 0; 71 | }; 72 | } // namespace okapi 73 | -------------------------------------------------------------------------------- /include/display/lv_misc/lv_circ.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_circ.h 3 | * 4 | */ 5 | 6 | #ifndef LV_CIRC_H 7 | #define LV_CIRC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_area.h" 17 | #include 18 | 19 | /********************* 20 | * DEFINES 21 | *********************/ 22 | #define LV_CIRC_OCT1_X(p) (p.x) 23 | #define LV_CIRC_OCT1_Y(p) (p.y) 24 | #define LV_CIRC_OCT2_X(p) (p.y) 25 | #define LV_CIRC_OCT2_Y(p) (p.x) 26 | #define LV_CIRC_OCT3_X(p) (-p.y) 27 | #define LV_CIRC_OCT3_Y(p) (p.x) 28 | #define LV_CIRC_OCT4_X(p) (-p.x) 29 | #define LV_CIRC_OCT4_Y(p) (p.y) 30 | #define LV_CIRC_OCT5_X(p) (-p.x) 31 | #define LV_CIRC_OCT5_Y(p) (-p.y) 32 | #define LV_CIRC_OCT6_X(p) (-p.y) 33 | #define LV_CIRC_OCT6_Y(p) (-p.x) 34 | #define LV_CIRC_OCT7_X(p) (p.y) 35 | #define LV_CIRC_OCT7_Y(p) (-p.x) 36 | #define LV_CIRC_OCT8_X(p) (p.x) 37 | #define LV_CIRC_OCT8_Y(p) (-p.y) 38 | 39 | /********************** 40 | * TYPEDEFS 41 | **********************/ 42 | 43 | /********************** 44 | * GLOBAL PROTOTYPES 45 | **********************/ 46 | 47 | /** 48 | * Initialize the circle drawing 49 | * @param c pointer to a point. The coordinates will be calculated here 50 | * @param tmp point to a variable. It will store temporary data 51 | * @param radius radius of the circle 52 | */ 53 | void lv_circ_init(lv_point_t *c, lv_coord_t *tmp, lv_coord_t radius); 54 | 55 | /** 56 | * Test the circle drawing is ready or not 57 | * @param c same as in circ_init 58 | * @return true if the circle is not ready yet 59 | */ 60 | bool lv_circ_cont(lv_point_t *c); 61 | 62 | /** 63 | * Get the next point from the circle 64 | * @param c same as in circ_init. The next point stored here. 65 | * @param tmp same as in circ_init. 66 | */ 67 | void lv_circ_next(lv_point_t *c, lv_coord_t *tmp); 68 | 69 | /********************** 70 | * MACROS 71 | **********************/ 72 | 73 | #ifdef __cplusplus 74 | } /* extern "C" */ 75 | #endif 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /include/okapi/api/units/QTime.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/RQuantity.hpp" 17 | 18 | namespace okapi { 19 | QUANTITY_TYPE(0, 0, 1, 0, QTime) 20 | 21 | constexpr QTime second(1.0); // SI base unit 22 | constexpr QTime millisecond = second / 1000; 23 | constexpr QTime minute = 60 * second; 24 | constexpr QTime hour = 60 * minute; 25 | constexpr QTime day = 24 * hour; 26 | 27 | inline namespace literals { 28 | constexpr QTime operator"" _s(long double x) { 29 | return QTime(x); 30 | } 31 | constexpr QTime operator"" _ms(long double x) { 32 | return static_cast(x) * millisecond; 33 | } 34 | constexpr QTime operator"" _min(long double x) { 35 | return static_cast(x) * minute; 36 | } 37 | constexpr QTime operator"" _h(long double x) { 38 | return static_cast(x) * hour; 39 | } 40 | constexpr QTime operator"" _day(long double x) { 41 | return static_cast(x) * day; 42 | } 43 | constexpr QTime operator"" _s(unsigned long long int x) { 44 | return QTime(static_cast(x)); 45 | } 46 | constexpr QTime operator"" _ms(unsigned long long int x) { 47 | return static_cast(x) * millisecond; 48 | } 49 | constexpr QTime operator"" _min(unsigned long long int x) { 50 | return static_cast(x) * minute; 51 | } 52 | constexpr QTime operator"" _h(unsigned long long int x) { 53 | return static_cast(x) * hour; 54 | } 55 | constexpr QTime operator"" _day(unsigned long long int x) { 56 | return static_cast(x) * day; 57 | } 58 | } // namespace literals 59 | } // namespace okapi 60 | -------------------------------------------------------------------------------- /include/okapi/impl/device/rotarysensor/adiGyro.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "api.h" 11 | #include "okapi/api/control/controllerInput.hpp" 12 | #include "okapi/api/device/rotarysensor/continuousRotarySensor.hpp" 13 | 14 | namespace okapi { 15 | class ADIGyro : public ContinuousRotarySensor { 16 | public: 17 | /** 18 | * A gyroscope on the given ADI port. If the port has not previously been configured as a gyro, 19 | * then the constructor will block for 1 second for calibration. The gyro measures in tenths of a 20 | * degree, so there are 3600 measurement points per revolution. 21 | * 22 | * @param iport the ADI port number 23 | * @param imultiplier a value multiplied by the gyro heading value 24 | */ 25 | ADIGyro(std::uint8_t iport, double imultiplier = 1); 26 | 27 | virtual ~ADIGyro(); 28 | 29 | /** 30 | * Get the current sensor value. 31 | * 32 | * @return the current sensor value, or ``PROS_ERR`` on a failure. 33 | */ 34 | double get() const override; 35 | 36 | /** 37 | * Get the current sensor value remapped into the target range ([1800, -1800] by default). 38 | * 39 | * @param iupperBound the upper bound of the range. 40 | * @param ilowerBound the lower bound of the range. 41 | * @return the remapped sensor value. 42 | */ 43 | double getRemapped(double iupperBound = 1800, double ilowerBound = -1800) const 44 | __attribute__((optimize(3))); 45 | 46 | /** 47 | * Reset the sensor to zero. 48 | * 49 | * @return 1 on success, PROS_ERR on fail 50 | */ 51 | std::int32_t reset() override; 52 | 53 | /** 54 | * Get the sensor value for use in a control loop. This method might be automatically called in 55 | * another thread by the controller. 56 | * 57 | * @return the current sensor value, or ``PROS_ERR`` on a failure. 58 | */ 59 | double controllerGet() override; 60 | 61 | protected: 62 | pros::ADIGyro gyro; 63 | }; 64 | } // namespace okapi 65 | -------------------------------------------------------------------------------- /include/display/lv_core/lv_refr.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_refr.h 3 | * 4 | */ 5 | 6 | #ifndef LV_REFR_H 7 | #define LV_REFR_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_obj.h" 17 | #include 18 | 19 | /********************* 20 | * DEFINES 21 | *********************/ 22 | 23 | /********************** 24 | * TYPEDEFS 25 | **********************/ 26 | 27 | /********************** 28 | * STATIC PROTOTYPES 29 | **********************/ 30 | 31 | /********************** 32 | * STATIC VARIABLES 33 | **********************/ 34 | 35 | /********************** 36 | * MACROS 37 | **********************/ 38 | 39 | /********************** 40 | * GLOBAL FUNCTIONS 41 | **********************/ 42 | 43 | /** 44 | * Initialize the screen refresh subsystem 45 | */ 46 | void lv_refr_init(void); 47 | 48 | /** 49 | * Invalidate an area 50 | * @param area_p pointer to area which should be invalidated 51 | */ 52 | void lv_inv_area(const lv_area_t *area_p); 53 | 54 | /** 55 | * Set a function to call after every refresh to announce the refresh time and 56 | * the number of refreshed pixels 57 | * @param cb pointer to a callback function (void my_refr_cb(uint32_t time_ms, 58 | * uint32_t px_num)) 59 | */ 60 | void lv_refr_set_monitor_cb(void (*cb)(uint32_t, uint32_t)); 61 | 62 | /** 63 | * Called when an area is invalidated to modify the coordinates of the area. 64 | * Special display controllers may require special coordinate rounding 65 | * @param cb pointer to the a function which will modify the area 66 | */ 67 | void lv_refr_set_round_cb(void (*cb)(lv_area_t *)); 68 | 69 | /** 70 | * Get the number of areas in the buffer 71 | * @return number of invalid areas 72 | */ 73 | uint16_t lv_refr_get_buf_size(void); 74 | 75 | /** 76 | * Pop (delete) the last 'num' invalidated areas from the buffer 77 | * @param num number of areas to delete 78 | */ 79 | void lv_refr_pop_from_buf(uint16_t num); 80 | /********************** 81 | * STATIC FUNCTIONS 82 | **********************/ 83 | 84 | #ifdef __cplusplus 85 | } /* extern "C" */ 86 | #endif 87 | 88 | #endif /*LV_REFR_H*/ 89 | -------------------------------------------------------------------------------- /include/okapi/api/units/QMass.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/RQuantity.hpp" 17 | 18 | namespace okapi { 19 | QUANTITY_TYPE(1, 0, 0, 0, QMass) 20 | 21 | constexpr QMass kg(1.0); // SI base unit 22 | constexpr QMass gramme = 0.001 * kg; 23 | constexpr QMass tonne = 1000 * kg; 24 | constexpr QMass ounce = 0.028349523125 * kg; 25 | constexpr QMass pound = 16 * ounce; 26 | constexpr QMass stone = 14 * pound; 27 | 28 | inline namespace literals { 29 | constexpr QMass operator"" _kg(long double x) { 30 | return QMass(x); 31 | } 32 | constexpr QMass operator"" _g(long double x) { 33 | return static_cast(x) * gramme; 34 | } 35 | constexpr QMass operator"" _t(long double x) { 36 | return static_cast(x) * tonne; 37 | } 38 | constexpr QMass operator"" _oz(long double x) { 39 | return static_cast(x) * ounce; 40 | } 41 | constexpr QMass operator"" _lb(long double x) { 42 | return static_cast(x) * pound; 43 | } 44 | constexpr QMass operator"" _st(long double x) { 45 | return static_cast(x) * stone; 46 | } 47 | constexpr QMass operator"" _kg(unsigned long long int x) { 48 | return QMass(static_cast(x)); 49 | } 50 | constexpr QMass operator"" _g(unsigned long long int x) { 51 | return static_cast(x) * gramme; 52 | } 53 | constexpr QMass operator"" _t(unsigned long long int x) { 54 | return static_cast(x) * tonne; 55 | } 56 | constexpr QMass operator"" _oz(unsigned long long int x) { 57 | return static_cast(x) * ounce; 58 | } 59 | constexpr QMass operator"" _lb(unsigned long long int x) { 60 | return static_cast(x) * pound; 61 | } 62 | constexpr QMass operator"" _st(unsigned long long int x) { 63 | return static_cast(x) * stone; 64 | } 65 | } // namespace literals 66 | } // namespace okapi 67 | -------------------------------------------------------------------------------- /include/main.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file main.h 3 | * 4 | * Contains common definitions and header files used throughout your PROS 5 | * project. 6 | * 7 | * Copyright (c) 2017-2018, Purdue University ACM SIGBots. 8 | * All rights reserved. 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | 15 | #ifndef _PROS_MAIN_H_ 16 | #define _PROS_MAIN_H_ 17 | 18 | /** 19 | * If defined, some commonly used enums will have preprocessor macros which give 20 | * a shorter, more convenient naming pattern. If this isn't desired, simply 21 | * comment the following line out. 22 | * 23 | * For instance, E_CONTROLLER_MASTER has a shorter name: CONTROLLER_MASTER. 24 | * E_CONTROLLER_MASTER is pedantically correct within the PROS styleguide, but 25 | * not convienent for most student programmers. 26 | */ 27 | #define PROS_USE_SIMPLE_NAMES 28 | 29 | /** 30 | * If defined, C++ literals will be available for use. All literals are in the 31 | * pros::literals namespace. 32 | * 33 | * For instance, you can do `4_mtr = 50` to set motor 4's target velocity to 50 34 | */ 35 | #define PROS_USE_LITERALS 36 | 37 | #include "api.h" 38 | #include "pros/apix.h" 39 | 40 | /** 41 | * You should add more #includes here 42 | */ 43 | //#include "okapi/api.hpp" 44 | //#include "pros/api_legacy.h" 45 | 46 | /** 47 | * If you find doing pros::Motor() to be tedious and you'd prefer just to do 48 | * Motor, you can use the namespace with the following commented out line. 49 | * 50 | * IMPORTANT: Only the okapi or pros namespace may be used, not both 51 | * concurrently! The okapi namespace will export all symbols inside the pros 52 | * namespace. 53 | */ 54 | // using namespace pros; 55 | // using namespace pros::literals; 56 | // using namespace okapi; 57 | 58 | /** 59 | * Prototypes for the competition control tasks are redefined here to ensure 60 | * that they can be called from user code (i.e. calling autonomous from a 61 | * button press in opcontrol() for testing purposes). 62 | */ 63 | #ifdef __cplusplus 64 | extern "C" { 65 | #endif 66 | void autonomous(void); 67 | void initialize(void); 68 | void disabled(void); 69 | void competition_initialize(void); 70 | void opcontrol(void); 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #ifdef __cplusplus 76 | /** 77 | * You can add C++-only headers here 78 | */ 79 | //#include 80 | #endif 81 | 82 | #endif // _PROS_MAIN_H_ 83 | -------------------------------------------------------------------------------- /include/okapi/api/filter/medianFilter.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Uses the median filter algorithm from N. Wirth’s book, implementation by N. Devillard. 3 | * 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | #pragma once 11 | 12 | #include "okapi/api/filter/filter.hpp" 13 | #include 14 | #include 15 | #include 16 | 17 | namespace okapi { 18 | /** 19 | * A filter which returns the median value of list of values. 20 | * 21 | * @tparam n number of taps in the filter 22 | */ 23 | template class MedianFilter : public Filter { 24 | public: 25 | MedianFilter() : middleIndex((((n)&1) ? ((n) / 2) : (((n) / 2) - 1))) { 26 | } 27 | 28 | /** 29 | * Filters a value, like a sensor reading. 30 | * 31 | * @param ireading new measurement 32 | * @return filtered result 33 | */ 34 | double filter(const double ireading) override { 35 | data[index++] = ireading; 36 | if (index >= n) { 37 | index = 0; 38 | } 39 | 40 | output = kth_smallset(); 41 | return output; 42 | } 43 | 44 | /** 45 | * Returns the previous output from filter. 46 | * 47 | * @return the previous output from filter 48 | */ 49 | double getOutput() const override { 50 | return output; 51 | } 52 | 53 | protected: 54 | std::array data{0}; 55 | std::size_t index = 0; 56 | double output = 0; 57 | const size_t middleIndex; 58 | 59 | /** 60 | * Algorithm from N. Wirth’s book, implementation by N. Devillard. 61 | */ 62 | double kth_smallset() { 63 | std::array dataCopy = data; 64 | size_t j, l, m; 65 | l = 0; 66 | m = n - 1; 67 | 68 | while (l < m) { 69 | double x = dataCopy[middleIndex]; 70 | size_t i = l; 71 | j = m; 72 | do { 73 | while (dataCopy[i] < x) { 74 | i++; 75 | } 76 | while (x < dataCopy[j]) { 77 | j--; 78 | } 79 | if (i <= j) { 80 | const double t = dataCopy[i]; 81 | dataCopy[i] = dataCopy[j]; 82 | dataCopy[j] = t; 83 | i++; 84 | j--; 85 | } 86 | } while (i <= j); 87 | if (j < middleIndex) 88 | l = i; 89 | if (middleIndex < i) 90 | m = j; 91 | } 92 | 93 | return dataCopy[middleIndex]; 94 | } 95 | }; 96 | } // namespace okapi 97 | -------------------------------------------------------------------------------- /src/opcontrol.cpp: -------------------------------------------------------------------------------- 1 | #include "screen/field.hpp" 2 | 3 | void opcontrol() 4 | { 5 | // make sure initializeStyles() happens or nothing will work! 6 | // in this example it is called in initialize() 7 | 8 | // initialize and load a screen object 9 | lv_obj_t *scr = lv_obj_create(NULL, NULL); 10 | lv_scr_load(scr); 11 | 12 | screen::Field field(scr); 13 | 14 | // two stacks use an array of colors 15 | // draw a purple stack with height 1 and an orange stack with height 3 in the far red zone 16 | field.draw(screen::scoringZone::farRed, {screen::color::purple, screen::color::orange}, {1, 3}); 17 | 18 | // one stack does not need to use an array 19 | // draw a green stack with height 4 in the near red zone 20 | field.draw(screen::scoringZone::nearRed, screen::color::green, 4); 21 | 22 | // draw the 1st(furthest) left stack with only the bottom two cubes 23 | field.draw(screen::cubeGroup::left1, 0b00011); 24 | 25 | // draw the 3rd(2nd closest) left stack, but not the cubes to the left of it 26 | field.draw(screen::cubeGroup::left3, 0b01100); 27 | 28 | // draw the first and 3rd cube in the row 29 | // right4 is the closest row of cubes on the right 30 | // it looks the same in binary and on the field 31 | field.draw(screen::cubeGroup::right4, 0b01010); 32 | 33 | // alternatively, macros can be used 34 | 35 | // draw the 3 cubes the macros describe 36 | // (this is the 5 cube stack on the audience side) 37 | field.draw(screen::cubeGroup::near, CUBE_NEAR_LEFT + CUBE_NEAR_RIGHT + CUBE_FAR_RIGHT); 38 | 39 | // draw the highest(rightmost), and the 2nd lowest(leftmost) cube of the 4th(closest) left cube 40 | // group 41 | field.draw(screen::cubeGroup::left4, CUBE_HIGHEST + CUBE_2LOWEST); 42 | 43 | // draw the left tower with no cubes in or around 44 | field.draw(screen::tower::left, screen::color::none, 0); 45 | 46 | // draw an orange cube in the center tower, and draw all cubes around it except the left one 47 | field.draw(screen::tower::center, screen::color::orange, 0b1110); 48 | 49 | // draw the far tower with no cube, and draw the cube past it and to the left of it 50 | field.draw(screen::tower::far, screen::color::none, TOWER_CUBE_FAR + TOWER_CUBE_LEFT); 51 | 52 | // draw a "robot" on the red (denoted by true) side of the field with a center y-value of 160 53 | // (straddling the line between the 4th and 5th tiles from the top) 54 | field.drawRobot(true, 160); 55 | 56 | // draw all objects not explicity defined here with their default settings 57 | field.finishDrawing(); 58 | 59 | while (true) { 60 | pros::delay(1000); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /include/screen/resources.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Contains the resources for printing the field 3 | */ 4 | 5 | #ifndef SCREEN_RESOURCES_HPP_ 6 | #define SCREEN_RESOURCES_HPP_ 7 | #include "main.h" 8 | 9 | extern lv_font_t smallFont; 10 | 11 | namespace screen { 12 | 13 | /** 14 | * These styles are used for the objects on the field, along with 15 | * some other, such as blueText and redText that are probably going 16 | * to be useful to anyone making an auton selector around it 17 | */ 18 | 19 | /** 20 | * This frist group of styles are likely to be used in every game, 21 | * and therefore are kept seperate for when this is updated 22 | */ 23 | 24 | extern lv_style_t blankStyle; 25 | extern lv_style_t listStyle; 26 | extern lv_style_t fieldStyle; 27 | extern lv_style_t blueAlliance; 28 | extern lv_style_t blueAllianceHighlighted; 29 | extern lv_style_t redAlliance; 30 | extern lv_style_t redAllianceHighlighted; 31 | extern lv_style_t lineStyle; 32 | extern lv_style_t whiteText; 33 | extern lv_style_t blueText; 34 | extern lv_style_t redText; 35 | extern lv_style_t greenBox; 36 | extern lv_style_t pressedButton; 37 | 38 | /** 39 | * This group has not been needed in the past, 40 | * but could be useful in future games 41 | */ 42 | 43 | extern lv_style_t littleWhiteText; 44 | extern lv_style_t perimeterStyle; 45 | 46 | /** 47 | * This group only pertains to the current game 48 | */ 49 | 50 | extern lv_style_t orangeStyleHighlighted; 51 | extern lv_style_t orangeStyle; 52 | extern lv_style_t greenStyleHighlighted; 53 | extern lv_style_t greenStyle; 54 | extern lv_style_t purpleStyleHighlighted; 55 | extern lv_style_t purpleStyle; 56 | extern lv_style_t neutralTower; 57 | extern lv_style_t redTower; 58 | extern lv_style_t blueTower; 59 | extern lv_style_t redZone; 60 | extern lv_style_t blueZone; 61 | extern lv_style_t redZoneHighlighted; 62 | extern lv_style_t blueZoneHighlighted; 63 | 64 | /** 65 | * Initializes all styles, MUST be run before anything is 66 | * done with the screen, I suggest calling it in initialize() 67 | */ 68 | 69 | void initializeStyles(); 70 | 71 | /** 72 | * Various enums for more readable parameters 73 | */ 74 | 75 | enum class color { none, orange, green, purple }; 76 | 77 | enum class cubeGroup { 78 | farLeft, 79 | farRight, 80 | farPurple, 81 | left1, 82 | left2, 83 | left3, 84 | left4, 85 | right1, 86 | right2, 87 | right3, 88 | right4, 89 | near 90 | }; 91 | 92 | enum class tower { left, right, center, far, near, red, blue }; 93 | 94 | enum class scoringZone { farRed, farBlue, nearRed, nearBlue }; 95 | 96 | } // namespace screen 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /include/okapi/api/util/logging.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/util/abstractTimer.hpp" 11 | #include 12 | 13 | namespace okapi { 14 | class Logger { 15 | public: 16 | enum class LogLevel { off = 0, debug = 4, info = 3, warn = 2, error = 1 }; 17 | 18 | /** 19 | * Initializes the logger. If the logger is not initialized when logging methods are called, 20 | * nothing will be logged. 21 | * 22 | * @param itimer A timer used to get the current time for log statements. 23 | * @param logfileName The name of the log file to open. 24 | * @param level The log level. Log statements above this level will be disabled. 25 | */ 26 | static void initialize(std::unique_ptr itimer, 27 | std::string_view filename, 28 | LogLevel level) noexcept; 29 | 30 | /** 31 | * Initializes the logger. If the logger is not initialized when logging methods are called, 32 | * nothing will be logged. 33 | * 34 | * @param itimer A timer used to get the current time for log statements. 35 | * @param logfileName The name of the log file to open. 36 | * @param level The log level. Log statements above this level will be disabled. 37 | */ 38 | static void 39 | initialize(std::unique_ptr itimer, FILE *file, LogLevel level) noexcept; 40 | 41 | /** 42 | * Get the logger instance. 43 | */ 44 | static Logger *instance() noexcept; 45 | 46 | /** 47 | * Set a new logging level. Log statements above this level will be disabled. For example, if the 48 | * level is set to LogLevel::warn, then LogLevel::warn and LogLevel::error will be enabled, but 49 | * LogLevel::info and LogLevel::debug will be disabled. 50 | */ 51 | static void setLogLevel(LogLevel level) noexcept; 52 | 53 | void debug(std::string_view message) const noexcept; 54 | 55 | void info(std::string_view message) const noexcept; 56 | 57 | void warn(std::string_view message) const noexcept; 58 | 59 | void error(std::string_view message) const noexcept; 60 | 61 | /** 62 | * Closes the connection to the log file. 63 | */ 64 | void close() noexcept; 65 | 66 | private: 67 | Logger(); 68 | static Logger *s_instance; 69 | static std::unique_ptr timer; 70 | static LogLevel logLevel; 71 | static FILE *logfile; 72 | }; 73 | } // namespace okapi 74 | -------------------------------------------------------------------------------- /include/okapi/api/control/util/pidTuner.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Jonathan Bayless, Team BLRS 3 | * @author Ryan Benasutti, WPI 4 | * 5 | * This Source Code Form is subject to the terms of the Mozilla Public 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 | */ 9 | #pragma once 10 | 11 | #include "okapi/api/control/controllerInput.hpp" 12 | #include "okapi/api/control/controllerOutput.hpp" 13 | #include "okapi/api/control/iterative/iterativePosPidController.hpp" 14 | #include "okapi/api/units/QTime.hpp" 15 | #include "okapi/api/util/logging.hpp" 16 | #include "okapi/api/util/timeUtil.hpp" 17 | #include 18 | #include 19 | 20 | namespace okapi { 21 | class PIDTuner { 22 | public: 23 | struct Output { 24 | double kP, kI, kD; 25 | }; 26 | 27 | PIDTuner(const std::shared_ptr> &iinput, 28 | const std::shared_ptr> &ioutput, 29 | const TimeUtil &itimeUtil, 30 | QTime itimeout, 31 | std::int32_t igoal, 32 | double ikPMin, 33 | double ikPMax, 34 | double ikIMin, 35 | double ikIMax, 36 | double ikDMin, 37 | double ikDMax, 38 | std::size_t inumIterations = 5, 39 | std::size_t inumParticles = 16, 40 | double ikSettle = 1, 41 | double ikITAE = 2); 42 | 43 | virtual ~PIDTuner(); 44 | 45 | virtual Output autotune(); 46 | 47 | protected: 48 | static constexpr double inertia = 0.5; // Particle inertia 49 | static constexpr double confSelf = 1.1; // Self confidence 50 | static constexpr double confSwarm = 1.2; // Particle swarm confidence 51 | static constexpr int increment = 5; 52 | static constexpr int divisor = 5; 53 | static constexpr QTime loopDelta = 10_ms; // NOLINT 54 | 55 | struct Particle { 56 | double pos, vel, best; 57 | }; 58 | 59 | struct ParticleSet { 60 | Particle kP, kI, kD; 61 | double bestError; 62 | }; 63 | 64 | Logger *logger; 65 | std::shared_ptr> input; 66 | std::shared_ptr> output; 67 | TimeUtil timeUtil; 68 | std::unique_ptr rate; 69 | 70 | const QTime timeout; 71 | const std::int32_t goal; 72 | const double kPMin; 73 | const double kPMax; 74 | const double kIMin; 75 | const double kIMax; 76 | const double kDMin; 77 | const double kDMax; 78 | const std::size_t numIterations; 79 | const std::size_t numParticles; 80 | const double kSettle; 81 | const double kITAE; 82 | }; 83 | } // namespace okapi 84 | -------------------------------------------------------------------------------- /include/okapi/api/filter/ekfFilter.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/filter/filter.hpp" 11 | #include "okapi/api/util/mathUtil.hpp" 12 | 13 | namespace okapi { 14 | class EKFFilter : public Filter { 15 | public: 16 | /** 17 | * One dimensional extended Kalman filter. The default arguments should work fine for most signal 18 | * filtering. It won't hurt to graph your signal and the filtered result, and check if the filter 19 | * is doing its job. 20 | * 21 | * Q is the covariance of the process noise and R is the 22 | * covariance of the observation noise. The default values for Q and R should be a modest balance 23 | * between trust in the sensor and FIR filtering. 24 | * 25 | * Think of R as how noisy your sensor is. Its value can be found mathematically by computing the 26 | * standard deviation of your sensor reading vs. "truth" (of course, "truth" is still an estimate; 27 | * try to calibrate your robot in a controlled setting where you can minimize the error in what 28 | * "truth" is). 29 | * 30 | * Think of Q as how noisy your model is. It decides how much "smoothing" the filter does and how 31 | * far it lags behind the true signal. This parameter is most often used as a "tuning" parameter 32 | * to adjust the response of the filter. 33 | * 34 | * @param iQ process noise covariance 35 | * @param iR measurement noise covariance 36 | */ 37 | explicit EKFFilter(double iQ = 0.0001, double iR = ipow(0.2, 2)); 38 | 39 | /** 40 | * Filters a value, like a sensor reading. Assumes the control input is zero. 41 | * 42 | * @param ireading new measurement 43 | * @return filtered result 44 | */ 45 | double filter(double ireading) override; 46 | 47 | /** 48 | * Filters a reading with a control input. 49 | * 50 | * @param ireading new measurement 51 | * @param icontrol control input 52 | * @return filtered result 53 | */ 54 | virtual double filter(double ireading, double icontrol); 55 | 56 | /** 57 | * Returns the previous output from filter. 58 | * 59 | * @return the previous output from filter 60 | */ 61 | double getOutput() const override; 62 | 63 | protected: 64 | const double Q, R; 65 | double xHat = 0; 66 | double xHatPrev = 0; 67 | double xHatMinus = 0; 68 | double P = 0; 69 | double Pprev = 1; 70 | double Pminus = 0; 71 | double K = 0; 72 | }; 73 | } // namespace okapi 74 | -------------------------------------------------------------------------------- /include/display/lv_misc/lv_mem.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_mem.h 3 | * 4 | */ 5 | 6 | #ifndef LV_MEM_H 7 | #define LV_MEM_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include 17 | #include 18 | 19 | /********************* 20 | * DEFINES 21 | *********************/ 22 | 23 | /********************** 24 | * TYPEDEFS 25 | **********************/ 26 | 27 | typedef struct { 28 | uint32_t total_size; 29 | uint32_t free_cnt; 30 | uint32_t free_size; 31 | uint32_t free_biggest_size; 32 | uint32_t used_cnt; 33 | uint8_t used_pct; 34 | uint8_t frag_pct; 35 | } lv_mem_monitor_t; 36 | 37 | /********************** 38 | * GLOBAL PROTOTYPES 39 | **********************/ 40 | 41 | /** 42 | * Initiaize the dyn_mem module (work memory and other variables) 43 | */ 44 | void lv_mem_init(void); 45 | 46 | /** 47 | * Allocate a memory dynamically 48 | * @param size size of the memory to allocate in bytes 49 | * @return pointer to the allocated memory 50 | */ 51 | void *lv_mem_alloc(uint32_t size); 52 | 53 | /** 54 | * Free an allocated data 55 | * @param data pointer to an allocated memory 56 | */ 57 | void lv_mem_free(const void *data); 58 | 59 | /** 60 | * Reallocate a memory with a new size. The old content will be kept. 61 | * @param data pointer to an allocated memory. 62 | * Its content will be copied to the new memory block and freed 63 | * @param new_size the desired new size in byte 64 | * @return pointer to the new memory 65 | */ 66 | void *lv_mem_realloc(void *data_p, uint32_t new_size); 67 | 68 | /** 69 | * Join the adjacent free memory blocks 70 | */ 71 | void lv_mem_defrag(void); 72 | 73 | /** 74 | * Give information about the work memory of dynamic allocation 75 | * @param mon_p pointer to a dm_mon_p variable, 76 | * the result of the analysis will be stored here 77 | */ 78 | void lv_mem_monitor(lv_mem_monitor_t *mon_p); 79 | 80 | /** 81 | * Give the size of an allocated memory 82 | * @param data pointer to an allocated memory 83 | * @return the size of data memory in bytes 84 | */ 85 | uint32_t lv_mem_get_size(const void *data); 86 | 87 | /** 88 | * Halt o NULL pointer 89 | * p pointer to a memory 90 | */ 91 | static inline void lv_mem_assert(void *p) { 92 | if (p == NULL) { 93 | while (1) 94 | ; 95 | } 96 | } 97 | 98 | /********************** 99 | * MACROS 100 | **********************/ 101 | 102 | #ifdef __cplusplus 103 | } /* extern "C" */ 104 | #endif 105 | 106 | #endif /*LV_MEM_H*/ 107 | -------------------------------------------------------------------------------- /include/okapi/api/control/closedLoopController.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/controllerOutput.hpp" 11 | #include "okapi/api/units/QTime.hpp" 12 | 13 | namespace okapi { 14 | /** 15 | * An abstract closed-loop controller. 16 | * 17 | * @tparam Input The target/input type. 18 | * @tparam Output The error/output type. 19 | */ 20 | template 21 | class ClosedLoopController : public ControllerOutput { 22 | public: 23 | virtual ~ClosedLoopController() = default; 24 | 25 | /** 26 | * Sets the target for the controller. 27 | * 28 | * @param itarget the new target 29 | */ 30 | virtual void setTarget(Input itarget) = 0; 31 | 32 | /** 33 | * Gets the last set target, or the default target if none was set. 34 | * 35 | * @return the last target 36 | */ 37 | virtual Input getTarget() = 0; 38 | 39 | /** 40 | * Returns the last error of the controller. Does not update when disabled. 41 | * 42 | * @return the last error 43 | */ 44 | virtual Output getError() const = 0; 45 | 46 | /** 47 | * Returns whether the controller has settled at the target. Determining what settling means is 48 | * implementation-dependent. 49 | * 50 | * If the controller is disabled, this method must return true. 51 | * 52 | * @return whether the controller is settled 53 | */ 54 | virtual bool isSettled() = 0; 55 | 56 | /** 57 | * Resets the controller's internal state so it is similar to when it was first initialized, while 58 | * keeping any user-configured information. 59 | */ 60 | virtual void reset() = 0; 61 | 62 | /** 63 | * Changes whether the controller is off or on. Turning the controller on after it was off will 64 | * cause the controller to move to its last set target, unless it was reset in that time. 65 | */ 66 | virtual void flipDisable() = 0; 67 | 68 | /** 69 | * Sets whether the controller is off or on. Turning the controller on after it was off will 70 | * cause the controller to move to its last set target, unless it was reset in that time. 71 | * 72 | * @param iisDisabled whether the controller is disabled 73 | */ 74 | virtual void flipDisable(bool iisDisabled) = 0; 75 | 76 | /** 77 | * Returns whether the controller is currently disabled. 78 | * 79 | * @return whether the controller is currently disabled 80 | */ 81 | virtual bool isDisabled() const = 0; 82 | }; 83 | } // namespace okapi 84 | -------------------------------------------------------------------------------- /include/display/lv_objx/lv_led.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_led.h 3 | * 4 | */ 5 | 6 | #ifndef LV_LED_H 7 | #define LV_LED_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "display/lv_conf.h" 17 | #if USE_LV_LED != 0 18 | 19 | #include "display/lv_core/lv_obj.h" 20 | 21 | /********************* 22 | * DEFINES 23 | *********************/ 24 | 25 | /********************** 26 | * TYPEDEFS 27 | **********************/ 28 | 29 | /*Data of led*/ 30 | typedef struct { 31 | /*No inherited ext.*/ 32 | /*New data for this type */ 33 | uint8_t bright; /*Current brightness of the LED (0..255)*/ 34 | } lv_led_ext_t; 35 | 36 | /********************** 37 | * GLOBAL PROTOTYPES 38 | **********************/ 39 | 40 | /** 41 | * Create a led objects 42 | * @param par pointer to an object, it will be the parent of the new led 43 | * @param copy pointer to a led object, if not NULL then the new object will be 44 | * copied from it 45 | * @return pointer to the created led 46 | */ 47 | lv_obj_t *lv_led_create(lv_obj_t *par, lv_obj_t *copy); 48 | 49 | /** 50 | * Set the brightness of a LED object 51 | * @param led pointer to a LED object 52 | * @param bright 0 (max. dark) ... 255 (max. light) 53 | */ 54 | void lv_led_set_bright(lv_obj_t *led, uint8_t bright); 55 | 56 | /** 57 | * Light on a LED 58 | * @param led pointer to a LED object 59 | */ 60 | void lv_led_on(lv_obj_t *led); 61 | 62 | /** 63 | * Light off a LED 64 | * @param led pointer to a LED object 65 | */ 66 | void lv_led_off(lv_obj_t *led); 67 | 68 | /** 69 | * Toggle the state of a LED 70 | * @param led pointer to a LED object 71 | */ 72 | void lv_led_toggle(lv_obj_t *led); 73 | 74 | /** 75 | * Set the style of a led 76 | * @param led pointer to a led object 77 | * @param style pointer to a style 78 | */ 79 | static inline void lv_led_set_style(lv_obj_t *led, lv_style_t *style) { 80 | lv_obj_set_style(led, style); 81 | } 82 | 83 | /** 84 | * Get the brightness of a LEd object 85 | * @param led pointer to LED object 86 | * @return bright 0 (max. dark) ... 255 (max. light) 87 | */ 88 | uint8_t lv_led_get_bright(lv_obj_t *led); 89 | 90 | /** 91 | * Get the style of an led object 92 | * @param led pointer to an led object 93 | * @return pointer to the led's style 94 | */ 95 | static inline lv_style_t *lv_led_get_style(lv_obj_t *led) { 96 | return lv_obj_get_style(led); 97 | } 98 | 99 | /********************** 100 | * MACROS 101 | **********************/ 102 | 103 | #endif /*USE_LV_LED*/ 104 | 105 | #ifdef __cplusplus 106 | } /* extern "C" */ 107 | #endif 108 | 109 | #endif /*LV_LED_H*/ 110 | -------------------------------------------------------------------------------- /include/okapi/api/filter/velMath.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/filter/composableFilter.hpp" 11 | #include "okapi/api/units/QAngularAcceleration.hpp" 12 | #include "okapi/api/units/QAngularSpeed.hpp" 13 | #include "okapi/api/units/QTime.hpp" 14 | #include "okapi/api/util/abstractTimer.hpp" 15 | #include "okapi/api/util/logging.hpp" 16 | #include 17 | 18 | namespace okapi { 19 | class VelMathArgs { 20 | public: 21 | explicit VelMathArgs(double iticksPerRev, QTime isampleTime = 0_ms); 22 | VelMathArgs(double iticksPerRev, 23 | const std::shared_ptr &ifilter, 24 | QTime isampleTime = 0_ms); 25 | 26 | virtual ~VelMathArgs(); 27 | 28 | double ticksPerRev; 29 | std::shared_ptr filter; 30 | QTime sampleTime; 31 | }; 32 | 33 | class VelMath { 34 | public: 35 | /** 36 | * Velocity math helper. Calculates filtered velocity. Throws a std::invalid_argument exception 37 | * if iticksPerRev is zero. 38 | * 39 | * @param iticksPerRev number of ticks per revolution (or whatever units you are using) 40 | * @param ifilter filter used for filtering the calculated velocity 41 | * @param isampleTime the minimum time between velocity measurements 42 | */ 43 | VelMath(double iticksPerRev, 44 | const std::shared_ptr &ifilter, 45 | QTime isampleTime, 46 | std::unique_ptr iloopDtTimer); 47 | 48 | VelMath(const VelMathArgs &iparams, std::unique_ptr iloopDtTimer); 49 | 50 | virtual ~VelMath(); 51 | 52 | /** 53 | * Calculates the current velocity and acceleration. Returns the (filtered) velocity. 54 | * 55 | * @param inewPos new position 56 | * @return current (filtered) velocity 57 | */ 58 | virtual QAngularSpeed step(double inewPos); 59 | 60 | /** 61 | * Sets ticks per revolution (or whatever units you are using). 62 | * 63 | * @para iTPR ticks per revolution 64 | */ 65 | virtual void setTicksPerRev(double iTPR); 66 | 67 | /** 68 | * Returns the last calculated velocity. 69 | */ 70 | virtual QAngularSpeed getVelocity() const; 71 | 72 | /** 73 | * Returns the last calculated acceleration. 74 | */ 75 | virtual QAngularAcceleration getAccel() const; 76 | 77 | protected: 78 | Logger *logger; 79 | QAngularSpeed vel{0_rpm}; 80 | QAngularSpeed lastVel{0_rpm}; 81 | QAngularAcceleration accel{0.0}; 82 | double lastPos{0}; 83 | double ticksPerRev; 84 | 85 | QTime sampleTime; 86 | std::unique_ptr loopDtTimer; 87 | std::shared_ptr filter; 88 | }; 89 | } // namespace okapi 90 | -------------------------------------------------------------------------------- /include/display/lv_objx/lv_objx_templ.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.h 3 | * 4 | */ 5 | 6 | /* TODO Remove these instructions 7 | * Search an replace: template -> object normal name with lower case (e.g. 8 | * button, label etc.) 9 | * templ -> object short name with lower case(e.g. btn, label 10 | * etc) 11 | * TEMPL -> object short name with upper case (e.g. BTN, 12 | * LABEL etc.) 13 | * 14 | */ 15 | 16 | #ifndef LV_TEMPL_H 17 | #define LV_TEMPL_H 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /********************* 24 | * INCLUDES 25 | *********************/ 26 | #include "display/lv_conf.h" 27 | #if USE_LV_TEMPL != 0 28 | 29 | #include "display/lv_core/lv_obj.h" 30 | 31 | /********************* 32 | * DEFINES 33 | *********************/ 34 | 35 | /********************** 36 | * TYPEDEFS 37 | **********************/ 38 | /*Data of template*/ 39 | typedef struct { 40 | lv_ANCESTOR_ext_t ANCESTOR; /*Ext. of ancestor*/ 41 | /*New data for this type */ 42 | } lv_templ_ext_t; 43 | 44 | /*Styles*/ 45 | typedef enum { 46 | LV_TEMPL_STYLE_X, 47 | LV_TEMPL_STYLE_Y, 48 | } lv_templ_style_t; 49 | 50 | /********************** 51 | * GLOBAL PROTOTYPES 52 | **********************/ 53 | 54 | /** 55 | * Create a template objects 56 | * @param par pointer to an object, it will be the parent of the new template 57 | * @param copy pointer to a template object, if not NULL then the new object 58 | * will be copied from it 59 | * @return pointer to the created template 60 | */ 61 | lv_obj_t *lv_templ_create(lv_obj_t *par, lv_obj_t *copy); 62 | 63 | /*====================== 64 | * Add/remove functions 65 | *=====================*/ 66 | 67 | /*===================== 68 | * Setter functions 69 | *====================*/ 70 | 71 | /** 72 | * Set a style of a template. 73 | * @param templ pointer to template object 74 | * @param type which style should be set 75 | * @param style pointer to a style 76 | * */ 77 | void lv_templ_set_style(lv_obj_t *templ, lv_templ_style_t type, 78 | lv_style_t *style); 79 | 80 | /*===================== 81 | * Getter functions 82 | *====================*/ 83 | 84 | /** 85 | * Get style of a template. 86 | * @param templ pointer to template object 87 | * @param type which style should be get 88 | * @return style pointer to the style 89 | * */ 90 | lv_style_t *lv_btn_get_style(lv_obj_t *templ, lv_templ_style_t type); 91 | 92 | /*===================== 93 | * Other functions 94 | *====================*/ 95 | 96 | /********************** 97 | * MACROS 98 | **********************/ 99 | 100 | #endif /*USE_LV_TEMPL*/ 101 | 102 | #ifdef __cplusplus 103 | } /* extern "C" */ 104 | #endif 105 | 106 | #endif /*LV_TEMPL_H*/ 107 | -------------------------------------------------------------------------------- /include/display/lv_draw/lv_draw_vbasic.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_vbasic.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_VBASIC_H 7 | #define LV_DRAW_VBASIC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "display/lv_conf.h" 17 | 18 | #if LV_VDB_SIZE != 0 19 | 20 | #include "display/lv_misc/lv_area.h" 21 | #include "display/lv_misc/lv_color.h" 22 | #include "display/lv_misc/lv_font.h" 23 | 24 | /********************* 25 | * DEFINES 26 | *********************/ 27 | 28 | /********************** 29 | * TYPEDEFS 30 | **********************/ 31 | 32 | /********************** 33 | * GLOBAL PROTOTYPES 34 | **********************/ 35 | 36 | void lv_vpx(lv_coord_t x, lv_coord_t y, const lv_area_t *mask_p, 37 | lv_color_t color, lv_opa_t opa); 38 | /** 39 | * Fill an area in the Virtual Display Buffer 40 | * @param cords_p coordinates of the area to fill 41 | * @param mask_p fill only o this mask 42 | * @param color fill color 43 | * @param opa opacity of the area (0..255) 44 | */ 45 | void lv_vfill(const lv_area_t *cords_p, const lv_area_t *mask_p, 46 | lv_color_t color, lv_opa_t opa); 47 | 48 | /** 49 | * Draw a letter in the Virtual Display Buffer 50 | * @param pos_p left-top coordinate of the latter 51 | * @param mask_p the letter will be drawn only on this area 52 | * @param font_p pointer to font 53 | * @param letter a letter to draw 54 | * @param color color of letter 55 | * @param opa opacity of letter (0..255) 56 | */ 57 | void lv_vletter(const lv_point_t *pos_p, const lv_area_t *mask_p, 58 | const lv_font_t *font_p, uint32_t letter, lv_color_t color, 59 | lv_opa_t opa); 60 | 61 | /** 62 | * Draw a color map to the display (image) 63 | * @param cords_p coordinates the color map 64 | * @param mask_p the map will drawn only on this area (truncated to VDB area) 65 | * @param map_p pointer to a lv_color_t array 66 | * @param opa opacity of the map 67 | * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color 68 | * pixels 69 | * @param alpha_byte true: extra alpha byte is inserted for every pixel 70 | * @param recolor mix the pixels with this color 71 | * @param recolor_opa the intense of recoloring 72 | */ 73 | void lv_vmap(const lv_area_t *cords_p, const lv_area_t *mask_p, 74 | const uint8_t *map_p, lv_opa_t opa, bool chroma_key, 75 | bool alpha_byte, lv_color_t recolor, lv_opa_t recolor_opa); 76 | 77 | /** 78 | * Reallocate 'color_map_tmp' to the new hor. res. size. It is used in 'sw_fill' 79 | */ 80 | void lv_vdraw_refresh_temp_arrays(void); 81 | 82 | /********************** 83 | * MACROS 84 | **********************/ 85 | 86 | #endif /*LV_VDB_SIZE != 0*/ 87 | 88 | #ifdef __cplusplus 89 | } /* extern "C" */ 90 | #endif 91 | 92 | #endif /*LV_DRAW_RBASIC_H*/ 93 | -------------------------------------------------------------------------------- /include/okapi/api/units/QLength.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Mikhail Semenov 3 | * @author Benjamin Jurke 4 | * @author Ryan Benasutti, WPI 5 | * 6 | * This code is a modified version of Benjamin Jurke's work in 2015. You can read his blog post 7 | * here: 8 | * https://benjaminjurke.com/content/articles/2015/compile-time-numerical-unit-dimension-checking/ 9 | * 10 | * This Source Code Form is subject to the terms of the Mozilla Public 11 | * License, v. 2.0. If a copy of the MPL was not distributed with this 12 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13 | */ 14 | #pragma once 15 | 16 | #include "okapi/api/units/RQuantity.hpp" 17 | 18 | namespace okapi { 19 | QUANTITY_TYPE(0, 1, 0, 0, QLength) 20 | 21 | constexpr QLength meter(1.0); // SI base unit 22 | constexpr QLength decimeter = meter / 10; 23 | constexpr QLength centimeter = meter / 100; 24 | constexpr QLength millimeter = meter / 1000; 25 | constexpr QLength kilometer = 1000 * meter; 26 | constexpr QLength inch = 2.54 * centimeter; 27 | constexpr QLength foot = 12 * inch; 28 | constexpr QLength yard = 3 * foot; 29 | constexpr QLength mile = 5280 * foot; 30 | 31 | inline namespace literals { 32 | constexpr QLength operator"" _mm(long double x) { 33 | return static_cast(x) * millimeter; 34 | } 35 | constexpr QLength operator"" _cm(long double x) { 36 | return static_cast(x) * centimeter; 37 | } 38 | constexpr QLength operator"" _m(long double x) { 39 | return static_cast(x) * meter; 40 | } 41 | constexpr QLength operator"" _km(long double x) { 42 | return static_cast(x) * kilometer; 43 | } 44 | constexpr QLength operator"" _mi(long double x) { 45 | return static_cast(x) * mile; 46 | } 47 | constexpr QLength operator"" _yd(long double x) { 48 | return static_cast(x) * yard; 49 | } 50 | constexpr QLength operator"" _ft(long double x) { 51 | return static_cast(x) * foot; 52 | } 53 | constexpr QLength operator"" _in(long double x) { 54 | return static_cast(x) * inch; 55 | } 56 | constexpr QLength operator"" _mm(unsigned long long int x) { 57 | return static_cast(x) * millimeter; 58 | } 59 | constexpr QLength operator"" _cm(unsigned long long int x) { 60 | return static_cast(x) * centimeter; 61 | } 62 | constexpr QLength operator"" _m(unsigned long long int x) { 63 | return static_cast(x) * meter; 64 | } 65 | constexpr QLength operator"" _km(unsigned long long int x) { 66 | return static_cast(x) * kilometer; 67 | } 68 | constexpr QLength operator"" _mi(unsigned long long int x) { 69 | return static_cast(x) * mile; 70 | } 71 | constexpr QLength operator"" _yd(unsigned long long int x) { 72 | return static_cast(x) * yard; 73 | } 74 | constexpr QLength operator"" _ft(unsigned long long int x) { 75 | return static_cast(x) * foot; 76 | } 77 | constexpr QLength operator"" _in(unsigned long long int x) { 78 | return static_cast(x) * inch; 79 | } 80 | } // namespace literals 81 | } // namespace okapi 82 | -------------------------------------------------------------------------------- /include/display/lv_draw/lv_draw_rbasic.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_rbasic..h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_RBASIC_H 7 | #define LV_DRAW_RBASIC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "display/lv_conf.h" 17 | #if USE_LV_REAL_DRAW != 0 18 | 19 | #include "display/lv_misc/lv_area.h" 20 | #include "display/lv_misc/lv_color.h" 21 | #include "display/lv_misc/lv_font.h" 22 | 23 | /********************* 24 | * DEFINES 25 | *********************/ 26 | 27 | /********************** 28 | * TYPEDEFS 29 | **********************/ 30 | 31 | /********************** 32 | * GLOBAL PROTOTYPES 33 | **********************/ 34 | 35 | void lv_rpx(lv_coord_t x, lv_coord_t y, const lv_area_t *mask_p, 36 | lv_color_t color, lv_opa_t opa); 37 | 38 | /** 39 | * Fill an area on the display 40 | * @param cords_p coordinates of the area to fill 41 | * @param mask_p fill only o this mask 42 | * @param color fill color 43 | * @param opa opacity (ignored, only for compatibility with lv_vfill) 44 | */ 45 | void lv_rfill(const lv_area_t *cords_p, const lv_area_t *mask_p, 46 | lv_color_t color, lv_opa_t opa); 47 | 48 | /** 49 | * Draw a letter to the display 50 | * @param pos_p left-top coordinate of the latter 51 | * @param mask_p the letter will be drawn only on this area 52 | * @param font_p pointer to font 53 | * @param letter a letter to draw 54 | * @param color color of letter 55 | * @param opa opacity of letter (ignored, only for compatibility with 56 | * lv_vletter) 57 | */ 58 | void lv_rletter(const lv_point_t *pos_p, const lv_area_t *mask_p, 59 | const lv_font_t *font_p, uint32_t letter, lv_color_t color, 60 | lv_opa_t opa); 61 | 62 | /** 63 | * When the letter is ant-aliased it needs to know the background color 64 | * @param bg_color the background color of the currently drawn letter 65 | */ 66 | void lv_rletter_set_background(lv_color_t color); 67 | 68 | /** 69 | * Draw a color map to the display (image) 70 | * @param cords_p coordinates the color map 71 | * @param mask_p the map will drawn only on this area 72 | * @param map_p pointer to a lv_color_t array 73 | * @param opa opacity of the map (ignored, only for compatibility with 74 | * 'lv_vmap') 75 | * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color 76 | * pixels 77 | * @param alpha_byte true: extra alpha byte is inserted for every pixel (not 78 | * supported, only l'v_vmap' can draw it) 79 | * @param recolor mix the pixels with this color 80 | * @param recolor_opa the intense of recoloring 81 | */ 82 | void lv_rmap(const lv_area_t *cords_p, const lv_area_t *mask_p, 83 | const uint8_t *map_p, lv_opa_t opa, bool chroma_key, 84 | bool alpha_byte, lv_color_t recolor, lv_opa_t recolor_opa); 85 | /********************** 86 | * MACROS 87 | **********************/ 88 | 89 | #endif /*USE_LV_REAL_DRAW*/ 90 | 91 | #ifdef __cplusplus 92 | } /* extern "C" */ 93 | #endif 94 | 95 | #endif /*LV_DRAW_RBASIC_H*/ 96 | -------------------------------------------------------------------------------- /include/okapi/api/chassis/controller/chassisScales.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/units/QAngle.hpp" 11 | #include "okapi/api/units/QLength.hpp" 12 | #include "okapi/api/units/RQuantity.hpp" 13 | #include 14 | #include 15 | 16 | namespace okapi { 17 | class ChassisScales { 18 | public: 19 | /** 20 | * The two scales a Chassis Controller needs to do all of its closed-loop control. First index is 21 | * the straight scale, second index is the turn scale. The straight scale converts motor degrees 22 | * to meters and the turn scale converts motor degrees to robot turn degrees. Read the clawbot 23 | * programming tutorial for more information behind the meaning of these two numbers. 24 | * 25 | * @param iscales {straight scale, turn scale} 26 | */ 27 | ChassisScales(const std::initializer_list &iscales) { 28 | std::vector vec(iscales); 29 | straight = vec.at(0); 30 | turn = vec.at(1); 31 | wheelDiameter = (360 / (straight * 1_pi)) * meter; 32 | wheelbaseWidth = turn * wheelDiameter; 33 | } 34 | 35 | /** 36 | * The two scales a Chassis Controller needs to do all of its closed-loop control. First index is 37 | * the wheel diameter, second index is the wheelbase width. Read the clawbot programming tutorial 38 | * for more information behind the meaning of these two numbers. 39 | * 40 | * The wheelbase diameter is the center-to-center distance between the wheels (center-to-center 41 | * meaning the width between the centers of both wheels). For example, if you are using four inch 42 | * omni wheels and there are 11.5 inches between the centers of each wheel, you would call the 43 | * constructor like so: 44 | * ChassisScales scales({4_in, 11.5_in}); 45 | * 46 | * Wheel diameter 47 | * 48 | * +-+ 49 | * | | 50 | * v v 51 | * 52 | * +---> === === 53 | * | + + 54 | * | ++---------------++ 55 | * | | | 56 | * Wheelbase Width | | | 57 | * | | | 58 | * | | | 59 | * | ++---------------++ 60 | * | + + 61 | * +---> === === 62 | * 63 | * 64 | * @param iwheelbase {wheel diameter, wheelbase width} 65 | */ 66 | ChassisScales(const std::initializer_list &iwheelbase) { 67 | std::vector vec(iwheelbase); 68 | wheelDiameter = vec.at(0); 69 | wheelbaseWidth = vec.at(1); 70 | straight = static_cast(360 / (wheelDiameter.convert(meter) * 1_pi)); 71 | turn = wheelbaseWidth.convert(meter) / wheelDiameter.convert(meter); 72 | } 73 | 74 | virtual ~ChassisScales() = default; 75 | 76 | double straight; 77 | double turn; 78 | QLength wheelDiameter; 79 | QLength wheelbaseWidth; 80 | }; 81 | } // namespace okapi 82 | -------------------------------------------------------------------------------- /include/display/README.md: -------------------------------------------------------------------------------- 1 | # Littlev Graphics Libraray 2 | 3 | ![LittlevGL cover](http://www.gl.littlev.hu/home/main_cover_small.png) 4 | 5 | LittlevGL provides everything you need to create a Graphical User Interface (GUI) on embedded systems with easy-to-use graphical elements, beautiful visual effects and low memory footprint. 6 | 7 | Homepage: https://littlevgl.com 8 | 9 | ### Table Of Content 10 | * [Key features](#key-features) 11 | * [Porting](#porting) 12 | * [Project set-up](#project-set-up) 13 | * [PC simulator](#pc-simulator) 14 | * [Screenshots](#screenshots) 15 | * [Contributing](#contributing) 16 | * [Donate](#donate) 17 | 18 | ## Key features 19 | * Powerful building blocks buttons, charts, lists, sliders, images etc 20 | * Advanced graphics with animations, anti-aliasing, opacity, smooth scrolling 21 | * Various input devices touch pad, mouse, keyboard, encoder, buttons etc 22 | * Multi language support with UTF-8 decoding 23 | * Fully customizable graphical elements 24 | * Hardware independent to use with any microcontroller or display 25 | * Scalable to operate with few memory (50 kB Flash, 10 kB RAM) 26 | * OS, External memory and GPU supported but not required 27 | * Single frame buffer operation even with advances graphical effects 28 | * Written in C for maximal compatibility 29 | * Simulator to develop on PC without embedded hardware 30 | * Tutorials, examples, themes for rapid development 31 | * Documentation and API references online 32 | 33 | ## Porting 34 | In the most sime case you need 4 things: 35 | 1. Call `lv_tick_inc(1)` in every millisecods in a Timer or Task 36 | 2. Register a function which can **copy a pixel array** to an area of the screen 37 | 3. Register a function which can **read an input device**. (E.g. touch pad) 38 | 4. Call `lv_task_handler()` periodically in every few milliseconds 39 | For more information visit https://littlevgl.com/porting 40 | 41 | ## Project set-up 42 | 1. **Clone** or [Download](https://littlevgl.com/download) the lvgl repository: `git clone https://github.com/littlevgl/lvgl.git` 43 | 2. **Create project** with your preferred IDE and add the *lvgl* folder 44 | 3. Copy **lvgl/lv_conf_templ.h** as **lv_conf.h** next to the *lvgl* folder 45 | 4. In the lv_conf.h delete the first `#if 0` and its `#endif`. Let the default configurations at first. 46 | 5. In your *main.c*: #include "lvgl/lvgl.h" 47 | 6. In your *main function*: 48 | * lvgl_init(); 49 | * tick, display and input device initialization (see above) 50 | 7. To **test** create a label: `lv_obj_t * label = lv_label_create(lv_scr_act(), NULL);` 51 | 8. In the main *while(1)* call `lv_task_handler();` and make a few milliseconds delay (e.g. `my_delay_ms(5);`) 52 | 9. Compile the code and load it to your embedded hardware 53 | 54 | ## PC Simulator 55 | If you don't have got an embedded hardware you can test the graphics library in a PC simulator. The simulator uses [SDL2](https://www.libsdl.org/) to emulate a display on your monitor and a touch pad with your mouse. 56 | 57 | There is a pre-configured PC project for **Eclipse CDT** in this repository: https://github.com/littlevgl/pc_simulator 58 | 59 | ## Screenshots 60 | ![TFT material](http://www.gl.littlev.hu/github_res/tft_material.png) 61 | ![TFT zen](http://www.gl.littlev.hu/github_res/tft_zen.png) 62 | ![TFT alien](http://www.gl.littlev.hu/github_res/tft_alien.png) 63 | ![TFT night](http://www.gl.littlev.hu/github_res/tft_night.png) 64 | 65 | ## Contributing 66 | See [CONTRIBUTING.md](https://github.com/littlevgl/lvgl/blob/master/docs/CONTRIBUTING.md) 67 | 68 | ## Donate 69 | If you are pleased with the graphics library, found it useful or be happy with the support you got, please help its further development: 70 | 71 | [![Donate](https://littlevgl.com/donate_dir/donate_btn.png)](https://littlevgl.com/donate) 72 | -------------------------------------------------------------------------------- /include/display/lv_misc/lv_task.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_task.c 3 | * An 'lv_task' is a void (*fp) (void* param) type function which will be 4 | * called periodically. 5 | * A priority (5 levels + disable) can be assigned to lv_tasks. 6 | */ 7 | 8 | #ifndef LV_TASK_H 9 | #define LV_TASK_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | /********************* 16 | * INCLUDES 17 | *********************/ 18 | #include "lv_ll.h" 19 | #include "lv_mem.h" 20 | #include 21 | #include 22 | 23 | /********************* 24 | * DEFINES 25 | *********************/ 26 | #ifndef LV_ATTRIBUTE_TASK_HANDLER 27 | #define LV_ATTRIBUTE_TASK_HANDLER 28 | #endif 29 | /********************** 30 | * TYPEDEFS 31 | **********************/ 32 | /** 33 | * Possible priorities for lv_tasks 34 | */ 35 | typedef enum { 36 | LV_TASK_PRIO_OFF = 0, 37 | LV_TASK_PRIO_LOWEST, 38 | LV_TASK_PRIO_LOW, 39 | LV_TASK_PRIO_MID, 40 | LV_TASK_PRIO_HIGH, 41 | LV_TASK_PRIO_HIGHEST, 42 | LV_TASK_PRIO_NUM, 43 | } lv_task_prio_t; 44 | 45 | /** 46 | * Descriptor of a lv_task 47 | */ 48 | typedef struct { 49 | uint32_t period; 50 | uint32_t last_run; 51 | void (*task)(void *); 52 | void *param; 53 | uint8_t prio : 3; 54 | uint8_t once : 1; 55 | } lv_task_t; 56 | 57 | /********************** 58 | * GLOBAL PROTOTYPES 59 | **********************/ 60 | 61 | /** 62 | * Init the lv_task module 63 | */ 64 | void lv_task_init(void); 65 | 66 | /** 67 | * Call it periodically to handle lv_tasks. 68 | */ 69 | LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void); 70 | 71 | /** 72 | * Create a new lv_task 73 | * @param task a function which is the task itself 74 | * @param period call period in ms unit 75 | * @param prio priority of the task (LV_TASK_PRIO_OFF means the task is stopped) 76 | * @param param free parameter 77 | * @return pointer to the new task 78 | */ 79 | lv_task_t *lv_task_create(void (*task)(void *), uint32_t period, 80 | lv_task_prio_t prio, void *param); 81 | 82 | /** 83 | * Delete a lv_task 84 | * @param lv_task_p pointer to task created by lv_task_p 85 | */ 86 | void lv_task_del(lv_task_t *lv_task_p); 87 | 88 | /** 89 | * Set new priority for a lv_task 90 | * @param lv_task_p pointer to a lv_task 91 | * @param prio the new priority 92 | */ 93 | void lv_task_set_prio(lv_task_t *lv_task_p, lv_task_prio_t prio); 94 | 95 | /** 96 | * Set new period for a lv_task 97 | * @param lv_task_p pointer to a lv_task 98 | * @param period the new period 99 | */ 100 | void lv_task_set_period(lv_task_t *lv_task_p, uint32_t period); 101 | 102 | /** 103 | * Make a lv_task ready. It will not wait its period. 104 | * @param lv_task_p pointer to a lv_task. 105 | */ 106 | void lv_task_ready(lv_task_t *lv_task_p); 107 | 108 | /** 109 | * Delete the lv_task after one call 110 | * @param lv_task_p pointer to a lv_task. 111 | */ 112 | void lv_task_once(lv_task_t *lv_task_p); 113 | 114 | /** 115 | * Reset a lv_task. 116 | * It will be called the previously set period milliseconds later. 117 | * @param lv_task_p pointer to a lv_task. 118 | */ 119 | void lv_task_reset(lv_task_t *lv_task_p); 120 | 121 | /** 122 | * Enable or disable the whole lv_task handling 123 | * @param en: true: lv_task handling is running, false: lv_task handling is 124 | * suspended 125 | */ 126 | void lv_task_enable(bool en); 127 | 128 | /** 129 | * Get idle percentage 130 | * @return the lv_task idle in percentage 131 | */ 132 | uint8_t lv_task_get_idle(void); 133 | 134 | /********************** 135 | * MACROS 136 | **********************/ 137 | 138 | #ifdef __cplusplus 139 | } /* extern "C" */ 140 | #endif 141 | 142 | #endif 143 | -------------------------------------------------------------------------------- /include/okapi/api/control/async/asyncVelIntegratedController.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/async/asyncVelocityController.hpp" 11 | #include "okapi/api/device/motor/abstractMotor.hpp" 12 | #include "okapi/api/util/logging.hpp" 13 | #include "okapi/api/util/timeUtil.hpp" 14 | #include 15 | 16 | namespace okapi { 17 | /** 18 | * Closed-loop controller that uses the V5 motor's onboard control to move. Input units are whatever 19 | * units the motor is in. 20 | */ 21 | class AsyncVelIntegratedController : public AsyncVelocityController { 22 | public: 23 | AsyncVelIntegratedController(const std::shared_ptr &imotor, 24 | const TimeUtil &itimeUtil); 25 | 26 | /** 27 | * Sets the target for the controller. 28 | */ 29 | void setTarget(double itarget) override; 30 | 31 | /** 32 | * Gets the last set target, or the default target if none was set. 33 | * 34 | * @return the last target 35 | */ 36 | double getTarget() override; 37 | 38 | /** 39 | * Returns the last error of the controller. Does not update when disabled. 40 | */ 41 | double getError() const override; 42 | 43 | /** 44 | * Returns whether the controller has settled at the target. Determining what settling means is 45 | * implementation-dependent. 46 | * 47 | * If the controller is disabled, this method must return true. 48 | * 49 | * @return whether the controller is settled 50 | */ 51 | bool isSettled() override; 52 | 53 | /** 54 | * Resets the controller's internal state so it is similar to when it was first initialized, while 55 | * keeping any user-configured information. 56 | */ 57 | void reset() override; 58 | 59 | /** 60 | * Changes whether the controller is off or on. Turning the controller on after it was off will 61 | * cause the controller to move to its last set target, unless it was reset in that time. 62 | */ 63 | void flipDisable() override; 64 | 65 | /** 66 | * Sets whether the controller is off or on. Turning the controller on after it was off will 67 | * cause the controller to move to its last set target, unless it was reset in that time. 68 | * 69 | * @param iisDisabled whether the controller is disabled 70 | */ 71 | void flipDisable(bool iisDisabled) override; 72 | 73 | /** 74 | * Returns whether the controller is currently disabled. 75 | * 76 | * @return whether the controller is currently disabled 77 | */ 78 | bool isDisabled() const override; 79 | 80 | /** 81 | * Blocks the current task until the controller has settled. Determining what settling means is 82 | * implementation-dependent. 83 | */ 84 | void waitUntilSettled() override; 85 | 86 | /** 87 | * Writes the value of the controller output. This method might be automatically called in another 88 | * thread by the controller. The range of input values is expected to be [-1, 1]. 89 | * 90 | * @param ivalue the controller's output in the range [-1, 1] 91 | */ 92 | void controllerSet(double ivalue) override; 93 | 94 | protected: 95 | Logger *logger; 96 | std::shared_ptr motor; 97 | double lastTarget = 0; 98 | bool controllerIsDisabled = false; 99 | bool hasFirstTarget = false; 100 | std::unique_ptr settledUtil; 101 | std::unique_ptr rate; 102 | 103 | virtual void resumeMovement(); 104 | }; 105 | } // namespace okapi 106 | -------------------------------------------------------------------------------- /include/display/lv_objx/lv_bar.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_bar.h 3 | * 4 | */ 5 | 6 | #ifndef LV_BAR_H 7 | #define LV_BAR_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "display/lv_conf.h" 17 | #if USE_LV_BAR != 0 18 | 19 | #include "display/lv_core/lv_obj.h" 20 | #include "lv_btn.h" 21 | #include "lv_cont.h" 22 | #include "lv_label.h" 23 | 24 | /********************* 25 | * DEFINES 26 | *********************/ 27 | 28 | /********************** 29 | * TYPEDEFS 30 | **********************/ 31 | 32 | /*Data of bar*/ 33 | typedef struct { 34 | /*No inherited ext*/ /*Ext. of ancestor*/ 35 | /*New data for this type */ 36 | int16_t cur_value; /*Current value of the bar*/ 37 | int16_t min_value; /*Minimum value of the bar*/ 38 | int16_t max_value; /*Maximum value of the bar*/ 39 | lv_style_t *style_indic; /*Style of the indicator*/ 40 | } lv_bar_ext_t; 41 | 42 | typedef enum { 43 | LV_BAR_STYLE_BG, 44 | LV_BAR_STYLE_INDIC, 45 | } lv_bar_style_t; 46 | 47 | /********************** 48 | * GLOBAL PROTOTYPES 49 | **********************/ 50 | 51 | /** 52 | * Create a bar objects 53 | * @param par pointer to an object, it will be the parent of the new bar 54 | * @param copy pointer to a bar object, if not NULL then the new object will be 55 | * copied from it 56 | * @return pointer to the created bar 57 | */ 58 | lv_obj_t *lv_bar_create(lv_obj_t *par, lv_obj_t *copy); 59 | 60 | /*===================== 61 | * Setter functions 62 | *====================*/ 63 | 64 | /** 65 | * Set a new value on the bar 66 | * @param bar pointer to a bar object 67 | * @param value new value 68 | */ 69 | void lv_bar_set_value(lv_obj_t *bar, int16_t value); 70 | 71 | /** 72 | * Set a new value with animation on the bar 73 | * @param bar pointer to a bar object 74 | * @param value new value 75 | * @param anim_time animation time in milliseconds 76 | */ 77 | void lv_bar_set_value_anim(lv_obj_t *bar, int16_t value, uint16_t anim_time); 78 | 79 | /** 80 | * Set minimum and the maximum values of a bar 81 | * @param bar pointer to the bar object 82 | * @param min minimum value 83 | * @param max maximum value 84 | */ 85 | void lv_bar_set_range(lv_obj_t *bar, int16_t min, int16_t max); 86 | 87 | /** 88 | * Set a style of a bar 89 | * @param bar pointer to a bar object 90 | * @param type which style should be set 91 | * @param style pointer to a style 92 | */ 93 | void lv_bar_set_style(lv_obj_t *bar, lv_bar_style_t type, lv_style_t *style); 94 | 95 | /*===================== 96 | * Getter functions 97 | *====================*/ 98 | 99 | /** 100 | * Get the value of a bar 101 | * @param bar pointer to a bar object 102 | * @return the value of the bar 103 | */ 104 | int16_t lv_bar_get_value(lv_obj_t *bar); 105 | 106 | /** 107 | * Get the minimum value of a bar 108 | * @param bar pointer to a bar object 109 | * @return the minimum value of the bar 110 | */ 111 | int16_t lv_bar_get_min_value(lv_obj_t *bar); 112 | 113 | /** 114 | * Get the maximum value of a bar 115 | * @param bar pointer to a bar object 116 | * @return the maximum value of the bar 117 | */ 118 | int16_t lv_bar_get_max_value(lv_obj_t *bar); 119 | 120 | /** 121 | * Get a style of a bar 122 | * @param bar pointer to a bar object 123 | * @param type which style should be get 124 | * @return style pointer to a style 125 | */ 126 | lv_style_t *lv_bar_get_style(lv_obj_t *bar, lv_bar_style_t type); 127 | 128 | /********************** 129 | * MACROS 130 | **********************/ 131 | 132 | #endif /*USE_LV_BAR*/ 133 | 134 | #ifdef __cplusplus 135 | } /* extern "C" */ 136 | #endif 137 | 138 | #endif /*LV_BAR_H*/ 139 | -------------------------------------------------------------------------------- /include/display/lv_objx/lv_sw.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_sw.h 3 | * 4 | */ 5 | 6 | #ifndef LV_SW_H 7 | #define LV_SW_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "display/lv_conf.h" 17 | #if USE_LV_SW != 0 18 | 19 | /*Testing of dependencies*/ 20 | #if USE_LV_SLIDER == 0 21 | #error "lv_sw: lv_slider is required. Enable it in lv_conf.h (USE_LV_SLIDER 1)" 22 | #endif 23 | 24 | #include "display/lv_core/lv_obj.h" 25 | #include "display/lv_objx/lv_slider.h" 26 | 27 | /********************* 28 | * DEFINES 29 | *********************/ 30 | 31 | /********************** 32 | * TYPEDEFS 33 | **********************/ 34 | /*Data of switch*/ 35 | typedef struct { 36 | lv_slider_ext_t slider; /*Ext. of ancestor*/ 37 | /*New data for this type */ 38 | lv_style_t *style_knob_off; /*Style of the knob when the switch is OFF*/ 39 | lv_style_t *style_knob_on; /*Style of the knob when the switch is ON (NULL to 40 | use the same as OFF)*/ 41 | uint8_t changed : 1; /*Indicates the switch explicitly changed by drag*/ 42 | } lv_sw_ext_t; 43 | 44 | typedef enum { 45 | LV_SW_STYLE_BG, 46 | LV_SW_STYLE_INDIC, 47 | LV_SW_STYLE_KNOB_OFF, 48 | LV_SW_STYLE_KNOB_ON, 49 | } lv_sw_style_t; 50 | 51 | /********************** 52 | * GLOBAL PROTOTYPES 53 | **********************/ 54 | 55 | /** 56 | * Create a switch objects 57 | * @param par pointer to an object, it will be the parent of the new switch 58 | * @param copy pointer to a switch object, if not NULL then the new object will 59 | * be copied from it 60 | * @return pointer to the created switch 61 | */ 62 | lv_obj_t *lv_sw_create(lv_obj_t *par, lv_obj_t *copy); 63 | 64 | /*===================== 65 | * Setter functions 66 | *====================*/ 67 | 68 | /** 69 | * Turn ON the switch 70 | * @param sw pointer to a switch object 71 | */ 72 | void lv_sw_on(lv_obj_t *sw); 73 | 74 | /** 75 | * Turn OFF the switch 76 | * @param sw pointer to a switch object 77 | */ 78 | void lv_sw_off(lv_obj_t *sw); 79 | 80 | /** 81 | * Set a function which will be called when the switch is toggled by the user 82 | * @param sw pointer to switch object 83 | * @param action a callback function 84 | */ 85 | static inline void lv_sw_set_action(lv_obj_t *sw, lv_action_t action) { 86 | lv_slider_set_action(sw, action); 87 | } 88 | 89 | /** 90 | * Set a style of a switch 91 | * @param sw pointer to a switch object 92 | * @param type which style should be set 93 | * @param style pointer to a style 94 | */ 95 | void lv_sw_set_style(lv_obj_t *sw, lv_sw_style_t type, lv_style_t *style); 96 | 97 | /*===================== 98 | * Getter functions 99 | *====================*/ 100 | 101 | /** 102 | * Get the state of a switch 103 | * @param sw pointer to a switch object 104 | * @return false: OFF; true: ON 105 | */ 106 | static inline bool lv_sw_get_state(lv_obj_t *sw) { 107 | return lv_bar_get_value(sw) == 0 ? false : true; 108 | } 109 | 110 | /** 111 | * Get the switch action function 112 | * @param slider pointer to a switch object 113 | * @return the callback function 114 | */ 115 | static inline lv_action_t lv_sw_get_action(lv_obj_t *slider) { 116 | return lv_slider_get_action(slider); 117 | } 118 | 119 | /** 120 | * Get a style of a switch 121 | * @param sw pointer to a switch object 122 | * @param type which style should be get 123 | * @return style pointer to a style 124 | */ 125 | lv_style_t *lv_sw_get_style(lv_obj_t *sw, lv_sw_style_t type); 126 | 127 | /********************** 128 | * MACROS 129 | **********************/ 130 | 131 | #endif /*USE_LV_SW*/ 132 | 133 | #ifdef __cplusplus 134 | } /* extern "C" */ 135 | #endif 136 | 137 | #endif /*LV_SW_H*/ 138 | -------------------------------------------------------------------------------- /include/okapi/impl/control/iterative/iterativeControllerFactory.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/iterative/iterativeMotorVelocityController.hpp" 11 | #include "okapi/api/control/iterative/iterativePosPidController.hpp" 12 | #include "okapi/api/control/iterative/iterativeVelPidController.hpp" 13 | #include "okapi/api/util/mathUtil.hpp" 14 | #include "okapi/impl/device/motor/motor.hpp" 15 | #include "okapi/impl/device/motor/motorGroup.hpp" 16 | 17 | namespace okapi { 18 | class IterativeControllerFactory { 19 | public: 20 | /** 21 | * Position PID controller. 22 | * 23 | * @param ikP proportional gain 24 | * @param ikI integral gain 25 | * @param ikD derivative gain 26 | * @param ikBias controller bias (constant offset added to the output) 27 | */ 28 | static IterativePosPIDController 29 | posPID(double ikP, 30 | double ikI, 31 | double ikD, 32 | double ikBias = 0, 33 | std::unique_ptr iderivativeFilter = std::make_unique()); 34 | 35 | /** 36 | * Velocity PD controller. 37 | * 38 | * @param ikP proportional gain 39 | * @param ikD derivative gain 40 | * @param ikF feed-forward gain 41 | * @param ikSF a feed-forward gain to counteract static friction 42 | */ 43 | static IterativeVelPIDController 44 | velPID(double ikP, 45 | double ikD, 46 | double ikF = 0, 47 | double ikSF = 0, 48 | const VelMathArgs &iparams = VelMathArgs(imev5TPR), 49 | std::unique_ptr iderivativeFilter = std::make_unique()); 50 | 51 | /** 52 | * Velocity PD controller that automatically writes to the motor. 53 | * 54 | * @param imotor output motor 55 | * @param ikP proportional gain 56 | * @param ikD derivative gain 57 | * @param ikF feed-forward gain 58 | * @param ikSF a feed-forward gain to counteract static friction 59 | */ 60 | static IterativeMotorVelocityController 61 | motorVelocity(Motor imotor, 62 | double ikP, 63 | double ikD, 64 | double ikF = 0, 65 | double ikSF = 0, 66 | const VelMathArgs &iparams = VelMathArgs(imev5TPR)); 67 | 68 | /** 69 | * Velocity PD controller that automatically writes to the motor. 70 | * 71 | * @param imotor output motor 72 | * @param ikP proportional gain 73 | * @param ikD derivative gain 74 | * @param ikF feed-forward gain 75 | * @param ikSF a feed-forward gain to counteract static friction 76 | */ 77 | static IterativeMotorVelocityController 78 | motorVelocity(MotorGroup imotor, 79 | double ikP, 80 | double ikD, 81 | double ikF = 0, 82 | double ikSF = 0, 83 | const VelMathArgs &iparams = VelMathArgs(imev5TPR)); 84 | 85 | /** 86 | * Velocity PD controller that automatically writes to the motor. 87 | * 88 | * @param imotor output motor 89 | * @param icontroller controller to use 90 | */ 91 | static IterativeMotorVelocityController 92 | motorVelocity(Motor imotor, 93 | std::shared_ptr> icontroller); 94 | 95 | /** 96 | * Velocity PD controller that automatically writes to the motor. 97 | * 98 | * @param imotor output motor 99 | * @param icontroller controller to use 100 | */ 101 | static IterativeMotorVelocityController 102 | motorVelocity(MotorGroup imotor, 103 | std::shared_ptr> icontroller); 104 | }; 105 | } // namespace okapi 106 | -------------------------------------------------------------------------------- /include/okapi/api/util/abstractTimer.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/units/QFrequency.hpp" 11 | #include "okapi/api/units/QTime.hpp" 12 | 13 | namespace okapi { 14 | class AbstractTimer { 15 | public: 16 | /** 17 | * A Timer base class which implements its methods in terms of millis(). 18 | * 19 | * @param ifirstCalled the current time 20 | */ 21 | explicit AbstractTimer(QTime ifirstCalled); 22 | 23 | virtual ~AbstractTimer(); 24 | 25 | /** 26 | * Returns the current time in units of QTime. 27 | * 28 | * @return the current time 29 | */ 30 | virtual QTime millis() const = 0; 31 | 32 | /** 33 | * Returns the time passed in ms since the previous call of this function. 34 | * 35 | * @return The time passed in ms since the previous call of this function 36 | */ 37 | virtual QTime getDt(); 38 | 39 | /** 40 | * Returns the time passed in ms since the previous call of getDt(). Does not change the time 41 | * recorded by getDt(). 42 | * 43 | * @return The time passed in ms since the previous call of getDt() 44 | */ 45 | virtual QTime readDt() const; 46 | 47 | /** 48 | * Returns the time the timer was first constructed. 49 | * 50 | * @return The time the timer was first constructed 51 | */ 52 | virtual QTime getStartingTime() const; 53 | 54 | /** 55 | * Returns the time since the timer was first constructed. 56 | * 57 | * @return The time since the timer was first constructed 58 | */ 59 | virtual QTime getDtFromStart() const; 60 | 61 | /** 62 | * Place a time marker. Placing another marker will overwrite the previous one. 63 | */ 64 | virtual void placeMark(); 65 | 66 | /** 67 | * Clears the marker. 68 | * 69 | * @return The old marker 70 | */ 71 | virtual QTime clearMark(); 72 | 73 | /** 74 | * Place a hard time marker. Placing another hard marker will not overwrite the previous one; 75 | * instead, call clearHardMark() and then place another. 76 | */ 77 | virtual void placeHardMark(); 78 | 79 | /** 80 | * Clears the hard marker. 81 | * 82 | * @return The old hard marker 83 | */ 84 | virtual QTime clearHardMark(); 85 | 86 | /** 87 | * Returns the time since the time marker. Returns 0_ms if there is no marker. 88 | * 89 | * @return The time since the time marker 90 | */ 91 | virtual QTime getDtFromMark() const; 92 | 93 | /** 94 | * Returns the time since the hard time marker. Returns 0_ms if there is no hard marker set. 95 | * 96 | * @return The time since the hard time marker 97 | */ 98 | virtual QTime getDtFromHardMark() const; 99 | 100 | /** 101 | * Returns true when the input time period has passed, then resets. Meant to be used in loops 102 | * to run an action every time period without blocking. 103 | * 104 | * @param time time period 105 | * @return true when the input time period has passed, false after reading true until the 106 | * period has passed again 107 | */ 108 | virtual bool repeat(QTime time); 109 | 110 | /** 111 | * Returns true when the input time period has passed, then resets. Meant to be used in loops 112 | * to run an action every time period without blocking. 113 | * 114 | * @param frequency the repeat frequency 115 | * @return true when the input time period has passed, false after reading true until the 116 | * period has passed again 117 | */ 118 | virtual bool repeat(QFrequency frequency); 119 | 120 | protected: 121 | QTime firstCalled; 122 | QTime lastCalled; 123 | QTime mark; 124 | QTime hardMark; 125 | QTime repeatMark; 126 | }; 127 | } // namespace okapi 128 | -------------------------------------------------------------------------------- /include/display/lv_misc/lv_anim.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file anim.h 3 | * 4 | */ 5 | 6 | #ifndef ANIM_H 7 | #define ANIM_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "display/lv_conf.h" 17 | #if USE_LV_ANIMATION 18 | 19 | #include 20 | #include 21 | 22 | /********************* 23 | * DEFINES 24 | *********************/ 25 | 26 | /********************** 27 | * TYPEDEFS 28 | **********************/ 29 | 30 | struct _lv_anim_t; 31 | 32 | typedef int32_t (*lv_anim_path_t)(const struct _lv_anim_t *); 33 | 34 | typedef void (*lv_anim_fp_t)(void *, int32_t); 35 | typedef void (*lv_anim_cb_t)(void *); 36 | 37 | typedef struct _lv_anim_t { 38 | void *var; /*Variable to animate*/ 39 | lv_anim_fp_t fp; /*Animator function*/ 40 | lv_anim_cb_t end_cb; /*Call it when the animation is ready*/ 41 | lv_anim_path_t path; /*An array with the steps of animations*/ 42 | int32_t start; /*Start value*/ 43 | int32_t end; /*End value*/ 44 | int16_t time; /*Animation time in ms*/ 45 | int16_t 46 | act_time; /*Current time in animation. Set to negative to make delay.*/ 47 | uint16_t playback_pause; /*Wait before play back*/ 48 | uint16_t repeat_pause; /*Wait before repeat*/ 49 | uint8_t playback : 1; /*When the animation is ready play it back*/ 50 | uint8_t repeat : 1; /*Repeat the animation infinitely*/ 51 | /*Animation system use these - user shouldn't set*/ 52 | uint8_t playback_now : 1; /*Play back is in progress*/ 53 | } lv_anim_t; 54 | 55 | /*Example initialization 56 | lv_anim_t a; 57 | a.var = obj; 58 | a.start = lv_obj_get_height(obj); 59 | a.end = new_height; 60 | a.fp = (lv_anim_fp_t)lv_obj_set_height; 61 | a.path = lv_anim_path_linear; 62 | a.end_cb = NULL; 63 | a.act_time = 0; 64 | a.time = 200; 65 | a.playback = 0; 66 | a.playback_pause = 0; 67 | a.repeat = 0; 68 | a.repeat_pause = 0; 69 | */ 70 | /********************** 71 | * GLOBAL PROTOTYPES 72 | **********************/ 73 | 74 | /** 75 | * Init. the animation module 76 | */ 77 | void lv_anim_init(void); 78 | 79 | /** 80 | * Create an animation 81 | * @param anim_p an initialized 'anim_t' variable. Not required after call. 82 | */ 83 | void lv_anim_create(lv_anim_t *anim_p); 84 | 85 | /** 86 | * Delete an animation for a variable with a given animatior function 87 | * @param var pointer to variable 88 | * @param fp a function pointer which is animating 'var', 89 | * or NULL to ignore it and delete all animation with 'var 90 | * @return true: at least 1 animation is deleted, false: no animation is deleted 91 | */ 92 | bool lv_anim_del(void *var, lv_anim_fp_t fp); 93 | 94 | /** 95 | * Calculate the time of an animation with a given speed and the start and end 96 | * values 97 | * @param speed speed of animation in unit/sec 98 | * @param start start value of the animation 99 | * @param end end value of the animation 100 | * @return the required time [ms] for the animation with the given parameters 101 | */ 102 | uint16_t lv_anim_speed_to_time(uint16_t speed, int32_t start, int32_t end); 103 | 104 | /** 105 | * Calculate the current value of an animation applying linear characteristic 106 | * @param a pointer to an animation 107 | * @return the current value to set 108 | */ 109 | int32_t lv_anim_path_linear(const lv_anim_t *a); 110 | 111 | /** 112 | * Calculate the current value of an animation applying step characteristic. 113 | * (Set end value on the end of the animation) 114 | * @param a pointer to an animation 115 | * @return the current value to set 116 | */ 117 | int32_t lv_anim_path_step(const lv_anim_t *a); 118 | /********************** 119 | * MACROS 120 | **********************/ 121 | 122 | #endif /*USE_LV_ANIMATION == 0*/ 123 | 124 | #ifdef __cplusplus 125 | } /* extern "C" */ 126 | #endif 127 | 128 | #endif /*LV_ANIM_H*/ 129 | -------------------------------------------------------------------------------- /include/display/lv_misc/lv_ll.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_ll.c 3 | * Handle linked lists. The nodes are dynamically allocated by the 'lv_mem' 4 | * module. 5 | */ 6 | 7 | #ifndef LV_LL_H 8 | #define LV_LL_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /********************* 15 | * INCLUDES 16 | *********************/ 17 | #include "lv_mem.h" 18 | #include 19 | #include 20 | 21 | /********************* 22 | * DEFINES 23 | *********************/ 24 | 25 | /********************** 26 | * TYPEDEFS 27 | **********************/ 28 | 29 | /*Dummy type to make handling easier*/ 30 | typedef uint8_t lv_ll_node_t; 31 | 32 | /*Description of a linked list*/ 33 | typedef struct { 34 | uint32_t n_size; 35 | lv_ll_node_t *head; 36 | lv_ll_node_t *tail; 37 | } lv_ll_t; 38 | 39 | /********************** 40 | * GLOBAL PROTOTYPES 41 | **********************/ 42 | 43 | /** 44 | * Initialize linked list 45 | * @param ll_dsc pointer to ll_dsc variable 46 | * @param node_size the size of 1 node in bytes 47 | */ 48 | void lv_ll_init(lv_ll_t *ll_p, uint32_t node_size); 49 | 50 | /** 51 | * Add a new head to a linked list 52 | * @param ll_p pointer to linked list 53 | * @return pointer to the new head 54 | */ 55 | void *lv_ll_ins_head(lv_ll_t *ll_p); 56 | 57 | /** 58 | * Insert a new node in front of the n_act node 59 | * @param ll_p pointer to linked list 60 | * @param n_act pointer a node 61 | * @return pointer to the new head 62 | */ 63 | void *lv_ll_ins_prev(lv_ll_t *ll_p, void *n_act); 64 | 65 | /** 66 | * Add a new tail to a linked list 67 | * @param ll_p pointer to linked list 68 | * @return pointer to the new tail 69 | */ 70 | void *lv_ll_ins_tail(lv_ll_t *ll_p); 71 | 72 | /** 73 | * Remove the node 'node_p' from 'll_p' linked list. 74 | * It Dose not free the the memory of node. 75 | * @param ll_p pointer to the linked list of 'node_p' 76 | * @param node_p pointer to node in 'll_p' linked list 77 | */ 78 | void lv_ll_rem(lv_ll_t *ll_p, void *node_p); 79 | 80 | /** 81 | * Remove and free all elements from a linked list. The list remain valid but 82 | * become empty. 83 | * @param ll_p pointer to linked list 84 | */ 85 | void lv_ll_clear(lv_ll_t *ll_p); 86 | 87 | /** 88 | * Move a node to a new linked list 89 | * @param ll_ori_p pointer to the original (old) linked list 90 | * @param ll_new_p pointer to the new linked list 91 | * @param node pointer to a node 92 | */ 93 | void lv_ll_chg_list(lv_ll_t *ll_ori_p, lv_ll_t *ll_new_p, void *node); 94 | 95 | /** 96 | * Return with head node of the linked list 97 | * @param ll_p pointer to linked list 98 | * @return pointer to the head of 'll_p' 99 | */ 100 | void *lv_ll_get_head(lv_ll_t *ll_p); 101 | 102 | /** 103 | * Return with tail node of the linked list 104 | * @param ll_p pointer to linked list 105 | * @return pointer to the head of 'll_p' 106 | */ 107 | void *lv_ll_get_tail(lv_ll_t *ll_p); 108 | 109 | /** 110 | * Return with the pointer of the next node after 'n_act' 111 | * @param ll_p pointer to linked list 112 | * @param n_act pointer a node 113 | * @return pointer to the next node 114 | */ 115 | void *lv_ll_get_next(lv_ll_t *ll_p, void *n_act); 116 | 117 | /** 118 | * Return with the pointer of the previous node after 'n_act' 119 | * @param ll_p pointer to linked list 120 | * @param n_act pointer a node 121 | * @return pointer to the previous node 122 | */ 123 | void *lv_ll_get_prev(lv_ll_t *ll_p, void *n_act); 124 | 125 | /********************** 126 | * MACROS 127 | **********************/ 128 | 129 | #define LL_READ(list, i) \ 130 | for (i = lv_ll_get_head(&list); i != NULL; i = lv_ll_get_next(&list, i)) 131 | 132 | #define LL_READ_BACK(list, i) \ 133 | for (i = lv_ll_get_tail(&list); i != NULL; i = lv_ll_get_prev(&list, i)) 134 | 135 | #ifdef __cplusplus 136 | } /* extern "C" */ 137 | #endif 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /include/display/lv_core/lv_indev.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_indev_proc.h 3 | * 4 | */ 5 | 6 | #ifndef LV_INDEV_H 7 | #define LV_INDEV_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "display/lv_core/lv_group.h" 17 | #include "display/lv_hal/lv_hal_indev.h" 18 | #include "lv_obj.h" 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | 24 | /********************** 25 | * TYPEDEFS 26 | **********************/ 27 | 28 | /********************** 29 | * GLOBAL PROTOTYPES 30 | **********************/ 31 | 32 | /** 33 | * Initialize the display input device subsystem 34 | */ 35 | void lv_indev_init(void); 36 | 37 | /** 38 | * Get the currently processed input device. Can be used in action functions 39 | * too. 40 | * @return pointer to the currently processed input device or NULL if no input 41 | * device processing right now 42 | */ 43 | lv_indev_t *lv_indev_get_act(void); 44 | 45 | /** 46 | * Reset one or all input devices 47 | * @param indev pointer to an input device to reset or NULL to reset all of them 48 | */ 49 | void lv_indev_reset(lv_indev_t *indev); 50 | 51 | /** 52 | * Reset the long press state of an input device 53 | * @param indev_proc pointer to an input device 54 | */ 55 | void lv_indev_reset_lpr(lv_indev_t *indev); 56 | 57 | /** 58 | * Enable input devices device by type 59 | * @param type Input device type 60 | * @param enable true: enable this type; false: disable this type 61 | */ 62 | void lv_indev_enable(lv_hal_indev_type_t type, bool enable); 63 | 64 | /** 65 | * Set a cursor for a pointer input device (for LV_INPUT_TYPE_POINTER and 66 | * LV_INPUT_TYPE_BUTTON) 67 | * @param indev pointer to an input device 68 | * @param cur_obj pointer to an object to be used as cursor 69 | */ 70 | void lv_indev_set_cursor(lv_indev_t *indev, lv_obj_t *cur_obj); 71 | 72 | #if USE_LV_GROUP 73 | /** 74 | * Set a destination group for a keypad input device (for LV_INDEV_TYPE_KEYPAD) 75 | * @param indev pointer to an input device 76 | * @param group point to a group 77 | */ 78 | void lv_indev_set_group(lv_indev_t *indev, lv_group_t *group); 79 | #endif 80 | 81 | /** 82 | * Set the an array of points for LV_INDEV_TYPE_BUTTON. 83 | * These points will be assigned to the buttons to press a specific point on the 84 | * screen 85 | * @param indev pointer to an input device 86 | * @param group point to a group 87 | */ 88 | void lv_indev_set_button_points(lv_indev_t *indev, lv_point_t *points); 89 | 90 | /** 91 | * Get the last point of an input device (for LV_INDEV_TYPE_POINTER and 92 | * LV_INDEV_TYPE_BUTTON) 93 | * @param indev pointer to an input device 94 | * @param point pointer to a point to store the result 95 | */ 96 | void lv_indev_get_point(lv_indev_t *indev, lv_point_t *point); 97 | 98 | /** 99 | * Check if there is dragging with an input device or not (for 100 | * LV_INDEV_TYPE_POINTER and LV_INDEV_TYPE_BUTTON) 101 | * @param indev pointer to an input device 102 | * @return true: drag is in progress 103 | */ 104 | bool lv_indev_is_dragging(lv_indev_t *indev); 105 | 106 | /** 107 | * Get the vector of dragging of an input device (for LV_INDEV_TYPE_POINTER and 108 | * LV_INDEV_TYPE_BUTTON) 109 | * @param indev pointer to an input device 110 | * @param point pointer to a point to store the vector 111 | */ 112 | void lv_indev_get_vect(lv_indev_t *indev, lv_point_t *point); 113 | /** 114 | * Get elapsed time since last press 115 | * @param indev pointer to an input device (NULL to get the overall smallest 116 | * inactivity) 117 | * @return Elapsed ticks (milliseconds) since last press 118 | */ 119 | uint32_t lv_indev_get_inactive_time(lv_indev_t *indev); 120 | 121 | /** 122 | * Do nothing until the next release 123 | * @param indev pointer to an input device 124 | */ 125 | void lv_indev_wait_release(lv_indev_t *indev); 126 | 127 | /********************** 128 | * MACROS 129 | **********************/ 130 | 131 | #ifdef __cplusplus 132 | } /* extern "C" */ 133 | #endif 134 | 135 | #endif /*LV_INDEV_H*/ 136 | -------------------------------------------------------------------------------- /include/pros/api_legacy.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file pros/api_legacy.h 3 | * 4 | * PROS 2 Legacy API header 5 | * 6 | * Contains declarations for functions that are name-compatible with the PROS 2 7 | * API. Some functions from the PROS 2 API are not useful or cannot be 8 | * implemented in PROS 3, but most common functions are available. 9 | * 10 | * This file should not be modified by users, since it gets replaced whenever 11 | * a kernel upgrade occurs. 12 | * 13 | * Copyright (c) 2017-2018, Purdue University ACM SIGBots. 14 | * All rights reserved. 15 | * 16 | * This Source Code Form is subject to the terms of the Mozilla Public 17 | * License, v. 2.0. If a copy of the MPL was not distributed with this 18 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 19 | */ 20 | 21 | #ifndef _PROS_API_LEGACY_H_ 22 | #define _PROS_API_LEGACY_H_ 23 | 24 | #include "api.h" 25 | 26 | #ifdef __cplusplus 27 | #define _NAMESPACE pros:: 28 | #define _CNAMESPACE pros::c:: 29 | #else 30 | #define _NAMESPACE 31 | #define _CNAMESPACE 32 | #endif 33 | 34 | /** 35 | * From adi.h 36 | */ 37 | #define analogCalibrate(port) adi_analog_calibrate(port) 38 | #define analogRead(port) adi_analog_read(port) 39 | #define analogReadCalibrated(port) adi_analog_read_calibrated(port) 40 | #define analogReadCalibratedHR(port) adi_analog_read_calibrated_HR(port) 41 | #define digitalRead(port) adi_digital_read(port) 42 | #define digitalWrite(port, value) adi_digital_write(port, value) 43 | #define pinMode(port, mode) adi_pin_mode(port, mode) 44 | #define adiMotorSet(port, speed) adi_motor_set(port, speed) 45 | #define adiMotorGet(port) adi_motor_get(port) 46 | #define adiMotorStop(port) adi_motor_stop(port) 47 | #define encoderGet(enc) adi_encoder_get(enc) 48 | #define encoderInit(portTop, portBottom, reverse) adi_encoder_init(portTop, portBottom, reverse) 49 | #define encoderShutdown(enc) adi_encoder_shutdown(enc) 50 | #define ultrasonicGet(ult) adi_ultrasonic_get(ult) 51 | #define ultrasonicInit(portEcho, portPing) adi_ultrasonic_init(portEcho, portPing) 52 | #define ultrasonicShutdown(ult) adi_ultrasonic_shutdown(ult) 53 | 54 | typedef _CNAMESPACE adi_encoder_t Encoder; 55 | typedef _CNAMESPACE adi_ultrasonic_t Ultrasonic; 56 | 57 | /** 58 | * From llemu.h 59 | */ 60 | #define lcdInit lcd_initialize 61 | #define lcdReadButtons lcd_read_buttons 62 | #define lcdClear lcd_clear 63 | #define lcdClearLine lcd_clear_line 64 | #define lcdShutdown lcd_shutdown 65 | #define lcdPrint(line, fmt, ...) lcd_print(line, fmt, __VA_ARGS__) 66 | #define lcdSetText(line, text) lcd_set_text(line, text) 67 | 68 | /** 69 | * From misc.h 70 | */ 71 | #define isEnabled() (!competition_is_disabled()) 72 | #define isAutonomous competition_is_autonomous 73 | #define isOnline competition_is_connected 74 | #define isJoystickConnected(id) controller_is_connected(id) 75 | #define joystickGetAnalog(id, channel) controller_get_analog(id, channel) 76 | 77 | /** 78 | * From rtos.h 79 | */ 80 | #define taskCreate(taskCode, stackDepth, parameters, priority) \ 81 | task_create(taskCode, parameters, priority, stackDepth, "") 82 | #define taskDelete(task) task_delete(task) 83 | #define taskDelay task_delay 84 | #define taskDelayUntil(previousWakeTime, cycleTime) task_delay_until(previousWakeTime, cycleTime) 85 | #define taskPriorityGet(task) task_get_priority(task) 86 | #define taskPrioritySet(task, newPriority) task_priority_set(task, newPriority) 87 | #define taskGetState(task) task_get_state(task) 88 | #define taskSuspend(task) task_suspend(task) 89 | #define taskResume(task) task_resume(task) 90 | #define taskGetCount task_get_count 91 | #define mutexCreate mutex_create 92 | #define mutexTake(mutex, blockTime) mutex_take(mutex, blockTime) 93 | #define mutexGive(mutex) mutex_give(mutex) 94 | 95 | typedef _NAMESPACE task_t TaskHandle; 96 | typedef _NAMESPACE mutex_t Mutex; 97 | 98 | /** 99 | * From motors.h 100 | */ 101 | #define motorSet(port, speed) motor_move(port, speed) 102 | #define motorGet(port) motor_get_voltage(port) 103 | #define motorStop(port) motor_move(port, 0) 104 | 105 | #undef _NAMESPACE 106 | #undef _CNAMESPACE 107 | 108 | #endif // _PROS_API_LEGACY_H_ 109 | -------------------------------------------------------------------------------- /include/display/lv_objx/lv_cont.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_cont.h 3 | * 4 | */ 5 | 6 | #ifndef LV_CONT_H 7 | #define LV_CONT_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "display/lv_conf.h" 17 | #if USE_LV_CONT != 0 18 | 19 | #include "display/lv_core/lv_obj.h" 20 | 21 | /********************* 22 | * DEFINES 23 | *********************/ 24 | 25 | /********************** 26 | * TYPEDEFS 27 | **********************/ 28 | 29 | /*Layout options*/ 30 | typedef enum { 31 | LV_LAYOUT_OFF = 0, 32 | LV_LAYOUT_CENTER, 33 | LV_LAYOUT_COL_L, /*Column left align*/ 34 | LV_LAYOUT_COL_M, /*Column middle align*/ 35 | LV_LAYOUT_COL_R, /*Column right align*/ 36 | LV_LAYOUT_ROW_T, /*Row top align*/ 37 | LV_LAYOUT_ROW_M, /*Row middle align*/ 38 | LV_LAYOUT_ROW_B, /*Row bottom align*/ 39 | LV_LAYOUT_PRETTY, /*Put as many object as possible in row and begin a new 40 | row*/ 41 | LV_LAYOUT_GRID, /*Align same-sized object into a grid*/ 42 | } lv_layout_t; 43 | 44 | typedef struct { 45 | /*Inherited from 'base_obj' so no inherited ext. */ /*Ext. of ancestor*/ 46 | /*New data for this type */ 47 | uint8_t layout : 4; /*A layout from 'lv_cont_layout_t' enum*/ 48 | uint8_t hor_fit : 1; /*1: Enable horizontal fit to involve all children*/ 49 | uint8_t ver_fit : 1; /*1: Enable horizontal fir to involve all children*/ 50 | } lv_cont_ext_t; 51 | 52 | /********************** 53 | * GLOBAL PROTOTYPES 54 | **********************/ 55 | 56 | /** 57 | * Create a container objects 58 | * @param par pointer to an object, it will be the parent of the new container 59 | * @param copy pointer to a container object, if not NULL then the new object 60 | * will be copied from it 61 | * @return pointer to the created container 62 | */ 63 | lv_obj_t *lv_cont_create(lv_obj_t *par, lv_obj_t *copy); 64 | 65 | /*===================== 66 | * Setter functions 67 | *====================*/ 68 | 69 | /** 70 | * Set a layout on a container 71 | * @param cont pointer to a container object 72 | * @param layout a layout from 'lv_cont_layout_t' 73 | */ 74 | void lv_cont_set_layout(lv_obj_t *cont, lv_layout_t layout); 75 | 76 | /** 77 | * Enable the horizontal or vertical fit. 78 | * The container size will be set to involve the children horizontally or 79 | * vertically. 80 | * @param cont pointer to a container object 81 | * @param hor_en true: enable the horizontal fit 82 | * @param ver_en true: enable the vertical fit 83 | */ 84 | void lv_cont_set_fit(lv_obj_t *cont, bool hor_en, bool ver_en); 85 | 86 | /** 87 | * Set the style of a container 88 | * @param cont pointer to a container object 89 | * @param style pointer to the new style 90 | */ 91 | static inline void lv_cont_set_style(lv_obj_t *cont, lv_style_t *style) { 92 | lv_obj_set_style(cont, style); 93 | } 94 | 95 | /*===================== 96 | * Getter functions 97 | *====================*/ 98 | 99 | /** 100 | * Get the layout of a container 101 | * @param cont pointer to container object 102 | * @return the layout from 'lv_cont_layout_t' 103 | */ 104 | lv_layout_t lv_cont_get_layout(lv_obj_t *cont); 105 | 106 | /** 107 | * Get horizontal fit enable attribute of a container 108 | * @param cont pointer to a container object 109 | * @return true: horizontal fit is enabled; false: disabled 110 | */ 111 | bool lv_cont_get_hor_fit(lv_obj_t *cont); 112 | 113 | /** 114 | * Get vertical fit enable attribute of a container 115 | * @param cont pointer to a container object 116 | * @return true: vertical fit is enabled; false: disabled 117 | */ 118 | bool lv_cont_get_ver_fit(lv_obj_t *cont); 119 | 120 | /** 121 | * Get the style of a container 122 | * @param cont pointer to a container object 123 | * @return pointer to the container's style 124 | */ 125 | static inline lv_style_t *lv_cont_get_style(lv_obj_t *cont) { 126 | return lv_obj_get_style(cont); 127 | } 128 | 129 | /********************** 130 | * MACROS 131 | **********************/ 132 | 133 | #endif /*USE_LV_CONT*/ 134 | 135 | #ifdef __cplusplus 136 | } /* extern "C" */ 137 | #endif 138 | 139 | #endif /*LV_CONT_H*/ 140 | -------------------------------------------------------------------------------- /include/display/lv_objx/lv_lmeter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_lmeter.h 3 | * 4 | */ 5 | 6 | #ifndef LV_LMETER_H 7 | #define LV_LMETER_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "display/lv_conf.h" 17 | #if USE_LV_LMETER != 0 18 | 19 | #include "display/lv_core/lv_obj.h" 20 | 21 | /********************* 22 | * DEFINES 23 | *********************/ 24 | 25 | /********************** 26 | * TYPEDEFS 27 | **********************/ 28 | /*Data of line meter*/ 29 | typedef struct { 30 | /*No inherited ext.*/ /*Ext. of ancestor*/ 31 | /*New data for this type */ 32 | uint16_t scale_angle; /*Angle of the scale in deg. (0..360)*/ 33 | uint8_t line_cnt; /*Count of lines */ 34 | int16_t cur_value; 35 | int16_t min_value; 36 | int16_t max_value; 37 | } lv_lmeter_ext_t; 38 | 39 | /********************** 40 | * GLOBAL PROTOTYPES 41 | **********************/ 42 | 43 | /** 44 | * Create a line meter objects 45 | * @param par pointer to an object, it will be the parent of the new line meter 46 | * @param copy pointer to a line meter object, if not NULL then the new object 47 | * will be copied from it 48 | * @return pointer to the created line meter 49 | */ 50 | lv_obj_t *lv_lmeter_create(lv_obj_t *par, lv_obj_t *copy); 51 | 52 | /*===================== 53 | * Setter functions 54 | *====================*/ 55 | 56 | /** 57 | * Set a new value on the line meter 58 | * @param lmeter pointer to a line meter object 59 | * @param value new value 60 | */ 61 | void lv_lmeter_set_value(lv_obj_t *lmeter, int16_t value); 62 | 63 | /** 64 | * Set minimum and the maximum values of a line meter 65 | * @param lmeter pointer to he line meter object 66 | * @param min minimum value 67 | * @param max maximum value 68 | */ 69 | void lv_lmeter_set_range(lv_obj_t *lmeter, int16_t min, int16_t max); 70 | 71 | /** 72 | * Set the scale settings of a line meter 73 | * @param lmeter pointer to a line meter object 74 | * @param angle angle of the scale (0..360) 75 | * @param line_cnt number of lines 76 | */ 77 | void lv_lmeter_set_scale(lv_obj_t *lmeter, uint16_t angle, uint8_t line_cnt); 78 | 79 | /** 80 | * Set the styles of a line meter 81 | * @param lmeter pointer to a line meter object 82 | * @param bg set the style of the line meter 83 | * */ 84 | static inline void lv_lmeter_set_style(lv_obj_t *lmeter, lv_style_t *bg) { 85 | lv_obj_set_style(lmeter, bg); 86 | } 87 | 88 | /*===================== 89 | * Getter functions 90 | *====================*/ 91 | 92 | /** 93 | * Get the value of a line meter 94 | * @param lmeter pointer to a line meter object 95 | * @return the value of the line meter 96 | */ 97 | int16_t lv_lmeter_get_value(lv_obj_t *lmeter); 98 | 99 | /** 100 | * Get the minimum value of a line meter 101 | * @param lmeter pointer to a line meter object 102 | * @return the minimum value of the line meter 103 | */ 104 | int16_t lv_lmeter_get_min_value(lv_obj_t *lmeter); 105 | 106 | /** 107 | * Get the maximum value of a line meter 108 | * @param lmeter pointer to a line meter object 109 | * @return the maximum value of the line meter 110 | */ 111 | int16_t lv_lmeter_get_max_value(lv_obj_t *lmeter); 112 | 113 | /** 114 | * Get the scale number of a line meter 115 | * @param lmeter pointer to a line meter object 116 | * @return number of the scale units 117 | */ 118 | uint8_t lv_lmeter_get_line_count(lv_obj_t *lmeter); 119 | 120 | /** 121 | * Get the scale angle of a line meter 122 | * @param lmeter pointer to a line meter object 123 | * @return angle of the scale 124 | */ 125 | uint16_t lv_lmeter_get_scale_angle(lv_obj_t *lmeter); 126 | 127 | /** 128 | * Get the style of a line meter 129 | * @param lmeter pointer to a line meter object 130 | * @return pointer to the line meter's style 131 | */ 132 | static inline lv_style_t *lv_lmeter_get_style_bg(lv_obj_t *lmeter) { 133 | return lv_obj_get_style(lmeter); 134 | } 135 | 136 | /********************** 137 | * MACROS 138 | **********************/ 139 | 140 | #endif /*USE_LV_LMETER*/ 141 | 142 | #ifdef __cplusplus 143 | } /* extern "C" */ 144 | #endif 145 | 146 | #endif /*LV_LMETER_H*/ 147 | -------------------------------------------------------------------------------- /include/display/lv_objx/lv_line.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_line.h 3 | * 4 | */ 5 | 6 | #ifndef LV_LINE_H 7 | #define LV_LINE_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "display/lv_conf.h" 17 | #if USE_LV_LINE != 0 18 | 19 | #include "display/lv_core/lv_obj.h" 20 | 21 | /********************* 22 | * DEFINES 23 | *********************/ 24 | 25 | /********************** 26 | * TYPEDEFS 27 | **********************/ 28 | 29 | /*Data of line*/ 30 | typedef struct { 31 | /*Inherited from 'base_obj' so no inherited ext.*/ /*Ext. of ancestor*/ 32 | const lv_point_t 33 | *point_array; /*Pointer to an array with the points of the line*/ 34 | uint16_t point_num; /*Number of points in 'point_array' */ 35 | uint8_t 36 | auto_size : 1; /*1: set obj. width to x max and obj. height to y max */ 37 | uint8_t y_inv : 1; /*1: y == 0 will be on the bottom*/ 38 | } lv_line_ext_t; 39 | 40 | /********************** 41 | * GLOBAL PROTOTYPES 42 | **********************/ 43 | 44 | /** 45 | * Create a line objects 46 | * @param par pointer to an object, it will be the parent of the new line 47 | * @return pointer to the created line 48 | */ 49 | lv_obj_t *lv_line_create(lv_obj_t *par, lv_obj_t *copy); 50 | 51 | /*===================== 52 | * Setter functions 53 | *====================*/ 54 | 55 | /** 56 | * Set an array of points. The line object will connect these points. 57 | * @param line pointer to a line object 58 | * @param point_a an array of points. Only the address is saved, 59 | * so the array can NOT be a local variable which will be destroyed 60 | * @param point_num number of points in 'point_a' 61 | */ 62 | void lv_line_set_points(lv_obj_t *line, const lv_point_t *point_a, 63 | uint16_t point_num); 64 | 65 | /** 66 | * Enable (or disable) the auto-size option. The size of the object will fit to 67 | * its points. 68 | * (set width to x max and height to y max) 69 | * @param line pointer to a line object 70 | * @param autosize_en true: auto size is enabled, false: auto size is disabled 71 | */ 72 | void lv_line_set_auto_size(lv_obj_t *line, bool autosize_en); 73 | 74 | /** 75 | * Enable (or disable) the y coordinate inversion. 76 | * If enabled then y will be subtracted from the height of the object, 77 | * therefore the y=0 coordinate will be on the bottom. 78 | * @param line pointer to a line object 79 | * @param yinv_en true: enable the y inversion, false:disable the y inversion 80 | */ 81 | void lv_line_set_y_invert(lv_obj_t *line, bool yinv_en); 82 | 83 | /** 84 | * Set the style of a line 85 | * @param line pointer to a line object 86 | * @param style pointer to a style 87 | */ 88 | static inline void lv_line_set_style(lv_obj_t *line, lv_style_t *style) { 89 | lv_obj_set_style(line, style); 90 | } 91 | 92 | /** 93 | * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in 94 | * v6.0 95 | * @param line 96 | * @param upscale 97 | */ 98 | static inline void lv_line_set_upscale(lv_obj_t *line, bool upcale) {} 99 | /*===================== 100 | * Getter functions 101 | *====================*/ 102 | 103 | /** 104 | * Get the auto size attribute 105 | * @param line pointer to a line object 106 | * @return true: auto size is enabled, false: disabled 107 | */ 108 | bool lv_line_get_auto_size(lv_obj_t *line); 109 | 110 | /** 111 | * Get the y inversion attribute 112 | * @param line pointer to a line object 113 | * @return true: y inversion is enabled, false: disabled 114 | */ 115 | bool lv_line_get_y_inv(lv_obj_t *line); 116 | 117 | /** 118 | * Get the style of an line object 119 | * @param line pointer to an line object 120 | * @return pointer to the line's style 121 | */ 122 | static inline lv_style_t *lv_line_get_style(lv_obj_t *line) { 123 | return lv_obj_get_style(line); 124 | } 125 | 126 | /** 127 | * Obsolete since v5.1. Just for compatibility with v5.0. Will be removed in 128 | * v6.0 129 | * @param line 130 | * @return false 131 | */ 132 | static inline bool lv_line_get_upscale(lv_obj_t *line) { return false; } 133 | 134 | /********************** 135 | * MACROS 136 | **********************/ 137 | 138 | #endif /*USE_LV_LINE*/ 139 | 140 | #ifdef __cplusplus 141 | } /* extern "C" */ 142 | #endif 143 | 144 | #endif /*LV_LINE_H*/ 145 | -------------------------------------------------------------------------------- /include/okapi/api/control/iterative/iterativeMotorVelocityController.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Ryan Benasutti, WPI 3 | * 4 | * This Source Code Form is subject to the terms of the Mozilla Public 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | */ 8 | #pragma once 9 | 10 | #include "okapi/api/control/iterative/iterativeVelocityController.hpp" 11 | #include "okapi/api/device/motor/abstractMotor.hpp" 12 | #include 13 | #include 14 | 15 | namespace okapi { 16 | class IterativeMotorVelocityController : public IterativeVelocityController { 17 | public: 18 | /** 19 | * Velocity controller that automatically writes to the motor. 20 | */ 21 | IterativeMotorVelocityController( 22 | const std::shared_ptr &imotor, 23 | const std::shared_ptr> &icontroller); 24 | 25 | /** 26 | * Do one iteration of the controller. 27 | * 28 | * @param inewReading new measurement 29 | * @return controller output 30 | */ 31 | double step(double ireading) override; 32 | 33 | /** 34 | * Sets the target for the controller. 35 | */ 36 | void setTarget(double itarget) override; 37 | 38 | /** 39 | * Writes the value of the controller output. This method might be automatically called in another 40 | * thread by the controller. The range of input values is expected to be [-1, 1]. 41 | * 42 | * @param ivalue the controller's output in the range [-1, 1] 43 | */ 44 | void controllerSet(double ivalue) override; 45 | 46 | /** 47 | * Gets the last set target, or the default target if none was set. 48 | * 49 | * @return the last target 50 | */ 51 | double getTarget() override; 52 | 53 | /** 54 | * Returns the last calculated output of the controller. 55 | */ 56 | double getOutput() const override; 57 | 58 | /** 59 | * Get the upper output bound. 60 | * 61 | * @return the upper output bound 62 | */ 63 | double getMaxOutput() override; 64 | 65 | /** 66 | * Get the lower output bound. 67 | * 68 | * @return the lower output bound 69 | */ 70 | double getMinOutput() override; 71 | 72 | /** 73 | * Returns the last error of the controller. Does not update when disabled. 74 | */ 75 | double getError() const override; 76 | 77 | /** 78 | * Returns whether the controller has settled at the target. Determining what settling means is 79 | * implementation-dependent. 80 | * 81 | * @return whether the controller is settled 82 | */ 83 | bool isSettled() override; 84 | 85 | /** 86 | * Set time between loops in ms. 87 | * 88 | * @param isampleTime time between loops in ms 89 | */ 90 | void setSampleTime(QTime isampleTime) override; 91 | 92 | /** 93 | * Set controller output bounds. 94 | * 95 | * @param imax max output 96 | * @param imin min output 97 | */ 98 | void setOutputLimits(double imax, double imin) override; 99 | 100 | /** 101 | * Resets the controller's internal state so it is similar to when it was first initialized, while 102 | * keeping any user-configured information. 103 | */ 104 | void reset() override; 105 | 106 | /** 107 | * Changes whether the controller is off or on. Turning the controller on after it was off will 108 | * cause the controller to move to its last set target, unless it was reset in that time. 109 | */ 110 | void flipDisable() override; 111 | 112 | /** 113 | * Sets whether the controller is off or on. Turning the controller on after it was off will 114 | * cause the controller to move to its last set target, unless it was reset in that time. 115 | * 116 | * @param iisDisabled whether the controller is disabled 117 | */ 118 | void flipDisable(bool iisDisabled) override; 119 | 120 | /** 121 | * Returns whether the controller is currently disabled. 122 | * 123 | * @return whether the controller is currently disabled 124 | */ 125 | bool isDisabled() const override; 126 | 127 | /** 128 | * Get the last set sample time. 129 | * 130 | * @return sample time 131 | */ 132 | QTime getSampleTime() const override; 133 | 134 | protected: 135 | std::shared_ptr motor; 136 | std::shared_ptr> controller; 137 | }; 138 | } // namespace okapi 139 | --------------------------------------------------------------------------------