├── .gitignore ├── Makefile ├── README.md ├── common.mk ├── firmware ├── libc.a ├── libm.a ├── libpros.a ├── okapilib.a ├── v5-common.ld ├── v5-hot.ld └── v5.ld ├── include ├── api.h ├── display │ ├── README.md │ ├── licence.txt │ ├── lv_conf.h │ ├── lv_conf_checker.h │ ├── lv_core │ │ ├── lv_core.mk │ │ ├── lv_group.h │ │ ├── lv_indev.h │ │ ├── lv_lang.h │ │ ├── lv_obj.h │ │ ├── lv_refr.h │ │ ├── lv_style.h │ │ └── lv_vdb.h │ ├── lv_draw │ │ ├── lv_draw.h │ │ ├── lv_draw.mk │ │ ├── lv_draw_arc.h │ │ ├── lv_draw_img.h │ │ ├── lv_draw_label.h │ │ ├── lv_draw_line.h │ │ ├── lv_draw_rbasic.h │ │ ├── lv_draw_rect.h │ │ ├── lv_draw_triangle.h │ │ └── lv_draw_vbasic.h │ ├── lv_fonts │ │ ├── lv_font_builtin.h │ │ └── lv_fonts.mk │ ├── lv_hal │ │ ├── lv_hal.h │ │ ├── lv_hal.mk │ │ ├── lv_hal_disp.h │ │ ├── lv_hal_indev.h │ │ └── lv_hal_tick.h │ ├── lv_misc │ │ ├── lv_anim.h │ │ ├── lv_area.h │ │ ├── lv_circ.h │ │ ├── lv_color.h │ │ ├── lv_font.h │ │ ├── lv_fs.h │ │ ├── lv_gc.h │ │ ├── lv_ll.h │ │ ├── lv_log.h │ │ ├── lv_math.h │ │ ├── lv_mem.h │ │ ├── lv_misc.mk │ │ ├── lv_symbol_def.h │ │ ├── lv_task.h │ │ ├── lv_templ.h │ │ ├── lv_txt.h │ │ └── lv_ufs.h │ ├── lv_objx │ │ ├── lv_arc.h │ │ ├── lv_bar.h │ │ ├── lv_btn.h │ │ ├── lv_btnm.h │ │ ├── lv_calendar.h │ │ ├── lv_canvas.h │ │ ├── lv_cb.h │ │ ├── lv_chart.h │ │ ├── lv_cont.h │ │ ├── lv_ddlist.h │ │ ├── lv_gauge.h │ │ ├── lv_img.h │ │ ├── lv_imgbtn.h │ │ ├── lv_kb.h │ │ ├── lv_label.h │ │ ├── lv_led.h │ │ ├── lv_line.h │ │ ├── lv_list.h │ │ ├── lv_lmeter.h │ │ ├── lv_mbox.h │ │ ├── lv_objx.mk │ │ ├── lv_objx_templ.h │ │ ├── lv_page.h │ │ ├── lv_preload.h │ │ ├── lv_roller.h │ │ ├── lv_slider.h │ │ ├── lv_spinbox.h │ │ ├── lv_sw.h │ │ ├── lv_ta.h │ │ ├── lv_table.h │ │ ├── lv_tabview.h │ │ ├── lv_tileview.h │ │ └── lv_win.h │ ├── lv_themes │ │ ├── lv_theme.h │ │ ├── lv_theme_alien.h │ │ ├── lv_theme_default.h │ │ ├── lv_theme_material.h │ │ ├── lv_theme_mono.h │ │ ├── lv_theme_nemo.h │ │ ├── lv_theme_night.h │ │ ├── lv_theme_templ.h │ │ ├── lv_theme_zen.h │ │ └── lv_themes.mk │ ├── lv_version.h │ └── lvgl.h ├── gui.h ├── main.h ├── okapi │ ├── api.hpp │ ├── api │ │ ├── chassis │ │ │ ├── controller │ │ │ │ ├── chassisController.hpp │ │ │ │ ├── chassisControllerIntegrated.hpp │ │ │ │ ├── chassisControllerPid.hpp │ │ │ │ └── chassisScales.hpp │ │ │ └── model │ │ │ │ ├── chassisModel.hpp │ │ │ │ ├── readOnlyChassisModel.hpp │ │ │ │ ├── skidSteerModel.hpp │ │ │ │ ├── threeEncoderSkidSteerModel.hpp │ │ │ │ └── xDriveModel.hpp │ │ ├── control │ │ │ ├── async │ │ │ │ ├── asyncController.hpp │ │ │ │ ├── asyncLinearMotionProfileController.hpp │ │ │ │ ├── asyncMotionProfileController.hpp │ │ │ │ ├── asyncPosIntegratedController.hpp │ │ │ │ ├── asyncPosPidController.hpp │ │ │ │ ├── asyncPositionController.hpp │ │ │ │ ├── asyncVelIntegratedController.hpp │ │ │ │ ├── asyncVelPidController.hpp │ │ │ │ ├── asyncVelocityController.hpp │ │ │ │ └── asyncWrapper.hpp │ │ │ ├── closedLoopController.hpp │ │ │ ├── controllerInput.hpp │ │ │ ├── controllerOutput.hpp │ │ │ ├── iterative │ │ │ │ ├── iterativeController.hpp │ │ │ │ ├── iterativeMotorVelocityController.hpp │ │ │ │ ├── iterativePosPidController.hpp │ │ │ │ ├── iterativePositionController.hpp │ │ │ │ ├── iterativeVelPidController.hpp │ │ │ │ └── iterativeVelocityController.hpp │ │ │ └── util │ │ │ │ ├── controllerRunner.hpp │ │ │ │ ├── flywheelSimulator.hpp │ │ │ │ ├── pidTuner.hpp │ │ │ │ └── settledUtil.hpp │ │ ├── coreProsAPI.hpp │ │ ├── device │ │ │ ├── button │ │ │ │ ├── abstractButton.hpp │ │ │ │ └── buttonBase.hpp │ │ │ ├── motor │ │ │ │ └── abstractMotor.hpp │ │ │ └── rotarysensor │ │ │ │ ├── continuousRotarySensor.hpp │ │ │ │ └── rotarySensor.hpp │ │ ├── filter │ │ │ ├── averageFilter.hpp │ │ │ ├── composableFilter.hpp │ │ │ ├── demaFilter.hpp │ │ │ ├── ekfFilter.hpp │ │ │ ├── emaFilter.hpp │ │ │ ├── filter.hpp │ │ │ ├── filteredControllerInput.hpp │ │ │ ├── medianFilter.hpp │ │ │ ├── passthroughFilter.hpp │ │ │ └── velMath.hpp │ │ ├── units │ │ │ ├── QAcceleration.hpp │ │ │ ├── QAngle.hpp │ │ │ ├── QAngularAcceleration.hpp │ │ │ ├── QAngularJerk.hpp │ │ │ ├── QAngularSpeed.hpp │ │ │ ├── QArea.hpp │ │ │ ├── QForce.hpp │ │ │ ├── QFrequency.hpp │ │ │ ├── QJerk.hpp │ │ │ ├── QLength.hpp │ │ │ ├── QMass.hpp │ │ │ ├── QPressure.hpp │ │ │ ├── QSpeed.hpp │ │ │ ├── QTime.hpp │ │ │ ├── QTorque.hpp │ │ │ ├── QVolume.hpp │ │ │ └── RQuantity.hpp │ │ └── util │ │ │ ├── abstractRate.hpp │ │ │ ├── abstractTimer.hpp │ │ │ ├── logging.hpp │ │ │ ├── mathUtil.hpp │ │ │ ├── supplier.hpp │ │ │ └── timeUtil.hpp │ ├── impl │ │ ├── chassis │ │ │ ├── controller │ │ │ │ └── chassisControllerFactory.hpp │ │ │ └── model │ │ │ │ └── chassisModelFactory.hpp │ │ ├── control │ │ │ ├── async │ │ │ │ └── asyncControllerFactory.hpp │ │ │ ├── iterative │ │ │ │ └── iterativeControllerFactory.hpp │ │ │ └── util │ │ │ │ ├── controllerRunnerFactory.hpp │ │ │ │ ├── pidTunerFactory.hpp │ │ │ │ └── settledUtilFactory.hpp │ │ ├── device │ │ │ ├── adiUltrasonic.hpp │ │ │ ├── button │ │ │ │ ├── adiButton.hpp │ │ │ │ └── controllerButton.hpp │ │ │ ├── controller.hpp │ │ │ ├── controllerUtil.hpp │ │ │ ├── motor │ │ │ │ ├── adiMotor.hpp │ │ │ │ ├── motor.hpp │ │ │ │ └── motorGroup.hpp │ │ │ ├── rotarysensor │ │ │ │ ├── adiEncoder.hpp │ │ │ │ ├── adiGyro.hpp │ │ │ │ ├── integratedEncoder.hpp │ │ │ │ └── potentiometer.hpp │ │ │ └── vision.hpp │ │ ├── filter │ │ │ └── velMathFactory.hpp │ │ └── util │ │ │ ├── rate.hpp │ │ │ ├── timeUtilFactory.hpp │ │ │ └── timer.hpp │ └── pathfinder │ │ └── include │ │ ├── pathfinder.h │ │ └── pathfinder │ │ ├── fit.h │ │ ├── followers │ │ ├── distance.h │ │ └── encoder.h │ │ ├── io.h │ │ ├── lib.h │ │ ├── mathutil.h │ │ ├── modifiers │ │ ├── swerve.h │ │ └── tank.h │ │ ├── spline.h │ │ ├── structs.h │ │ └── trajectory.h └── pros │ ├── adi.h │ ├── adi.hpp │ ├── api_legacy.h │ ├── apix.h │ ├── colors.h │ ├── llemu.h │ ├── llemu.hpp │ ├── misc.h │ ├── misc.hpp │ ├── motors.h │ ├── motors.hpp │ ├── rtos.h │ ├── rtos.hpp │ ├── serial.h │ ├── serial.hpp │ ├── vision.h │ └── vision.hpp ├── project.pros └── src ├── autonomous.cpp ├── gui.cpp ├── initialize.cpp └── opcontrol.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.o 3 | *.obj 4 | 5 | # Executables 6 | *.bin 7 | *.elf 8 | 9 | # PROS 10 | bin/ 11 | .vscode/ 12 | compile_commands.json 13 | temp.log 14 | temp.errors 15 | *.ini 16 | .d/ -------------------------------------------------------------------------------- /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:=0 24 | # TODO: CHANGE THIS! 25 | LIBNAME:=libbest 26 | VERSION:=1.0.0 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)/**/*.h $(INCDIR)/**/*.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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # v5gui 2 | Example LVGL GUI code for Vex V5 Brain 3 | 4 | There are two examples included. The first uses individual buttons that can be placed anywhere on the screen. The second uses a button matrix. 5 | 6 | The GUI consists of two regions: the Button Region and the Status Region. Inside the Status region is a Label object. This split is done to make sure the status information can be display if the buttons exceed the size of the button region. Which is good when debugging placment issues. 7 | 8 | In the first example, individual buttons are placed on the screen using using lv_obj_align. All buttons use one callback function defined by lv_btn_set_action. The lv_obj_set_free_num assigns a numeric value to the button pressed for the callback function to use. 9 | 10 | The Buttons look like this when run in the LVGL PC Simulator. 11 | ![](https://raw.githubusercontent.com/timeconfusing/Images/master/LVGL-buttons.PNG) 12 | 13 | In the second example, 14 | 15 | The button matrix allow for fast definition of multiple rows and columns of buttons. The defintion of the matrix is as follows: 16 | 17 | ```// Create a button descriptor string array w/ no repeat "\224" 18 | static const char * btnm_map[] = { "\2241", "\2242", "\2243", "\n", 19 | "\2244", "\2245", "\2246", "" }; 20 | ``` 21 | 22 | The escape section prevents a press of the button being interpreted as a multipress of the button. The matrix is created by lv_btnm_set_map. The last character in the string for the button_map is what the callback function receives when pressed. The callback function is defined by lv_btnm_set_action. 23 | 24 | The Button Matrix looks like this when run in the LVGL PC Simulator. 25 | ![](https://raw.githubusercontent.com/timeconfusing/Images/master/LVGL-btnm.PNG) 26 | -------------------------------------------------------------------------------- /firmware/libc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timeconfusing/v5gui/4803dc33a7b75b513f3e4fdc630f247a7cf4e09b/firmware/libc.a -------------------------------------------------------------------------------- /firmware/libm.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timeconfusing/v5gui/4803dc33a7b75b513f3e4fdc630f247a7cf4e09b/firmware/libm.a -------------------------------------------------------------------------------- /firmware/libpros.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timeconfusing/v5gui/4803dc33a7b75b513f3e4fdc630f247a7cf4e09b/firmware/libpros.a -------------------------------------------------------------------------------- /firmware/okapilib.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/timeconfusing/v5gui/4803dc33a7b75b513f3e4fdc630f247a7cf4e09b/firmware/okapilib.a -------------------------------------------------------------------------------- /firmware/v5-common.ld: -------------------------------------------------------------------------------- 1 | _HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x02E00000; /* ~48 MB */ 2 | 3 | start_of_cold_mem = 0x03800000; 4 | _COLD_MEM_SIZE = 0x04800000; 5 | end_of_cold_mem = start_of_cold_mem + _COLD_MEM_SIZE; 6 | 7 | start_of_hot_mem = 0x07800000; 8 | _HOT_MEM_SIZE = 0x00800000; 9 | end_of_hot_mem = start_of_hot_mem + _HOT_MEM_SIZE; 10 | 11 | MEMORY 12 | { 13 | /* user code 72M */ 14 | COLD_MEMORY : ORIGIN = start_of_cold_mem, LENGTH = _COLD_MEM_SIZE /* Just under 19 MB */ 15 | HEAP : ORIGIN = 0x04A00000, LENGTH = _HEAP_SIZE 16 | HOT_MEMORY : ORIGIN = start_of_hot_mem, LENGTH = _HOT_MEM_SIZE /* Just over 8 MB */ 17 | } 18 | -------------------------------------------------------------------------------- /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-2019, 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 2 44 | #define PROS_VERSION_PATCH 0 45 | #define PROS_VERSION_STRING "3.2.0" 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/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/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/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 | CSRCS += lv_lang.c 8 | 9 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_core 10 | VPATH += :$(LVGL_DIR)/lvgl/lv_core 11 | 12 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_core" 13 | -------------------------------------------------------------------------------- /include/display/lv_core/lv_lang.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_lang.h 3 | * 4 | */ 5 | 6 | #ifndef LV_LANG_H 7 | #define LV_LANG_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_MULTI_LANG 23 | 24 | #include 25 | 26 | /********************* 27 | * DEFINES 28 | *********************/ 29 | #define LV_LANG_TXT_ID_NONE 0xFFFF /*Used to not assign any text IDs for a multi-language object.*/ 30 | 31 | /********************** 32 | * TYPEDEFS 33 | **********************/ 34 | 35 | /********************** 36 | * GLOBAL PROTOTYPES 37 | **********************/ 38 | 39 | /** 40 | * Change the language 41 | * @param lang_id the id of the 42 | */ 43 | void lv_lang_set(uint8_t lang_id); 44 | 45 | /** 46 | * Set a function to get the texts of the set languages from a `txt_id` 47 | * @param fp a function pointer to get the texts 48 | */ 49 | void lv_lang_set_text_func(const void * (*fp)(uint16_t)); 50 | 51 | /** 52 | * Use the function set by `lv_lang_set_text_func` to get the `txt_id` text in the set language 53 | * @param txt_id an ID of the text to get 54 | * @return the `txt_id` txt on the set language 55 | */ 56 | const void * lv_lang_get_text(uint16_t txt_id); 57 | 58 | /** 59 | * Return with ID of the currently selected language 60 | * @return pointer to the active screen object (loaded by 'lv_scr_load()') 61 | */ 62 | uint8_t lv_lang_act(void); 63 | 64 | /********************** 65 | * MACROS 66 | **********************/ 67 | 68 | #endif /*USE_LV_MULTI_LANG*/ 69 | 70 | #ifdef __cplusplus 71 | } /* extern "C" */ 72 | #endif 73 | 74 | #endif /*LV_LANG_H*/ 75 | -------------------------------------------------------------------------------- /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 | * Redraw the invalidated areas now. 50 | * Normally the redrawing is periodically executed in `lv_task_handler` but a long blocking process can 51 | * prevent the call of `lv_task_handler`. In this case if the the GUI is updated in the process (e.g. progress bar) 52 | * this function can be called when the screen should be updated. 53 | */ 54 | void lv_refr_now(void); 55 | 56 | /** 57 | * Invalidate an area 58 | * @param area_p pointer to area which should be invalidated 59 | */ 60 | void lv_inv_area(const lv_area_t * area_p); 61 | 62 | /** 63 | * Set a function to call after every refresh to announce the refresh time and the number of refreshed pixels 64 | * @param cb pointer to a callback function (void my_refr_cb(uint32_t time_ms, uint32_t px_num)) 65 | */ 66 | void lv_refr_set_monitor_cb(void (*cb)(uint32_t, uint32_t)); 67 | 68 | /** 69 | * Called when an area is invalidated to modify the coordinates of the area. 70 | * Special display controllers may require special coordinate rounding 71 | * @param cb pointer to the a function which will modify the area 72 | */ 73 | void lv_refr_set_round_cb(void(*cb)(lv_area_t*)); 74 | 75 | /** 76 | * Get the number of areas in the buffer 77 | * @return number of invalid areas 78 | */ 79 | uint16_t lv_refr_get_buf_size(void); 80 | 81 | /** 82 | * Pop (delete) the last 'num' invalidated areas from the buffer 83 | * @param num number of areas to delete 84 | */ 85 | void lv_refr_pop_from_buf(uint16_t num); 86 | /********************** 87 | * STATIC FUNCTIONS 88 | **********************/ 89 | 90 | 91 | #ifdef __cplusplus 92 | } /* extern "C" */ 93 | #endif 94 | 95 | #endif /*LV_REFR_H*/ 96 | -------------------------------------------------------------------------------- /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 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 22 | #if LV_VDB_SIZE != 0 23 | 24 | #include "display/lv_misc/lv_color.h" 25 | #include "display/lv_misc/lv_area.h" 26 | 27 | /********************* 28 | * DEFINES 29 | *********************/ 30 | /*Can be used in `lv_conf.h` the set an invalid address for the VDB. It should be replaced later by a valid address using `lv_vdb_set_adr()`*/ 31 | #define LV_VDB_ADR_INV 8 /*8 is still too small to be valid but it's aligned on 64 bit machines as well*/ 32 | 33 | #ifndef LV_VDB_PX_BPP 34 | #define LV_VDB_PX_BPP LV_COLOR_SIZE /* Default is LV_COLOR_SIZE */ 35 | #endif 36 | 37 | 38 | #if LV_VDB_TRUE_DOUBLE_BUFFERED && (LV_VDB_SIZE != LV_HOR_RES * LV_VER_RES || LV_VDB_DOUBLE == 0) 39 | #error "With LV_VDB_TRUE_DOUBLE_BUFFERED: (LV_VDB_SIZE = LV_HOR_RES * LV_VER_RES and LV_VDB_DOUBLE = 1 is required" 40 | #endif 41 | 42 | 43 | /* The size of VDB in bytes. 44 | * (LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3): just divide by 8 to convert bits to bytes 45 | * (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0): add an extra byte to round up. 46 | * E.g. if LV_VDB_SIZE = 10 and LV_VDB_PX_BPP = 1 -> 10 bits -> 2 bytes*/ 47 | #define LV_VDB_SIZE_IN_BYTES ((LV_VDB_SIZE * LV_VDB_PX_BPP) >> 3) + (((LV_VDB_SIZE * LV_VDB_PX_BPP) & 0x7) ? 1 : 0) 48 | 49 | /********************** 50 | * TYPEDEFS 51 | **********************/ 52 | 53 | typedef struct 54 | { 55 | lv_area_t area; 56 | lv_color_t *buf; 57 | } lv_vdb_t; 58 | 59 | /********************** 60 | * GLOBAL PROTOTYPES 61 | **********************/ 62 | 63 | /** 64 | * Get the 'vdb' variable or allocate one in LV_VDB_DOUBLE mode 65 | * @return pointer to a 'vdb' variable 66 | */ 67 | lv_vdb_t * lv_vdb_get(void); 68 | 69 | /** 70 | * Flush the content of the vdb 71 | */ 72 | void lv_vdb_flush(void); 73 | 74 | /** 75 | * Set the address of VDB buffer(s) manually. To use this set `LV_VDB_ADR` (and `LV_VDB2_ADR`) to `LV_VDB_ADR_INV` in `lv_conf.h`. 76 | * It should be called before `lv_init()`. The size of the buffer should be: `LV_VDB_SIZE_IN_BYTES` 77 | * @param buf1 address of the VDB. 78 | * @param buf2 address of the second buffer. `NULL` if `LV_VDB_DOUBLE 0` 79 | */ 80 | void lv_vdb_set_adr(void * buf1, void * buf2); 81 | 82 | /** 83 | * Call in the display driver's 'disp_flush' function when the flushing is finished 84 | */ 85 | void lv_flush_ready(void); 86 | 87 | /** 88 | * Get currently active VDB, where the drawing happens. Used with `LV_VDB_DOUBLE 1` 89 | * @return pointer to the active VDB. If `LV_VDB_DOUBLE 0` give the single VDB 90 | */ 91 | lv_vdb_t * lv_vdb_get_active(void); 92 | 93 | /** 94 | * Get currently inactive VDB, which is being displayed or being flushed. Used with `LV_VDB_DOUBLE 1` 95 | * @return pointer to the inactive VDB. If `LV_VDB_DOUBLE 0` give the single VDB 96 | */ 97 | lv_vdb_t * lv_vdb_get_inactive(void); 98 | 99 | /** 100 | * Whether the flushing is in progress or not 101 | * @return true: flushing is in progress; false: flushing ready 102 | */ 103 | bool lv_vdb_is_flushing(void); 104 | 105 | /********************** 106 | * MACROS 107 | **********************/ 108 | 109 | #else /*LV_VDB_SIZE != 0*/ 110 | 111 | /*Just for compatibility*/ 112 | void lv_flush_ready(void); 113 | #endif 114 | 115 | #ifdef __cplusplus 116 | } /* extern "C" */ 117 | #endif 118 | 119 | #endif /*LV_VDB_H*/ 120 | -------------------------------------------------------------------------------- /include/display/lv_draw/lv_draw.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_H 7 | #define LV_DRAW_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 22 | #include "display/lv_core/lv_style.h" 23 | #include "display/lv_misc/lv_txt.h" 24 | 25 | /********************* 26 | * DEFINES 27 | *********************/ 28 | /*If image pixels contains alpha we need to know how much byte is a pixel*/ 29 | #if LV_COLOR_DEPTH == 1 || LV_COLOR_DEPTH == 8 30 | # define LV_IMG_PX_SIZE_ALPHA_BYTE 2 31 | #elif LV_COLOR_DEPTH == 16 32 | # define LV_IMG_PX_SIZE_ALPHA_BYTE 3 33 | #elif LV_COLOR_DEPTH == 32 34 | # define LV_IMG_PX_SIZE_ALPHA_BYTE 4 35 | #endif 36 | 37 | /********************** 38 | * TYPEDEFS 39 | **********************/ 40 | 41 | enum { 42 | LV_IMG_SRC_VARIABLE, 43 | LV_IMG_SRC_FILE, 44 | LV_IMG_SRC_SYMBOL, 45 | LV_IMG_SRC_UNKNOWN, 46 | }; 47 | typedef uint8_t lv_img_src_t; 48 | 49 | 50 | /********************** 51 | * GLOBAL PROTOTYPES 52 | **********************/ 53 | 54 | #if LV_ANTIALIAS != 0 55 | 56 | /** 57 | * Get the opacity of a pixel based it's position in a line segment 58 | * @param seg segment length 59 | * @param px_id position of of a pixel which opacity should be get [0..seg-1] 60 | * @param base_opa the base opacity 61 | * @return the opacity of the given pixel 62 | */ 63 | lv_opa_t lv_draw_aa_get_opa(lv_coord_t seg, lv_coord_t px_id, lv_opa_t base_opa); 64 | 65 | /** 66 | * Add a vertical anti-aliasing segment (pixels with decreasing opacity) 67 | * @param x start point x coordinate 68 | * @param y start point y coordinate 69 | * @param length length of segment (negative value to start from 0 opacity) 70 | * @param mask draw only in this area 71 | * @param color color of pixels 72 | * @param opa maximum opacity 73 | */ 74 | void lv_draw_aa_ver_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); 75 | 76 | /** 77 | * Add a horizontal anti-aliasing segment (pixels with decreasing opacity) 78 | * @param x start point x coordinate 79 | * @param y start point y coordinate 80 | * @param length length of segment (negative value to start from 0 opacity) 81 | * @param mask draw only in this area 82 | * @param color color of pixels 83 | * @param opa maximum opacity 84 | */ 85 | void lv_draw_aa_hor_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); 86 | #endif 87 | 88 | /********************** 89 | * GLOBAL VARIABLES 90 | **********************/ 91 | extern void (*const px_fp)(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); 92 | extern void (*const fill_fp)(const lv_area_t * coords, const lv_area_t * mask, lv_color_t color, lv_opa_t opa); 93 | extern void (*const letter_fp)(const lv_point_t * pos_p, const lv_area_t * mask, const lv_font_t * font_p, uint32_t letter, lv_color_t color, lv_opa_t opa); 94 | extern void (*const map_fp)(const lv_area_t * cords_p, const lv_area_t * mask_p, 95 | const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, 96 | lv_color_t recolor, lv_opa_t recolor_opa); 97 | 98 | /********************** 99 | * MACROS 100 | **********************/ 101 | 102 | /********************** 103 | * POST INCLUDES 104 | *********************/ 105 | #include "lv_draw_rect.h" 106 | #include "lv_draw_label.h" 107 | #include "lv_draw_img.h" 108 | #include "lv_draw_line.h" 109 | #include "lv_draw_triangle.h" 110 | 111 | #ifdef __cplusplus 112 | } /* extern "C" */ 113 | #endif 114 | 115 | #endif /*LV_DRAW_H*/ 116 | -------------------------------------------------------------------------------- /include/display/lv_draw/lv_draw.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_draw_vbasic.c 2 | CSRCS += lv_draw_rbasic.c 3 | CSRCS += lv_draw.c 4 | CSRCS += lv_draw_rect.c 5 | CSRCS += lv_draw_label.c 6 | CSRCS += lv_draw_line.c 7 | CSRCS += lv_draw_img.c 8 | CSRCS += lv_draw_arc.c 9 | CSRCS += lv_draw_triangle.c 10 | 11 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_draw 12 | VPATH += :$(LVGL_DIR)/lvgl/lv_draw 13 | 14 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_draw" 15 | -------------------------------------------------------------------------------- /include/display/lv_draw/lv_draw_arc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_arc.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_ARC_H 7 | #define LV_DRAW_ARC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_draw.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | 30 | /** 31 | * Draw an arc. (Can draw pie too with great thickness.) 32 | * @param center_x the x coordinate of the center of the arc 33 | * @param center_y the y coordinate of the center of the arc 34 | * @param radius the radius of the arc 35 | * @param mask the arc will be drawn only in this mask 36 | * @param start_angle the start angle of the arc (0 deg on the bottom, 90 deg on the right) 37 | * @param end_angle the end angle of the arc 38 | * @param style style of the arc (`body.thickness`, `body.main_color`, `body.opa` is used) 39 | * @param opa_scale scale down all opacities by the factor 40 | */ 41 | void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, const lv_area_t * mask, 42 | uint16_t start_angle, uint16_t end_angle, const lv_style_t * style, lv_opa_t opa_scale); 43 | 44 | /********************** 45 | * MACROS 46 | **********************/ 47 | 48 | 49 | #ifdef __cplusplus 50 | } /* extern "C" */ 51 | #endif 52 | 53 | #endif /*LV_DRAW_ARC*/ 54 | -------------------------------------------------------------------------------- /include/display/lv_draw/lv_draw_label.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_label.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_LABEL_H 7 | #define LV_DRAW_LABEL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_draw.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | 30 | /** 31 | * Write a text 32 | * @param coords coordinates of the label 33 | * @param mask the label will be drawn only in this area 34 | * @param style pointer to a style 35 | * @param opa_scale scale down all opacities by the factor 36 | * @param txt 0 terminated text to write 37 | * @param flag settings for the text from 'txt_flag_t' enum 38 | * @param offset text offset in x and y direction (NULL if unused) 39 | * 40 | */ 41 | void lv_draw_label(const lv_area_t * coords,const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale, 42 | const char * txt, lv_txt_flag_t flag, lv_point_t * offset); 43 | 44 | /********************** 45 | * MACROS 46 | **********************/ 47 | 48 | 49 | #ifdef __cplusplus 50 | } /* extern "C" */ 51 | #endif 52 | 53 | #endif /*LV_DRAW_LABEL_H*/ 54 | -------------------------------------------------------------------------------- /include/display/lv_draw/lv_draw_line.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_line.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_LINE_H 7 | #define LV_DRAW_LINE_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | /********************* 18 | * DEFINES 19 | *********************/ 20 | 21 | /********************** 22 | * TYPEDEFS 23 | **********************/ 24 | 25 | /********************** 26 | * GLOBAL PROTOTYPES 27 | **********************/ 28 | 29 | /** 30 | * Draw a line 31 | * @param point1 first point of the line 32 | * @param point2 second point of the line 33 | * @param mask the line will be drawn only on this area 34 | * @param style pointer to a line's style 35 | * @param opa_scale scale down all opacities by the factor 36 | */ 37 | void lv_draw_line(const lv_point_t * point1, const lv_point_t * point2, const lv_area_t * mask, 38 | const lv_style_t * style, lv_opa_t opa_scale); 39 | 40 | /********************** 41 | * MACROS 42 | **********************/ 43 | 44 | 45 | #ifdef __cplusplus 46 | } /* extern "C" */ 47 | #endif 48 | 49 | #endif /*LV_DRAW_LINE_H*/ 50 | -------------------------------------------------------------------------------- /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 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_REAL_DRAW != 0 23 | 24 | #include "display/lv_misc/lv_color.h" 25 | #include "display/lv_misc/lv_area.h" 26 | #include "display/lv_misc/lv_font.h" 27 | 28 | /********************* 29 | * DEFINES 30 | *********************/ 31 | 32 | /********************** 33 | * TYPEDEFS 34 | **********************/ 35 | 36 | /********************** 37 | * GLOBAL PROTOTYPES 38 | **********************/ 39 | 40 | void lv_rpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa); 41 | 42 | /** 43 | * Fill an area on the display 44 | * @param cords_p coordinates of the area to fill 45 | * @param mask_p fill only o this mask 46 | * @param color fill color 47 | * @param opa opacity (ignored, only for compatibility with lv_vfill) 48 | */ 49 | void lv_rfill(const lv_area_t * cords_p, const lv_area_t * mask_p, 50 | lv_color_t color, lv_opa_t opa); 51 | 52 | /** 53 | * Draw a letter to the display 54 | * @param pos_p left-top coordinate of the latter 55 | * @param mask_p the letter will be drawn only on this area 56 | * @param font_p pointer to font 57 | * @param letter a letter to draw 58 | * @param color color of letter 59 | * @param opa opacity of letter (ignored, only for compatibility with lv_vletter) 60 | */ 61 | void lv_rletter(const lv_point_t * pos_p, const lv_area_t * mask_p, 62 | const lv_font_t * font_p, uint32_t letter, 63 | lv_color_t color, lv_opa_t opa); 64 | 65 | /** 66 | * When the letter is ant-aliased it needs to know the background color 67 | * @param bg_color the background color of the currently drawn letter 68 | */ 69 | void lv_rletter_set_background(lv_color_t color); 70 | 71 | 72 | /** 73 | * Draw a color map to the display (image) 74 | * @param cords_p coordinates the color map 75 | * @param mask_p the map will drawn only on this area 76 | * @param map_p pointer to a lv_color_t array 77 | * @param opa opacity of the map (ignored, only for compatibility with 'lv_vmap') 78 | * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels 79 | * @param alpha_byte true: extra alpha byte is inserted for every pixel (not supported, only l'v_vmap' can draw it) 80 | * @param recolor mix the pixels with this color 81 | * @param recolor_opa the intense of recoloring 82 | */ 83 | void lv_rmap(const lv_area_t * cords_p, const lv_area_t * mask_p, 84 | const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, 85 | lv_color_t recolor, lv_opa_t recolor_opa); 86 | /********************** 87 | * MACROS 88 | **********************/ 89 | 90 | #endif /*USE_LV_REAL_DRAW*/ 91 | 92 | #ifdef __cplusplus 93 | } /* extern "C" */ 94 | #endif 95 | 96 | #endif /*LV_DRAW_RBASIC_H*/ 97 | -------------------------------------------------------------------------------- /include/display/lv_draw/lv_draw_rect.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_rect.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_RECT_H 7 | #define LV_DRAW_RECT_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_draw.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | 30 | /** 31 | * Draw a rectangle 32 | * @param coords the coordinates of the rectangle 33 | * @param mask the rectangle will be drawn only in this mask 34 | * @param style pointer to a style 35 | * @param opa_scale scale down all opacities by the factor 36 | */ 37 | void lv_draw_rect(const lv_area_t * coords, const lv_area_t * mask, const lv_style_t * style, lv_opa_t opa_scale); 38 | 39 | /********************** 40 | * MACROS 41 | **********************/ 42 | 43 | 44 | #ifdef __cplusplus 45 | } /* extern "C" */ 46 | #endif 47 | 48 | #endif /*LV_DRAW_RECT_H*/ 49 | -------------------------------------------------------------------------------- /include/display/lv_draw/lv_draw_triangle.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_draw_triangle.h 3 | * 4 | */ 5 | 6 | #ifndef LV_DRAW_TRIANGLE_H 7 | #define LV_DRAW_TRIANGLE_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #include "lv_draw.h" 17 | 18 | /********************* 19 | * DEFINES 20 | *********************/ 21 | 22 | /********************** 23 | * TYPEDEFS 24 | **********************/ 25 | 26 | /********************** 27 | * GLOBAL PROTOTYPES 28 | **********************/ 29 | /*Experimental use for 3D modeling*/ 30 | #define USE_LV_TRIANGLE 1 31 | 32 | #if USE_LV_TRIANGLE != 0 33 | /** 34 | * 35 | * @param points pointer to an array with 3 points 36 | * @param mask the triangle will be drawn only in this mask 37 | * @param color color of the triangle 38 | */ 39 | void lv_draw_triangle(const lv_point_t * points, const lv_area_t * mask, lv_color_t color); 40 | #endif 41 | 42 | /********************** 43 | * MACROS 44 | **********************/ 45 | 46 | 47 | #ifdef __cplusplus 48 | } /* extern "C" */ 49 | #endif 50 | 51 | #endif /*LV_DRAW_TRIANGLE_H*/ 52 | -------------------------------------------------------------------------------- /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 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 22 | #if LV_VDB_SIZE != 0 23 | 24 | #include "display/lv_misc/lv_color.h" 25 | #include "display/lv_misc/lv_area.h" 26 | #include "display/lv_misc/lv_font.h" 27 | 28 | /********************* 29 | * DEFINES 30 | *********************/ 31 | 32 | /********************** 33 | * TYPEDEFS 34 | **********************/ 35 | 36 | /********************** 37 | * GLOBAL PROTOTYPES 38 | **********************/ 39 | 40 | void lv_vpx(lv_coord_t x, lv_coord_t y, const lv_area_t * mask_p, lv_color_t color, lv_opa_t opa); 41 | /** 42 | * Fill an area in the Virtual Display Buffer 43 | * @param cords_p coordinates of the area to fill 44 | * @param mask_p fill only o this mask 45 | * @param color fill color 46 | * @param opa opacity of the area (0..255) 47 | */ 48 | void lv_vfill(const lv_area_t * cords_p, const lv_area_t * mask_p, 49 | lv_color_t color, lv_opa_t opa); 50 | 51 | /** 52 | * Draw a letter in the Virtual Display Buffer 53 | * @param pos_p left-top coordinate of the latter 54 | * @param mask_p the letter will be drawn only on this area 55 | * @param font_p pointer to font 56 | * @param letter a letter to draw 57 | * @param color color of letter 58 | * @param opa opacity of letter (0..255) 59 | */ 60 | void lv_vletter(const lv_point_t * pos_p, const lv_area_t * mask_p, 61 | const lv_font_t * font_p, uint32_t letter, 62 | lv_color_t color, lv_opa_t opa); 63 | 64 | /** 65 | * Draw a color map to the display (image) 66 | * @param cords_p coordinates the color map 67 | * @param mask_p the map will drawn only on this area (truncated to VDB area) 68 | * @param map_p pointer to a lv_color_t array 69 | * @param opa opacity of the map 70 | * @param chroma_keyed true: enable transparency of LV_IMG_LV_COLOR_TRANSP color pixels 71 | * @param alpha_byte true: extra alpha byte is inserted for every pixel 72 | * @param recolor mix the pixels with this color 73 | * @param recolor_opa the intense of recoloring 74 | */ 75 | void lv_vmap(const lv_area_t * cords_p, const lv_area_t * mask_p, 76 | const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte, 77 | lv_color_t recolor, lv_opa_t recolor_opa); 78 | 79 | /********************** 80 | * MACROS 81 | **********************/ 82 | 83 | #endif /*LV_VDB_SIZE != 0*/ 84 | 85 | #ifdef __cplusplus 86 | } /* extern "C" */ 87 | #endif 88 | 89 | #endif /*LV_DRAW_RBASIC_H*/ 90 | -------------------------------------------------------------------------------- /include/display/lv_fonts/lv_font_builtin.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_font_builtin.h 3 | * 4 | */ 5 | 6 | #ifndef LV_FONT_BUILTIN_H 7 | #define LV_FONT_BUILTIN_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 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 | /** 37 | * Initialize the built-in fonts 38 | */ 39 | void lv_font_builtin_init(void); 40 | 41 | /********************** 42 | * MACROS 43 | **********************/ 44 | 45 | /********************** 46 | * FONT DECLARATIONS 47 | **********************/ 48 | 49 | /*10 px */ 50 | #if USE_LV_FONT_DEJAVU_10 51 | LV_FONT_DECLARE(lv_font_dejavu_10); 52 | #endif 53 | 54 | #if USE_LV_FONT_DEJAVU_10_LATIN_SUP 55 | LV_FONT_DECLARE(lv_font_dejavu_10_latin_sup); 56 | #endif 57 | 58 | #if USE_LV_FONT_DEJAVU_10_CYRILLIC 59 | LV_FONT_DECLARE(lv_font_dejavu_10_cyrillic); 60 | #endif 61 | 62 | #if USE_LV_FONT_SYMBOL_10 63 | LV_FONT_DECLARE(lv_font_symbol_10); 64 | #endif 65 | 66 | /*20 px */ 67 | #if USE_LV_FONT_DEJAVU_20 68 | LV_FONT_DECLARE(lv_font_dejavu_20); 69 | #endif 70 | 71 | #if USE_LV_FONT_DEJAVU_20_LATIN_SUP 72 | LV_FONT_DECLARE(lv_font_dejavu_20_latin_sup); 73 | #endif 74 | 75 | #if USE_LV_FONT_DEJAVU_20_CYRILLIC 76 | LV_FONT_DECLARE(lv_font_dejavu_20_cyrillic); 77 | #endif 78 | 79 | #if USE_LV_FONT_SYMBOL_20 80 | LV_FONT_DECLARE(lv_font_symbol_20); 81 | #endif 82 | 83 | /*30 px */ 84 | #if USE_LV_FONT_DEJAVU_30 85 | LV_FONT_DECLARE(lv_font_dejavu_30); 86 | #endif 87 | 88 | #if USE_LV_FONT_DEJAVU_30_LATIN_SUP 89 | LV_FONT_DECLARE(lv_font_dejavu_30_latin_sup); 90 | #endif 91 | 92 | #if USE_LV_FONT_DEJAVU_30_CYRILLIC 93 | LV_FONT_DECLARE(lv_font_dejavu_30_cyrillic); 94 | #endif 95 | 96 | #if USE_LV_FONT_SYMBOL_30 97 | LV_FONT_DECLARE(lv_font_symbol_30); 98 | #endif 99 | 100 | /*40 px */ 101 | #if USE_LV_FONT_DEJAVU_40 102 | LV_FONT_DECLARE(lv_font_dejavu_40); 103 | #endif 104 | 105 | #if USE_LV_FONT_DEJAVU_40_LATIN_SUP 106 | LV_FONT_DECLARE(lv_font_dejavu_40_latin_sup); 107 | #endif 108 | 109 | #if USE_LV_FONT_DEJAVU_40_CYRILLIC 110 | LV_FONT_DECLARE(lv_font_dejavu_40_cyrillic); 111 | #endif 112 | 113 | #if USE_LV_FONT_SYMBOL_40 114 | LV_FONT_DECLARE(lv_font_symbol_40); 115 | #endif 116 | 117 | #if USE_LV_FONT_MONOSPACE_8 118 | LV_FONT_DECLARE(lv_font_monospace_8); 119 | #endif 120 | 121 | #if USE_PROS_FONT_DEJAVU_MONO_10 122 | LV_FONT_DECLARE(pros_font_dejavu_mono_10); 123 | #endif 124 | #if USE_PROS_FONT_DEJAVU_MONO_10_LATIN_SUP 125 | LV_FONT_DECLARE(pros_font_dejavu_mono_10_latin_sup); 126 | #endif 127 | #if USE_PROS_FONT_DEJAVU_MONO_20 128 | LV_FONT_DECLARE(pros_font_dejavu_mono_20); 129 | #endif 130 | #if USE_PROS_FONT_DEJAVU_MONO_20_LATIN_SUP 131 | LV_FONT_DECLARE(pros_font_dejavu_mono_20_latin_sup); 132 | #endif 133 | #if USE_PROS_FONT_DEJAVU_MONO_30 134 | LV_FONT_DECLARE(pros_font_dejavu_mono_30); 135 | #endif 136 | #if USE_PROS_FONT_DEJAVU_MONO_30_LATIN_SUP 137 | LV_FONT_DECLARE(pros_font_dejavu_mono_30_latin_sup); 138 | #endif 139 | #if USE_PROS_FONT_DEJAVU_MONO_40 140 | LV_FONT_DECLARE(pros_font_dejavu_mono_40); 141 | #endif 142 | #if USE_PROS_FONT_DEJAVU_MONO_40_LATIN_SUP 143 | LV_FONT_DECLARE(pros_font_dejavu_mono_40_latin_sup); 144 | #endif 145 | 146 | #ifdef __cplusplus 147 | } /* extern "C" */ 148 | #endif 149 | 150 | #endif /*LV_FONT_BUILTIN_H*/ 151 | -------------------------------------------------------------------------------- /include/display/lv_fonts/lv_fonts.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_font_builtin.c 2 | CSRCS += lv_font_dejavu_10.c 3 | CSRCS += lv_font_dejavu_20.c 4 | CSRCS += lv_font_dejavu_30.c 5 | CSRCS += lv_font_dejavu_40.c 6 | CSRCS += lv_font_dejavu_10_cyrillic.c 7 | CSRCS += lv_font_dejavu_20_cyrillic.c 8 | CSRCS += lv_font_dejavu_30_cyrillic.c 9 | CSRCS += lv_font_dejavu_40_cyrillic.c 10 | CSRCS += lv_font_dejavu_10_latin_sup.c 11 | CSRCS += lv_font_dejavu_20_latin_sup.c 12 | CSRCS += lv_font_dejavu_30_latin_sup.c 13 | CSRCS += lv_font_dejavu_40_latin_sup.c 14 | CSRCS += lv_font_symbol_10.c 15 | CSRCS += lv_font_symbol_20.c 16 | CSRCS += lv_font_symbol_30.c 17 | CSRCS += lv_font_symbol_40.c 18 | CSRCS += lv_font_monospace_8.c 19 | 20 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_fonts 21 | VPATH += :$(LVGL_DIR)/lvgl/lv_fonts 22 | 23 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_fonts" 24 | -------------------------------------------------------------------------------- /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/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_DIR)/lvgl/lv_hal 6 | VPATH += :$(LVGL_DIR)/lvgl/lv_hal 7 | 8 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_hal" 9 | -------------------------------------------------------------------------------- /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 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | #include 22 | #include 23 | 24 | /********************* 25 | * DEFINES 26 | *********************/ 27 | #ifndef LV_ATTRIBUTE_TICK_INC 28 | #define LV_ATTRIBUTE_TICK_INC 29 | #endif 30 | 31 | /********************** 32 | * TYPEDEFS 33 | **********************/ 34 | 35 | /********************** 36 | * GLOBAL PROTOTYPES 37 | **********************/ 38 | 39 | /** 40 | * You have to call this function periodically 41 | * @param tick_period the call period of this function in milliseconds 42 | */ 43 | LV_ATTRIBUTE_TICK_INC void lv_tick_inc(uint32_t tick_period); 44 | 45 | /** 46 | * Get the elapsed milliseconds since start up 47 | * @return the elapsed milliseconds 48 | */ 49 | uint32_t lv_tick_get(void); 50 | 51 | /** 52 | * Get the elapsed milliseconds since a previous time stamp 53 | * @param prev_tick a previous time stamp (return value of systick_get() ) 54 | * @return the elapsed milliseconds since 'prev_tick' 55 | */ 56 | uint32_t lv_tick_elaps(uint32_t prev_tick); 57 | 58 | /********************** 59 | * MACROS 60 | **********************/ 61 | 62 | #ifdef __cplusplus 63 | } /* extern "C" */ 64 | #endif 65 | 66 | #endif /*LV_HAL_TICK_H*/ 67 | -------------------------------------------------------------------------------- /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 | /********************* 15 | * INCLUDES 16 | *********************/ 17 | #include 18 | #include "lv_area.h" 19 | 20 | /********************* 21 | * DEFINES 22 | *********************/ 23 | #define LV_CIRC_OCT1_X(p) (p.x) 24 | #define LV_CIRC_OCT1_Y(p) (p.y) 25 | #define LV_CIRC_OCT2_X(p) (p.y) 26 | #define LV_CIRC_OCT2_Y(p) (p.x) 27 | #define LV_CIRC_OCT3_X(p) (-p.y) 28 | #define LV_CIRC_OCT3_Y(p) (p.x) 29 | #define LV_CIRC_OCT4_X(p) (-p.x) 30 | #define LV_CIRC_OCT4_Y(p) (p.y) 31 | #define LV_CIRC_OCT5_X(p) (-p.x) 32 | #define LV_CIRC_OCT5_Y(p) (-p.y) 33 | #define LV_CIRC_OCT6_X(p) (-p.y) 34 | #define LV_CIRC_OCT6_Y(p) (-p.x) 35 | #define LV_CIRC_OCT7_X(p) (p.y) 36 | #define LV_CIRC_OCT7_Y(p) (-p.x) 37 | #define LV_CIRC_OCT8_X(p) (p.x) 38 | #define LV_CIRC_OCT8_Y(p) (-p.y) 39 | 40 | /********************** 41 | * TYPEDEFS 42 | **********************/ 43 | 44 | /********************** 45 | * GLOBAL PROTOTYPES 46 | **********************/ 47 | 48 | /** 49 | * Initialize the circle drawing 50 | * @param c pointer to a point. The coordinates will be calculated here 51 | * @param tmp point to a variable. It will store temporary data 52 | * @param radius radius of the circle 53 | */ 54 | void lv_circ_init(lv_point_t * c, lv_coord_t * tmp, lv_coord_t radius); 55 | 56 | /** 57 | * Test the circle drawing is ready or not 58 | * @param c same as in circ_init 59 | * @return true if the circle is not ready yet 60 | */ 61 | bool lv_circ_cont(lv_point_t * c); 62 | 63 | /** 64 | * Get the next point from the circle 65 | * @param c same as in circ_init. The next point stored here. 66 | * @param tmp same as in circ_init. 67 | */ 68 | void lv_circ_next(lv_point_t * c, lv_coord_t * tmp); 69 | 70 | /********************** 71 | * MACROS 72 | **********************/ 73 | 74 | #ifdef __cplusplus 75 | } /* extern "C" */ 76 | #endif 77 | 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /include/display/lv_misc/lv_gc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_gc.h 3 | * 4 | */ 5 | 6 | #ifndef LV_GC_H 7 | #define LV_GC_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | #ifdef LV_CONF_INCLUDE_SIMPLE 18 | #include "lv_conf.h" 19 | #else 20 | #include "display/lv_conf.h" 21 | #endif 22 | 23 | #include 24 | #include 25 | #include "lv_mem.h" 26 | #include "lv_ll.h" 27 | 28 | /********************* 29 | * DEFINES 30 | *********************/ 31 | 32 | #define LV_GC_ROOTS(prefix) \ 33 | prefix lv_ll_t _lv_task_ll; /*Linked list to store the lv_tasks*/ \ 34 | prefix lv_ll_t _lv_scr_ll; /*Linked list of screens*/ \ 35 | prefix lv_ll_t _lv_drv_ll;\ 36 | prefix lv_ll_t _lv_file_ll;\ 37 | prefix lv_ll_t _lv_anim_ll;\ 38 | prefix void * _lv_def_scr;\ 39 | prefix void * _lv_act_scr;\ 40 | prefix void * _lv_top_layer;\ 41 | prefix void * _lv_sys_layer;\ 42 | prefix void * _lv_task_act;\ 43 | prefix void * _lv_indev_list;\ 44 | prefix void * _lv_disp_list;\ 45 | 46 | 47 | #define LV_NO_PREFIX 48 | #define LV_ROOTS LV_GC_ROOTS(LV_NO_PREFIX) 49 | 50 | #if LV_ENABLE_GC == 1 51 | # if LV_MEM_CUSTOM != 1 52 | # error "GC requires CUSTOM_MEM" 53 | # endif /* LV_MEM_CUSTOM */ 54 | #else /* LV_ENABLE_GC */ 55 | # define LV_GC_ROOT(x) x 56 | LV_GC_ROOTS(extern) 57 | #endif /* LV_ENABLE_GC */ 58 | 59 | 60 | /********************** 61 | * TYPEDEFS 62 | **********************/ 63 | 64 | /********************** 65 | * GLOBAL PROTOTYPES 66 | **********************/ 67 | 68 | /********************** 69 | * MACROS 70 | **********************/ 71 | 72 | 73 | #ifdef __cplusplus 74 | } /* extern "C" */ 75 | #endif 76 | 77 | #endif /*LV_GC_H*/ 78 | -------------------------------------------------------------------------------- /include/display/lv_misc/lv_log.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_log.h 3 | * 4 | */ 5 | 6 | #ifndef LV_LOG_H 7 | #define LV_LOG_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | #include 22 | 23 | /********************* 24 | * DEFINES 25 | *********************/ 26 | 27 | /*Possible log level. For compatibility declare it independently from `USE_LV_LOG`*/ 28 | 29 | #define LV_LOG_LEVEL_TRACE 0 /*A lot of logs to give detailed information*/ 30 | #define LV_LOG_LEVEL_INFO 1 /*Log important events*/ 31 | #define LV_LOG_LEVEL_WARN 2 /*Log if something unwanted happened but didn't caused problem*/ 32 | #define LV_LOG_LEVEL_ERROR 3 /*Only critical issue, when the system may fail*/ 33 | #define _LV_LOG_LEVEL_NUM 4 34 | 35 | typedef int8_t lv_log_level_t; 36 | 37 | #if USE_LV_LOG 38 | /********************** 39 | * TYPEDEFS 40 | **********************/ 41 | 42 | 43 | /********************** 44 | * GLOBAL PROTOTYPES 45 | **********************/ 46 | 47 | /** 48 | * Register custom print (or anything else) function to call when log is added 49 | * @param f a function pointer: 50 | * `void my_print (lv_log_level_t level, const char * file, uint32_t line, const char * dsc)` 51 | */ 52 | void lv_log_register_print(void f(lv_log_level_t, const char *, uint32_t, const char *)); 53 | 54 | /** 55 | * Add a log 56 | * @param level the level of log. (From `lv_log_level_t` enum) 57 | * @param file name of the file when the log added 58 | * @param line line number in the source code where the log added 59 | * @param dsc description of the log 60 | */ 61 | void lv_log_add(lv_log_level_t level, const char * file, int line, const char * dsc); 62 | 63 | /********************** 64 | * MACROS 65 | **********************/ 66 | 67 | #define LV_LOG_TRACE(dsc) lv_log_add(LV_LOG_LEVEL_TRACE, __FILE__, __LINE__, dsc); 68 | #define LV_LOG_INFO(dsc) lv_log_add(LV_LOG_LEVEL_INFO, __FILE__, __LINE__, dsc); 69 | #define LV_LOG_WARN(dsc) lv_log_add(LV_LOG_LEVEL_WARN, __FILE__, __LINE__, dsc); 70 | #define LV_LOG_ERROR(dsc) lv_log_add(LV_LOG_LEVEL_ERROR, __FILE__, __LINE__, dsc); 71 | 72 | #else /*USE_LV_LOG*/ 73 | 74 | /*Do nothing if `USE_LV_LOG 0`*/ 75 | #define lv_log_add(level, file, line, dsc) {;} 76 | #define LV_LOG_TRACE(dsc) {;} 77 | #define LV_LOG_INFO(dsc) {;} 78 | #define LV_LOG_WARN(dsc) {;} 79 | #define LV_LOG_ERROR(dsc) {;} 80 | #endif /*USE_LV_LOG*/ 81 | 82 | #ifdef __cplusplus 83 | } /* extern "C" */ 84 | #endif 85 | 86 | #endif /*LV_LOG_H*/ 87 | -------------------------------------------------------------------------------- /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 | /********************* 15 | * INCLUDES 16 | *********************/ 17 | #include 18 | 19 | /********************* 20 | * DEFINES 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 | #define LV_TRIGO_SIN_MAX 32767 27 | #define LV_TRIGO_SHIFT 15 /* >> LV_TRIGO_SHIFT to normalize*/ 28 | 29 | #define LV_BEZIER_VAL_MAX 1024 /*Max time in Bezier functions (not [0..1] to use integers) */ 30 | #define LV_BEZIER_VAL_SHIFT 10 /*log2(LV_BEZIER_VAL_MAX): used to normalize up scaled values*/ 31 | 32 | /********************** 33 | * TYPEDEFS 34 | **********************/ 35 | 36 | /********************** 37 | * GLOBAL PROTOTYPES 38 | **********************/ 39 | /** 40 | * Convert a number to string 41 | * @param num a number 42 | * @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements) 43 | * @return same as `buf` (just for convenience) 44 | */ 45 | char * lv_math_num_to_str(int32_t num, char * buf); 46 | 47 | /** 48 | * Return with sinus of an angle 49 | * @param angle 50 | * @return sinus of 'angle'. sin(-90) = -32767, sin(90) = 32767 51 | */ 52 | int16_t lv_trigo_sin(int16_t angle); 53 | 54 | /** 55 | * Calculate a value of a Cubic Bezier function. 56 | * @param t time in range of [0..LV_BEZIER_VAL_MAX] 57 | * @param u0 start values in range of [0..LV_BEZIER_VAL_MAX] 58 | * @param u1 control value 1 values in range of [0..LV_BEZIER_VAL_MAX] 59 | * @param u2 control value 2 in range of [0..LV_BEZIER_VAL_MAX] 60 | * @param u3 end values in range of [0..LV_BEZIER_VAL_MAX] 61 | * @return the value calculated from the given parameters in range of [0..LV_BEZIER_VAL_MAX] 62 | */ 63 | int32_t lv_bezier3(uint32_t t, int32_t u0, int32_t u1, int32_t u2, int32_t u3); 64 | 65 | /********************** 66 | * MACROS 67 | **********************/ 68 | 69 | #ifdef __cplusplus 70 | } /* extern "C" */ 71 | #endif 72 | 73 | #endif 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 | /********************* 15 | * INCLUDES 16 | *********************/ 17 | #ifdef LV_CONF_INCLUDE_SIMPLE 18 | #include "lv_conf.h" 19 | #else 20 | #include "display/lv_conf.h" 21 | #endif 22 | 23 | #include 24 | #include 25 | #include "lv_log.h" 26 | 27 | /********************* 28 | * DEFINES 29 | *********************/ 30 | // Check windows 31 | #ifdef __WIN64 32 | # define LV_MEM_ENV64 33 | #endif 34 | 35 | // Check GCC 36 | #ifdef __GNUC__ 37 | # if defined(__x86_64__) || defined(__ppc64__) 38 | # define LV_MEM_ENV64 39 | # endif 40 | #endif 41 | 42 | /********************** 43 | * TYPEDEFS 44 | **********************/ 45 | 46 | typedef struct 47 | { 48 | uint32_t total_size; 49 | uint32_t free_cnt; 50 | uint32_t free_size; 51 | uint32_t free_biggest_size; 52 | uint32_t used_cnt; 53 | uint8_t used_pct; 54 | uint8_t frag_pct; 55 | } lv_mem_monitor_t; 56 | 57 | /********************** 58 | * GLOBAL PROTOTYPES 59 | **********************/ 60 | 61 | 62 | /** 63 | * Initiaize the dyn_mem module (work memory and other variables) 64 | */ 65 | void lv_mem_init(void); 66 | 67 | /** 68 | * Allocate a memory dynamically 69 | * @param size size of the memory to allocate in bytes 70 | * @return pointer to the allocated memory 71 | */ 72 | void * lv_mem_alloc(uint32_t size); 73 | 74 | /** 75 | * Free an allocated data 76 | * @param data pointer to an allocated memory 77 | */ 78 | void lv_mem_free(const void * data); 79 | 80 | /** 81 | * Reallocate a memory with a new size. The old content will be kept. 82 | * @param data pointer to an allocated memory. 83 | * Its content will be copied to the new memory block and freed 84 | * @param new_size the desired new size in byte 85 | * @return pointer to the new memory 86 | */ 87 | void * lv_mem_realloc(void * data_p, uint32_t new_size); 88 | 89 | /** 90 | * Join the adjacent free memory blocks 91 | */ 92 | void lv_mem_defrag(void); 93 | 94 | /** 95 | * Give information about the work memory of dynamic allocation 96 | * @param mon_p pointer to a dm_mon_p variable, 97 | * the result of the analysis will be stored here 98 | */ 99 | void lv_mem_monitor(lv_mem_monitor_t * mon_p); 100 | 101 | /** 102 | * Give the size of an allocated memory 103 | * @param data pointer to an allocated memory 104 | * @return the size of data memory in bytes 105 | */ 106 | uint32_t lv_mem_get_size(const void * data); 107 | 108 | 109 | /********************** 110 | * MACROS 111 | **********************/ 112 | 113 | /** 114 | * Halt on NULL pointer 115 | * p pointer to a memory 116 | */ 117 | #if USE_LV_LOG == 0 118 | # define lv_mem_assert(p) {if(p == NULL) while(1); } 119 | #else 120 | # define lv_mem_assert(p) {if(p == NULL) {LV_LOG_ERROR("Out of memory!"); while(1); }} 121 | #endif 122 | #ifdef __cplusplus 123 | } /* extern "C" */ 124 | #endif 125 | 126 | #endif /*LV_MEM_H*/ 127 | 128 | -------------------------------------------------------------------------------- /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_math.c 13 | CSRCS += lv_log.c 14 | CSRCS += lv_gc.c 15 | 16 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_misc 17 | VPATH += :$(LVGL_DIR)/lvgl/lv_misc 18 | 19 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_misc" 20 | -------------------------------------------------------------------------------- /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 called periodically. 4 | * A priority (5 levels + disable) can be assigned to lv_tasks. 5 | */ 6 | 7 | #ifndef LV_TASK_H 8 | #define LV_TASK_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /********************* 15 | * INCLUDES 16 | *********************/ 17 | #ifdef LV_CONF_INCLUDE_SIMPLE 18 | #include "lv_conf.h" 19 | #else 20 | #include "display/lv_conf.h" 21 | #endif 22 | 23 | #include 24 | #include 25 | #include "lv_mem.h" 26 | #include "lv_ll.h" 27 | 28 | /********************* 29 | * DEFINES 30 | *********************/ 31 | #ifndef LV_ATTRIBUTE_TASK_HANDLER 32 | #define LV_ATTRIBUTE_TASK_HANDLER 33 | #endif 34 | /********************** 35 | * TYPEDEFS 36 | **********************/ 37 | /** 38 | * Possible priorities for lv_tasks 39 | */ 40 | enum 41 | { 42 | LV_TASK_PRIO_OFF = 0, 43 | LV_TASK_PRIO_LOWEST, 44 | LV_TASK_PRIO_LOW, 45 | LV_TASK_PRIO_MID, 46 | LV_TASK_PRIO_HIGH, 47 | LV_TASK_PRIO_HIGHEST, 48 | LV_TASK_PRIO_NUM, 49 | }; 50 | typedef uint8_t lv_task_prio_t; 51 | 52 | /** 53 | * Descriptor of a lv_task 54 | */ 55 | typedef struct 56 | { 57 | uint32_t period; 58 | uint32_t last_run; 59 | void (*task) (void*); 60 | void * param; 61 | uint8_t prio:3; 62 | uint8_t once:1; 63 | } lv_task_t; 64 | 65 | /********************** 66 | * GLOBAL PROTOTYPES 67 | **********************/ 68 | 69 | /** 70 | * Init the lv_task module 71 | */ 72 | void lv_task_init(void); 73 | 74 | /** 75 | * Call it periodically to handle lv_tasks. 76 | */ 77 | LV_ATTRIBUTE_TASK_HANDLER void lv_task_handler(void); 78 | 79 | /** 80 | * Create a new lv_task 81 | * @param task a function which is the task itself 82 | * @param period call period in ms unit 83 | * @param prio priority of the task (LV_TASK_PRIO_OFF means the task is stopped) 84 | * @param param free parameter 85 | * @return pointer to the new task 86 | */ 87 | lv_task_t* lv_task_create(void (*task) (void *), uint32_t period, lv_task_prio_t prio, void * param); 88 | 89 | /** 90 | * Delete a lv_task 91 | * @param lv_task_p pointer to task created by lv_task_p 92 | */ 93 | void lv_task_del(lv_task_t* lv_task_p); 94 | 95 | /** 96 | * Set new priority for a lv_task 97 | * @param lv_task_p pointer to a lv_task 98 | * @param prio the new priority 99 | */ 100 | void lv_task_set_prio(lv_task_t* lv_task_p, lv_task_prio_t prio); 101 | 102 | /** 103 | * Set new period for a lv_task 104 | * @param lv_task_p pointer to a lv_task 105 | * @param period the new period 106 | */ 107 | void lv_task_set_period(lv_task_t* lv_task_p, uint32_t period); 108 | 109 | /** 110 | * Make a lv_task ready. It will not wait its period. 111 | * @param lv_task_p pointer to a lv_task. 112 | */ 113 | void lv_task_ready(lv_task_t* lv_task_p); 114 | 115 | 116 | /** 117 | * Delete the lv_task after one call 118 | * @param lv_task_p pointer to a lv_task. 119 | */ 120 | void lv_task_once(lv_task_t * lv_task_p); 121 | 122 | /** 123 | * Reset a lv_task. 124 | * It will be called the previously set period milliseconds later. 125 | * @param lv_task_p pointer to a lv_task. 126 | */ 127 | void lv_task_reset(lv_task_t* lv_task_p); 128 | 129 | /** 130 | * Enable or disable the whole lv_task handling 131 | * @param en: true: lv_task handling is running, false: lv_task handling is suspended 132 | */ 133 | void lv_task_enable(bool en); 134 | 135 | /** 136 | * Get idle percentage 137 | * @return the lv_task idle in percentage 138 | */ 139 | uint8_t lv_task_get_idle(void); 140 | 141 | /********************** 142 | * MACROS 143 | **********************/ 144 | 145 | #ifdef __cplusplus 146 | } /* extern "C" */ 147 | #endif 148 | 149 | #endif 150 | -------------------------------------------------------------------------------- /include/display/lv_misc/lv_templ.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.h 3 | * 4 | */ 5 | 6 | #ifndef LV_TEMPL_H 7 | #define LV_TEMPL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | 17 | /********************* 18 | * DEFINES 19 | *********************/ 20 | 21 | /********************** 22 | * TYPEDEFS 23 | **********************/ 24 | 25 | /********************** 26 | * GLOBAL PROTOTYPES 27 | **********************/ 28 | 29 | /********************** 30 | * MACROS 31 | **********************/ 32 | 33 | 34 | #ifdef __cplusplus 35 | } /* extern "C" */ 36 | #endif 37 | 38 | #endif /*LV_TEMPL_H*/ 39 | -------------------------------------------------------------------------------- /include/display/lv_objx/lv_arc.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_arc.h 3 | * 4 | */ 5 | 6 | 7 | #ifndef LV_ARC_H 8 | #define LV_ARC_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /********************* 15 | * INCLUDES 16 | *********************/ 17 | #ifdef LV_CONF_INCLUDE_SIMPLE 18 | #include "lv_conf.h" 19 | #else 20 | #include "display/lv_conf.h" 21 | #endif 22 | 23 | #if USE_LV_ARC != 0 24 | 25 | #include "display/lv_core/lv_obj.h" 26 | 27 | /********************* 28 | * DEFINES 29 | *********************/ 30 | 31 | /********************** 32 | * TYPEDEFS 33 | **********************/ 34 | /*Data of arc*/ 35 | typedef struct { 36 | /*New data for this type */ 37 | lv_coord_t angle_start; 38 | lv_coord_t angle_end; 39 | } lv_arc_ext_t; 40 | 41 | 42 | /*Styles*/ 43 | enum { 44 | LV_ARC_STYLE_MAIN, 45 | }; 46 | typedef uint8_t lv_arc_style_t; 47 | 48 | 49 | 50 | /********************** 51 | * GLOBAL PROTOTYPES 52 | **********************/ 53 | 54 | /** 55 | * Create a arc objects 56 | * @param par pointer to an object, it will be the parent of the new arc 57 | * @param copy pointer to a arc object, if not NULL then the new object will be copied from it 58 | * @return pointer to the created arc 59 | */ 60 | lv_obj_t * lv_arc_create(lv_obj_t * par, const lv_obj_t * copy); 61 | 62 | /*====================== 63 | * Add/remove functions 64 | *=====================*/ 65 | 66 | 67 | /*===================== 68 | * Setter functions 69 | *====================*/ 70 | 71 | /** 72 | * Set the start and end angles of an arc. 0 deg: bottom, 90 deg: right etc. 73 | * @param arc pointer to an arc object 74 | * @param start the start angle [0..360] 75 | * @param end the end angle [0..360] 76 | */ 77 | void lv_arc_set_angles(lv_obj_t * arc, uint16_t start, uint16_t end); 78 | 79 | /** 80 | * Set a style of a arc. 81 | * @param arc pointer to arc object 82 | * @param type which style should be set 83 | * @param style pointer to a style 84 | * */ 85 | void lv_arc_set_style(lv_obj_t * arc, lv_arc_style_t type, lv_style_t *style); 86 | 87 | /*===================== 88 | * Getter functions 89 | *====================*/ 90 | 91 | /** 92 | * Get the start angle of an arc. 93 | * @param arc pointer to an arc object 94 | * @return the start angle [0..360] 95 | */ 96 | uint16_t lv_arc_get_angle_start(lv_obj_t * arc); 97 | 98 | /** 99 | * Get the end angle of an arc. 100 | * @param arc pointer to an arc object 101 | * @return the end angle [0..360] 102 | */ 103 | uint16_t lv_arc_get_angle_end(lv_obj_t * arc); 104 | 105 | /** 106 | * Get style of a arc. 107 | * @param arc pointer to arc object 108 | * @param type which style should be get 109 | * @return style pointer to the style 110 | * */ 111 | lv_style_t * lv_arc_get_style(const lv_obj_t * arc, lv_arc_style_t type); 112 | 113 | /*===================== 114 | * Other functions 115 | *====================*/ 116 | 117 | /********************** 118 | * MACROS 119 | **********************/ 120 | 121 | #endif /*USE_LV_ARC*/ 122 | 123 | #ifdef __cplusplus 124 | } /* extern "C" */ 125 | #endif 126 | 127 | #endif /*LV_ARC_H*/ 128 | -------------------------------------------------------------------------------- /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 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_LED != 0 23 | 24 | #include "display/lv_core/lv_obj.h" 25 | 26 | /********************* 27 | * DEFINES 28 | *********************/ 29 | 30 | /********************** 31 | * TYPEDEFS 32 | **********************/ 33 | 34 | /*Data of led*/ 35 | typedef struct 36 | { 37 | /*No inherited ext.*/ 38 | /*New data for this type */ 39 | uint8_t bright; /*Current brightness of the LED (0..255)*/ 40 | } lv_led_ext_t; 41 | 42 | /********************** 43 | * GLOBAL PROTOTYPES 44 | **********************/ 45 | 46 | /** 47 | * Create a led objects 48 | * @param par pointer to an object, it will be the parent of the new led 49 | * @param copy pointer to a led object, if not NULL then the new object will be copied from it 50 | * @return pointer to the created led 51 | */ 52 | lv_obj_t * lv_led_create(lv_obj_t * par, const lv_obj_t * copy); 53 | 54 | /** 55 | * Set the brightness of a LED object 56 | * @param led pointer to a LED object 57 | * @param bright 0 (max. dark) ... 255 (max. light) 58 | */ 59 | void lv_led_set_bright(lv_obj_t * led, uint8_t bright); 60 | 61 | /** 62 | * Light on a LED 63 | * @param led pointer to a LED object 64 | */ 65 | void lv_led_on(lv_obj_t * led); 66 | 67 | /** 68 | * Light off a LED 69 | * @param led pointer to a LED object 70 | */ 71 | void lv_led_off(lv_obj_t * led); 72 | 73 | /** 74 | * Toggle the state of a LED 75 | * @param led pointer to a LED object 76 | */ 77 | void lv_led_toggle(lv_obj_t * led); 78 | 79 | /** 80 | * Set the style of a led 81 | * @param led pointer to a led object 82 | * @param style pointer to a style 83 | */ 84 | static inline void lv_led_set_style(lv_obj_t *led, lv_style_t *style) 85 | { 86 | lv_obj_set_style(led, style); 87 | } 88 | 89 | /** 90 | * Get the brightness of a LEd object 91 | * @param led pointer to LED object 92 | * @return bright 0 (max. dark) ... 255 (max. light) 93 | */ 94 | uint8_t lv_led_get_bright(const lv_obj_t * led); 95 | 96 | /** 97 | * Get the style of an led object 98 | * @param led pointer to an led object 99 | * @return pointer to the led's style 100 | */ 101 | static inline lv_style_t* lv_led_get_style(const lv_obj_t *led) 102 | { 103 | return lv_obj_get_style(led); 104 | } 105 | 106 | /********************** 107 | * MACROS 108 | **********************/ 109 | 110 | #endif /*USE_LV_LED*/ 111 | 112 | #ifdef __cplusplus 113 | } /* extern "C" */ 114 | #endif 115 | 116 | #endif /*LV_LED_H*/ 117 | -------------------------------------------------------------------------------- /include/display/lv_objx/lv_objx.mk: -------------------------------------------------------------------------------- 1 | CSRCS += lv_arc.c 2 | CSRCS += lv_bar.c 3 | CSRCS += lv_cb.c 4 | CSRCS += lv_ddlist.c 5 | CSRCS += lv_kb.c 6 | CSRCS += lv_line.c 7 | CSRCS += lv_mbox.c 8 | CSRCS += lv_preload.c 9 | CSRCS += lv_roller.c 10 | CSRCS += lv_table.c 11 | CSRCS += lv_tabview.c 12 | CSRCS += lv_tileview.c 13 | CSRCS += lv_btn.c 14 | CSRCS += lv_calendar.c 15 | CSRCS += lv_chart.c 16 | CSRCS += lv_canvas.c 17 | CSRCS += lv_gauge.c 18 | CSRCS += lv_label.c 19 | CSRCS += lv_list.c 20 | CSRCS += lv_slider.c 21 | CSRCS += lv_ta.c 22 | CSRCS += lv_spinbox.c 23 | CSRCS += lv_btnm.c 24 | CSRCS += lv_cont.c 25 | CSRCS += lv_img.c 26 | CSRCS += lv_imgbtn.c 27 | CSRCS += lv_led.c 28 | CSRCS += lv_lmeter.c 29 | CSRCS += lv_page.c 30 | CSRCS += lv_sw.c 31 | CSRCS += lv_win.c 32 | 33 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_objx 34 | VPATH += :$(LVGL_DIR)/lvgl/lv_objx 35 | 36 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_objx" 37 | -------------------------------------------------------------------------------- /include/display/lv_objx/lv_objx_templ.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_templ.h 3 | * 4 | */ 5 | 6 | 7 | /* TODO Remove these instructions 8 | * Search an replace: template -> object normal name with lower case (e.g. button, label etc.) 9 | * templ -> object short name with lower case(e.g. btn, label etc) 10 | * TEMPL -> object short name with upper case (e.g. BTN, LABEL etc.) 11 | * 12 | */ 13 | 14 | #ifndef LV_TEMPL_H 15 | #define LV_TEMPL_H 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /********************* 22 | * INCLUDES 23 | *********************/ 24 | #ifdef LV_CONF_INCLUDE_SIMPLE 25 | #include "lv_conf.h" 26 | #else 27 | #include "display/lv_conf.h" 28 | #endif 29 | 30 | #if USE_LV_TEMPL != 0 31 | 32 | #include "display/lv_core/lv_obj.h" 33 | 34 | /********************* 35 | * DEFINES 36 | *********************/ 37 | 38 | /********************** 39 | * TYPEDEFS 40 | **********************/ 41 | /*Data of template*/ 42 | typedef struct { 43 | lv_ANCESTOR_ext_t ANCESTOR; /*Ext. of ancestor*/ 44 | /*New data for this type */ 45 | } lv_templ_ext_t; 46 | 47 | 48 | /*Styles*/ 49 | enum { 50 | LV_TEMPL_STYLE_X, 51 | LV_TEMPL_STYLE_Y, 52 | }; 53 | typedef uint8_t lv_templ_style_t; 54 | 55 | 56 | /********************** 57 | * GLOBAL PROTOTYPES 58 | **********************/ 59 | 60 | /** 61 | * Create a template objects 62 | * @param par pointer to an object, it will be the parent of the new template 63 | * @param copy pointer to a template object, if not NULL then the new object will be copied from it 64 | * @return pointer to the created template 65 | */ 66 | lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy); 67 | 68 | /*====================== 69 | * Add/remove functions 70 | *=====================*/ 71 | 72 | 73 | /*===================== 74 | * Setter functions 75 | *====================*/ 76 | 77 | /** 78 | * Set a style of a template. 79 | * @param templ pointer to template object 80 | * @param type which style should be set 81 | * @param style pointer to a style 82 | */ 83 | void lv_templ_set_style(lv_obj_t * templ, lv_templ_style_t type, lv_style_t *style); 84 | 85 | /*===================== 86 | * Getter functions 87 | *====================*/ 88 | 89 | /** 90 | * Get style of a template. 91 | * @param templ pointer to template object 92 | * @param type which style should be get 93 | * @return style pointer to the style 94 | */ 95 | lv_style_t * lv_templ_get_style(const lv_obj_t * templ, lv_templ_style_t type); 96 | 97 | /*===================== 98 | * Other functions 99 | *====================*/ 100 | 101 | /********************** 102 | * MACROS 103 | **********************/ 104 | 105 | #endif /*USE_LV_TEMPL*/ 106 | 107 | #ifdef __cplusplus 108 | } /* extern "C" */ 109 | #endif 110 | 111 | #endif /*LV_TEMPL_H*/ 112 | -------------------------------------------------------------------------------- /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 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_THEME_ALIEN 23 | 24 | /********************* 25 | * DEFINES 26 | *********************/ 27 | 28 | /********************** 29 | * TYPEDEFS 30 | **********************/ 31 | 32 | /********************** 33 | * GLOBAL PROTOTYPES 34 | **********************/ 35 | 36 | /** 37 | * Initialize the alien theme 38 | * @param hue [0..360] hue value from HSV color space to define the theme's base color 39 | * @param font pointer to a font (NULL to use the default) 40 | * @return pointer to the initialized theme 41 | */ 42 | lv_theme_t * lv_theme_alien_init(uint16_t hue, lv_font_t *font); 43 | /** 44 | * Get a pointer to the theme 45 | * @return pointer to the theme 46 | */ 47 | lv_theme_t * lv_theme_get_alien(void); 48 | 49 | /********************** 50 | * MACROS 51 | **********************/ 52 | 53 | #endif 54 | 55 | #ifdef __cplusplus 56 | } /* extern "C" */ 57 | #endif 58 | 59 | #endif /*LV_THEME_ALIEN_H*/ 60 | -------------------------------------------------------------------------------- /include/display/lv_themes/lv_theme_default.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_theme_default.h 3 | * 4 | */ 5 | 6 | #ifndef LV_THEME_DEFAULT_H 7 | #define LV_THEME_DEFAULT_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_THEME_DEFAULT 23 | 24 | /********************* 25 | * DEFINES 26 | *********************/ 27 | 28 | /********************** 29 | * TYPEDEFS 30 | **********************/ 31 | 32 | /********************** 33 | * GLOBAL PROTOTYPES 34 | **********************/ 35 | 36 | /** 37 | * Initialize the default theme 38 | * @param hue [0..360] hue value from HSV color space to define the theme's base color 39 | * @param font pointer to a font (NULL to use the default) 40 | * @return pointer to the initialized theme 41 | */ 42 | lv_theme_t * lv_theme_default_init(uint16_t hue, lv_font_t *font); 43 | 44 | /** 45 | * Get a pointer to the theme 46 | * @return pointer to the theme 47 | */ 48 | lv_theme_t * lv_theme_get_default(void); 49 | 50 | /********************** 51 | * MACROS 52 | **********************/ 53 | 54 | #endif 55 | 56 | #ifdef __cplusplus 57 | } /* extern "C" */ 58 | #endif 59 | 60 | #endif /*LV_THEME_TEMPL_H*/ 61 | -------------------------------------------------------------------------------- /include/display/lv_themes/lv_theme_material.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_theme_material.h 3 | * 4 | */ 5 | 6 | #ifndef LV_THEME_MATERIAL_H 7 | #define LV_THEME_MATERIAL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_THEME_MATERIAL 23 | 24 | /********************* 25 | * DEFINES 26 | *********************/ 27 | 28 | /********************** 29 | * TYPEDEFS 30 | **********************/ 31 | 32 | /********************** 33 | * GLOBAL PROTOTYPES 34 | **********************/ 35 | 36 | /** 37 | * Initialize the material theme 38 | * @param hue [0..360] hue value from HSV color space to define the theme's base color 39 | * @param font pointer to a font (NULL to use the default) 40 | * @return pointer to the initialized theme 41 | */ 42 | lv_theme_t * lv_theme_material_init(uint16_t hue, lv_font_t *font); 43 | 44 | /** 45 | * Get a pointer to the theme 46 | * @return pointer to the theme 47 | */ 48 | lv_theme_t * lv_theme_get_material(void); 49 | 50 | /********************** 51 | * MACROS 52 | **********************/ 53 | 54 | #endif 55 | 56 | #ifdef __cplusplus 57 | } /* extern "C" */ 58 | #endif 59 | 60 | #endif /*LV_THEME_MATERIAL_H*/ 61 | -------------------------------------------------------------------------------- /include/display/lv_themes/lv_theme_mono.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_theme_mono.h 3 | * 4 | */ 5 | 6 | #ifndef LV_THEME_MONO_H 7 | #define LV_THEME_MONO_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_THEME_MONO 23 | 24 | /********************* 25 | * DEFINES 26 | *********************/ 27 | 28 | /********************** 29 | * TYPEDEFS 30 | **********************/ 31 | 32 | /********************** 33 | * GLOBAL PROTOTYPES 34 | **********************/ 35 | 36 | /** 37 | * Initialize the mono theme 38 | * @param hue [0..360] hue value from HSV color space to define the theme's base color 39 | * @param font pointer to a font (NULL to use the default) 40 | * @return pointer to the initialized theme 41 | */ 42 | lv_theme_t * lv_theme_mono_init(uint16_t hue, lv_font_t *font); 43 | 44 | /** 45 | * Get a pointer to the theme 46 | * @return pointer to the theme 47 | */ 48 | lv_theme_t * lv_theme_get_mono(void); 49 | 50 | /********************** 51 | * MACROS 52 | **********************/ 53 | 54 | #endif 55 | 56 | #ifdef __cplusplus 57 | } /* extern "C" */ 58 | #endif 59 | 60 | #endif /*LV_THEME_MONO_H*/ 61 | -------------------------------------------------------------------------------- /include/display/lv_themes/lv_theme_nemo.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_theme_nemo.h 3 | * 4 | */ 5 | 6 | #ifndef LV_THEME_NEMO_H 7 | #define LV_THEME_NEMO_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_THEME_NEMO 23 | 24 | /********************* 25 | * DEFINES 26 | *********************/ 27 | 28 | /********************** 29 | * TYPEDEFS 30 | **********************/ 31 | 32 | /********************** 33 | * GLOBAL PROTOTYPES 34 | **********************/ 35 | 36 | /** 37 | * Initialize the material theme 38 | * @param hue [0..360] hue value from HSV color space to define the theme's base color 39 | * @param font pointer to a font (NULL to use the default) 40 | * @return pointer to the initialized theme 41 | */ 42 | lv_theme_t * lv_theme_nemo_init(uint16_t hue, lv_font_t *font); 43 | 44 | /** 45 | * Get a pointer to the theme 46 | * @return pointer to the theme 47 | */ 48 | lv_theme_t * lv_theme_get_nemo(void); 49 | 50 | /********************** 51 | * MACROS 52 | **********************/ 53 | 54 | #endif 55 | 56 | #ifdef __cplusplus 57 | } /* extern "C" */ 58 | #endif 59 | 60 | #endif /*LV_THEME_NEMO_H*/ 61 | -------------------------------------------------------------------------------- /include/display/lv_themes/lv_theme_night.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_theme_night.h 3 | * 4 | */ 5 | 6 | #ifndef LV_THEME_NIGHT_H 7 | #define LV_THEME_NIGHT_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_THEME_NIGHT 23 | 24 | /********************* 25 | * DEFINES 26 | *********************/ 27 | 28 | /********************** 29 | * TYPEDEFS 30 | **********************/ 31 | 32 | /********************** 33 | * GLOBAL PROTOTYPES 34 | **********************/ 35 | 36 | /** 37 | * Initialize the night theme 38 | * @param hue [0..360] hue value from HSV color space to define the theme's base color 39 | * @param font pointer to a font (NULL to use the default) 40 | * @return pointer to the initialized theme 41 | */ 42 | lv_theme_t * lv_theme_night_init(uint16_t hue, lv_font_t *font); 43 | 44 | /** 45 | * Get a pointer to the theme 46 | * @return pointer to the theme 47 | */ 48 | lv_theme_t * lv_theme_get_night(void); 49 | 50 | /********************** 51 | * MACROS 52 | **********************/ 53 | 54 | #endif 55 | 56 | #ifdef __cplusplus 57 | } /* extern "C" */ 58 | #endif 59 | 60 | #endif /*LV_THEME_NIGHT_H*/ 61 | -------------------------------------------------------------------------------- /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 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_THEME_TEMPL 23 | 24 | /********************* 25 | * DEFINES 26 | *********************/ 27 | 28 | /********************** 29 | * TYPEDEFS 30 | **********************/ 31 | 32 | /********************** 33 | * GLOBAL PROTOTYPES 34 | **********************/ 35 | 36 | /** 37 | * Initialize the templ theme 38 | * @param hue [0..360] hue value from HSV color space to define the theme's base color 39 | * @param font pointer to a font (NULL to use the default) 40 | * @return pointer to the initialized theme 41 | */ 42 | lv_theme_t * lv_theme_templ_init(uint16_t hue, lv_font_t *font); 43 | 44 | /** 45 | * Get a pointer to the theme 46 | * @return pointer to the theme 47 | */ 48 | lv_theme_t * lv_theme_get_templ(void); 49 | 50 | /********************** 51 | * MACROS 52 | **********************/ 53 | 54 | #endif 55 | 56 | #ifdef __cplusplus 57 | } /* extern "C" */ 58 | #endif 59 | 60 | #endif /*LV_THEME_TEMPL_H*/ 61 | -------------------------------------------------------------------------------- /include/display/lv_themes/lv_theme_zen.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_theme_zen.h 3 | * 4 | */ 5 | 6 | #ifndef LV_THEME_ZEN_H 7 | #define LV_THEME_ZEN_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | #ifdef LV_CONF_INCLUDE_SIMPLE 17 | #include "lv_conf.h" 18 | #else 19 | #include "display/lv_conf.h" 20 | #endif 21 | 22 | #if USE_LV_THEME_ZEN 23 | 24 | /********************* 25 | * DEFINES 26 | *********************/ 27 | 28 | /********************** 29 | * TYPEDEFS 30 | **********************/ 31 | 32 | /********************** 33 | * GLOBAL PROTOTYPES 34 | **********************/ 35 | 36 | /** 37 | * Initialize the zen theme 38 | * @param hue [0..360] hue value from HSV color space to define the theme's base color 39 | * @param font pointer to a font (NULL to use the default) 40 | * @return pointer to the initialized theme 41 | */ 42 | lv_theme_t * lv_theme_zen_init(uint16_t hue, lv_font_t *font); 43 | 44 | /** 45 | * Get a pointer to the theme 46 | * @return pointer to the theme 47 | */ 48 | lv_theme_t * lv_theme_get_zen(void); 49 | 50 | /********************** 51 | * MACROS 52 | **********************/ 53 | 54 | #endif 55 | 56 | #ifdef __cplusplus 57 | } /* extern "C" */ 58 | #endif 59 | 60 | #endif /*LV_THEME_ZEN_H*/ 61 | -------------------------------------------------------------------------------- /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 | CSRCS += lv_theme_nemo.c 9 | CSRCS += lv_theme_mono.c 10 | 11 | DEPPATH += --dep-path $(LVGL_DIR)/lvgl/lv_themes 12 | VPATH += :$(LVGL_DIR)/lvgl/lv_themes 13 | 14 | CFLAGS += "-I$(LVGL_DIR)/lvgl/lv_themes" 15 | -------------------------------------------------------------------------------- /include/display/lv_version.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file lv_version.h 3 | * 4 | */ 5 | 6 | #ifndef LV_VERSION_H 7 | #define LV_VERSION_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" { 11 | #endif 12 | 13 | /********************* 14 | * INCLUDES 15 | *********************/ 16 | /*Current version of LittlevGL*/ 17 | #define LVGL_VERSION_MAJOR 5 18 | #define LVGL_VERSION_MINOR 3 19 | #define LVGL_VERSION_PATCH 0 20 | #define LVGL_VERSION_INFO "" 21 | 22 | 23 | /********************* 24 | * DEFINES 25 | *********************/ 26 | 27 | /********************** 28 | * TYPEDEFS 29 | **********************/ 30 | 31 | /********************** 32 | * GLOBAL PROTOTYPES 33 | **********************/ 34 | 35 | /********************** 36 | * MACROS 37 | **********************/ 38 | /* Gives 1 if the x.y.z version is supported in the current version 39 | * Usage: 40 | * 41 | * - Require v6 42 | * #if LV_VERSION_CHECK(6,0,0) 43 | * new_func_in_v6(); 44 | * #endif 45 | * 46 | * 47 | * - Require at least v5.3 48 | * #if LV_VERSION_CHECK(5,3,0) 49 | * new_feature_from_v5_3(); 50 | * #endif 51 | * 52 | * 53 | * - Require v5.3.2 bugfixes 54 | * #if LV_VERSION_CHECK(5,3,2) 55 | * bugfix_in_v5_3_2(); 56 | * #endif 57 | * 58 | * */ 59 | #define LV_VERSION_CHECK(x,y,z) (x == LVGL_VERSION_MAJOR && (y < LVGL_VERSION_MINOR || (y == LVGL_VERSION_MINOR && z <= LVGL_VERSION_PATCH))) 60 | 61 | 62 | #ifdef __cplusplus 63 | } /* extern "C" */ 64 | #endif 65 | 66 | #endif /*LV_VERSION_H*/ 67 | -------------------------------------------------------------------------------- /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 | #include "lv_version.h" 20 | 21 | #include "lv_misc/lv_log.h" 22 | #include "lv_misc/lv_task.h" 23 | 24 | #include "lv_hal/lv_hal.h" 25 | 26 | #include "lv_core/lv_obj.h" 27 | #include "lv_core/lv_group.h" 28 | #include "lv_core/lv_lang.h" 29 | #include "lv_core/lv_vdb.h" 30 | #include "lv_core/lv_refr.h" 31 | 32 | #include "lv_themes/lv_theme.h" 33 | 34 | #include "lv_objx/lv_btn.h" 35 | #include "lv_objx/lv_imgbtn.h" 36 | #include "lv_objx/lv_img.h" 37 | #include "lv_objx/lv_label.h" 38 | #include "lv_objx/lv_line.h" 39 | #include "lv_objx/lv_page.h" 40 | #include "lv_objx/lv_cont.h" 41 | #include "lv_objx/lv_list.h" 42 | #include "lv_objx/lv_chart.h" 43 | #include "lv_objx/lv_table.h" 44 | #include "lv_objx/lv_cb.h" 45 | #include "lv_objx/lv_bar.h" 46 | #include "lv_objx/lv_slider.h" 47 | #include "lv_objx/lv_led.h" 48 | #include "lv_objx/lv_btnm.h" 49 | #include "lv_objx/lv_kb.h" 50 | #include "lv_objx/lv_ddlist.h" 51 | #include "lv_objx/lv_roller.h" 52 | #include "lv_objx/lv_ta.h" 53 | #include "lv_objx/lv_canvas.h" 54 | #include "lv_objx/lv_win.h" 55 | #include "lv_objx/lv_tabview.h" 56 | #include "lv_objx/lv_tileview.h" 57 | #include "lv_objx/lv_mbox.h" 58 | #include "lv_objx/lv_gauge.h" 59 | #include "lv_objx/lv_lmeter.h" 60 | #include "lv_objx/lv_sw.h" 61 | #include "lv_objx/lv_kb.h" 62 | #include "lv_objx/lv_arc.h" 63 | #include "lv_objx/lv_preload.h" 64 | #include "lv_objx/lv_calendar.h" 65 | #include "lv_objx/lv_spinbox.h" 66 | #pragma GCC diagnostic pop 67 | 68 | /********************* 69 | * DEFINES 70 | *********************/ 71 | 72 | /********************** 73 | * TYPEDEFS 74 | **********************/ 75 | 76 | /********************** 77 | * GLOBAL PROTOTYPES 78 | **********************/ 79 | 80 | /********************** 81 | * MACROS 82 | **********************/ 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /*LVGL_H*/ 89 | -------------------------------------------------------------------------------- /include/gui.h: -------------------------------------------------------------------------------- 1 | #ifndef GUI_H 2 | #define GUI_H 3 | 4 | extern int auton_sel; 5 | void gui(void); 6 | 7 | #endif // GUI_H 8 | 9 | -------------------------------------------------------------------------------- /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 | // change api.h to apix.h for lvgl support (apix.h includes 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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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/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 -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /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/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 -------------------------------------------------------------------------------- /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/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/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/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/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-2019, 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 | -------------------------------------------------------------------------------- /src/autonomous.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "gui.h" 3 | 4 | /** 5 | * Runs the user autonomous code. This function will be started in its own task 6 | * with the default priority and stack size whenever the robot is enabled via 7 | * the Field Management System or the VEX Competition Switch in the autonomous 8 | * mode. Alternatively, this function may be called in initialize or opcontrol 9 | * for non-competition testing purposes. 10 | * 11 | * If the robot is disabled or communications is lost, the autonomous task 12 | * will be stopped. Re-enabling the robot will restart the task, not re-start it 13 | * from where it left off. 14 | */ 15 | void autonomous() { 16 | switch (auton_sel) { 17 | case 1: 18 | // auton1(); 19 | break; 20 | case 2: 21 | // auton2(); 22 | break; 23 | default: 24 | // empty_auton(); 25 | break; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/initialize.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "gui.h" 3 | 4 | // comment or remove all pros::lcd calls 5 | // void on_center_button() { 6 | // static bool pressed = false; 7 | // pressed = !pressed; 8 | // if (pressed) { 9 | // pros::lcd::set_text(2, "I was pressed!"); 10 | // } else { 11 | // pros::lcd::clear_line(2); 12 | // } 13 | // } 14 | 15 | /** 16 | * Runs initialization code. This occurs as soon as the program is started. 17 | * 18 | * All other competition modes are blocked by initialize; it is recommended 19 | * to keep execution time for this mode under a few seconds. 20 | */ 21 | void initialize() { 22 | // pros::lcd::initialize(); 23 | // pros::lcd::set_text(1, "Hello PROS User!"); 24 | // 25 | // pros::lcd::register_btn1_cb(on_center_button); 26 | 27 | gui(); 28 | } 29 | 30 | /** 31 | * Runs while the robot is in the disabled state of Field Management System or 32 | * the VEX Competition Switch, following either autonomous or opcontrol. When 33 | * the robot is enabled, this task will exit. 34 | */ 35 | void disabled() {} 36 | 37 | /** 38 | * Runs after initialize(), and before autonomous when connected to the Field 39 | * Management System or the VEX Competition Switch. This is intended for 40 | * competition-specific initialization routines, such as an autonomous selector 41 | * on the LCD. 42 | * 43 | * This task will exit when the robot is enabled and autonomous or opcontrol 44 | * starts. 45 | */ 46 | void competition_initialize() {} 47 | -------------------------------------------------------------------------------- /src/opcontrol.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * Runs the operator control code. This function will be started in its own task 5 | * with the default priority and stack size whenever the robot is enabled via 6 | * the Field Management System or the VEX Competition Switch in the operator 7 | * control mode. 8 | * 9 | * If no competition control is connected, this function will run immediately 10 | * following initialize(). 11 | * 12 | * If the robot is disabled or communications is lost, the 13 | * operator control task will be stopped. Re-enabling the robot will restart the 14 | * task, not resume it from where it left off. 15 | */ 16 | void opcontrol() { 17 | 18 | // there is only a brain for this lvgl example 19 | // pros::Controller master(pros::E_CONTROLLER_MASTER); 20 | // pros::Motor left_mtr(1); 21 | // pros::Motor right_mtr(2); 22 | while (true) { 23 | // pros::lcd::print(0, "%d %d %d", (pros::lcd::read_buttons() & LCD_BTN_LEFT) >> 2, 24 | // (pros::lcd::read_buttons() & LCD_BTN_CENTER) >> 1, 25 | // (pros::lcd::read_buttons() & LCD_BTN_RIGHT) >> 0); 26 | // int left = master.get_analog(ANALOG_LEFT_Y); 27 | // int right = master.get_analog(ANALOG_RIGHT_Y); 28 | // 29 | // left_mtr = left; 30 | // right_mtr = right; 31 | pros::delay(20); 32 | } 33 | } 34 | --------------------------------------------------------------------------------