From 8ecc51e893f95dee34bfe5f8756154a86999885f Mon Sep 17 00:00:00 2001 From: Octogonapus Date: Mon, 28 Sep 2020 20:29:59 -0400 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=93=9D=20Fix=20ADI=20encoder=20docs?= =?UTF-8?q?=20that=20are=20missing=20a=20comment=20about=20the=20allowed?= =?UTF-8?q?=20top=20port=20(#256)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/pros/adi.h | 2 +- include/pros/ext_adi.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/pros/adi.h b/include/pros/adi.h index 9af07d8a2..b850fc0a9 100644 --- a/include/pros/adi.h +++ b/include/pros/adi.h @@ -494,7 +494,7 @@ int32_t adi_encoder_get(adi_encoder_t enc); * * \param port_top * The "top" wire from the encoder sensor with the removable cover side - * up + * up. This should be in port 1, 3, 5, or 7 ('A', 'C', 'E', or 'G'). * \param port_bottom * The "bottom" wire from the encoder sensor * \param reverse diff --git a/include/pros/ext_adi.h b/include/pros/ext_adi.h index 881f74914..391617f4d 100644 --- a/include/pros/ext_adi.h +++ b/include/pros/ext_adi.h @@ -421,7 +421,7 @@ int32_t ext_adi_encoder_get(ext_adi_encoder_t enc); * The smart port number that the ADI Expander is in * \param adi_port_top * The "top" wire from the encoder sensor with the removable cover side - * up + * up. This should be in port 1, 3, 5, or 7 ('A', 'C', 'E', or 'G'). * \param adi_port_bottom * The "bottom" wire from the encoder sensor * \param reverse From c1691d1bc83173e816dbadb93798b69bc4743237 Mon Sep 17 00:00:00 2001 From: Alex Brooke Date: Wed, 28 Oct 2020 22:47:12 -0400 Subject: [PATCH 2/5] =?UTF-8?q?=E2=9C=A8=20Add=20Support=20for=20Distance?= =?UTF-8?q?=20Sensor=20(#257)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 5a66cee62c5920d1440d174c63de6fc41f8c63c1 Author: Kunwar Sahni Date: Sun Oct 11 14:47:42 2020 -0400 Change to virtual commit 803bf93b94207a880f15903fe4118c8fa55aca30 Author: mooreBrendan Date: Tue Oct 6 16:46:16 2020 -0400 changed get_size to int32_t in c++ commit af6768b2621c31a1bbcad30ffe81533c4cc7dc06 Author: Kunwar Sahni Date: Tue Oct 6 11:11:47 2020 -0400 Remove new line commit c46b79448ab417211c9684e69b7e7c12048e856d Author: Kunwar Sahni Date: Tue Oct 6 11:04:37 2020 -0400 Apply suggestions from code review Co-authored-by: Alex Brooke commit 7e94cfd1e776f8254f3eff28fdd9319b47826be6 Author: Kunwar Sahni Date: Sat Oct 3 17:59:53 2020 -0400 Add confidence documentation commit ee2e87ffd1fefb6063cb009ab12be1ea1fe364ec Author: Kunwar Sahni Date: Sat Oct 3 14:00:17 2020 -0400 Change to device sdk function commit db589a9cc2fd8413e9c218e0d5c12459d8586dd3 Merge: 6c91e5d ad938e5 Author: WillXuCodes Date: Sat Oct 3 01:19:19 2020 -0400 Merge branch 'feature/distance-sensor' of https://github.com/purduesigbots/pros into feature/distance-sensor commit 6c91e5dc217a25d8ceb4ff29dd44d66ae5d3fc80 Author: WillXuCodes Date: Sat Oct 3 01:14:10 2020 -0400 Fixed bad macro and extraneous newline commit ad938e5c357bc979c87bf305e8d77035f175f5de Author: Kunwar Sahni Date: Fri Oct 2 19:52:04 2020 -0400 Fix Formatting issues commit bb2c816c705a9fbc09446241ea09ca3bf68c23e3 Author: Kunwar Sahni Date: Fri Oct 2 19:45:30 2020 -0400 Apply suggestions from code review Co-authored-by: Alex Brooke commit 3bc747e2f2aa0ac24c08cfb0794ecdfb65c1f5a5 Author: Kunwar Sahni Date: Fri Oct 2 19:44:54 2020 -0400 Update include/pros/distance.h Co-authored-by: Alex Brooke commit 6684e6ed3b3d1a7c77118b6ace410d8c7be8f47e Author: Kunwar Sahni Date: Fri Oct 2 19:44:33 2020 -0400 Update include/pros/distance.h Co-authored-by: Alex Brooke commit 7872b50c8fe7c517c9e8a4827277f6cd11ade812 Author: Kunwar Sahni Date: Fri Oct 2 19:44:22 2020 -0400 Update include/pros/distance.h Co-authored-by: Alex Brooke commit 19d032a6cee9c700f7cf81e44cc5ff88349634cb Author: Kunwar Sahni Date: Fri Oct 2 19:44:12 2020 -0400 Update include/pros/distance.h Co-authored-by: Alex Brooke commit 050ec1598bb824f4cd91c254fd69ecb8fd1f1629 Author: Kunwar Sahni Date: Fri Oct 2 18:12:33 2020 -0400 Change to Device over index commit 7ad19a2f6ab088c47f222debad3f58bc4fc21f54 Author: WillXuCodes Date: Tue Sep 29 18:16:35 2020 -0400 Saved file commit cfd8e38fd25846e71039aba7af64cc0fafb2dcfd Author: WillXuCodes Date: Tue Sep 29 18:15:11 2020 -0400 Removed unnecessary using namespace pros::c from cpp file. commit 7e73e49ca12a90ec0b23ef987ba8cdf9207c7c0c Author: WillXuCodes Date: Tue Sep 29 18:04:46 2020 -0400 Added std:: to cpp files, and return types in the cpp files themselves. commit 72b801686b915c2ebebb9fc771e5ea753afb2907 Author: WillXuCodes Date: Tue Sep 29 17:56:02 2020 -0400 Added missing semi colon commit 5fa435caa3ee7e79c4c9d81f33ecc8c6afba2326 Author: WillXuCodes Date: Tue Sep 29 17:50:08 2020 -0400 Fixed error handling function commit b15afafa620e6ddee80c74ca8b194f4c946d0ebb Author: WillXuCodes Date: Tue Sep 29 17:28:48 2020 -0400 Added distance header files to api header. commit bdef884978e3d3cfd453fb9ea5ca55a818803e82 Author: WillXuCodes Date: Fri Sep 25 23:08:04 2020 -0400 Deleted unnecesary old comment regarding adding error handling commit f4d8f53871701fa12acb815547b8c50570cf2b25 Author: mooreBrendan Date: Fri Sep 25 19:24:40 2020 -0400 added the cpp file for the distance sensor and reverted main commit dda2bbfbd96384f95f0c7db7fa6ea02358d0bfd0 Author: WillXuCodes Date: Fri Sep 25 18:29:42 2020 -0400 Added bad port or device error handling (Needs review) commit fd2a4e2fe0f78b9912948bfb2754d877ed03f1c0 Merge: 0a3d5f9 bfc5a35 Author: WillXuCodes Date: Fri Sep 25 18:11:31 2020 -0400 Merge branch 'feature/distance-sensor' of https://github.com/purduesigbots/pros into feature/distance-sensor commit 0a3d5f9ff53eaad9f112c088b6c2408035329437 Author: WillXuCodes Date: Fri Sep 25 18:00:00 2020 -0400 Added distance sensor to device type enum, also started C file for distance sensor. commit bfc5a3555d357ecbfec87e01f104edbec7c12cc4 Author: mooreBrendan Date: Fri Sep 25 17:58:49 2020 -0400 fixed the #ifndef in hpp file commit a07f393003b32ce4d5f9f339df9c1fef61fbd653 Author: mooreBrendan Date: Fri Sep 25 17:55:20 2020 -0400 added distance.hpp commit 2ee04ea37b3b718cd0e049eb3f74d2e03371bacb Author: Kunwar Sahni Date: Fri Sep 25 11:40:51 2020 -0400 Add get confidence commit 0913f1ad71bddc5ade990d70784be0204a62f4d4 Author: Kunwar Sahni Date: Fri Sep 25 11:29:03 2020 -0400 Add Distance Header --- include/api.h | 2 + include/pros/apix.h | 1 + include/pros/distance.h | 101 ++++++++++++++++++++++++++++++ include/pros/distance.hpp | 114 ++++++++++++++++++++++++++++++++++ src/devices/vdml_distance.c | 53 ++++++++++++++++ src/devices/vdml_distance.cpp | 38 ++++++++++++ 6 files changed, 309 insertions(+) create mode 100644 include/pros/distance.h create mode 100644 include/pros/distance.hpp create mode 100644 src/devices/vdml_distance.c create mode 100644 src/devices/vdml_distance.cpp diff --git a/include/api.h b/include/api.h index 0f971bd65..066a6f1ce 100644 --- a/include/api.h +++ b/include/api.h @@ -49,6 +49,7 @@ #include "pros/adi.h" #include "pros/colors.h" +#include "pros/distance.h" #include "pros/ext_adi.h" #include "pros/imu.h" #include "pros/llemu.h" @@ -59,6 +60,7 @@ #ifdef __cplusplus #include "pros/adi.hpp" +#include "pros/distance.hpp" #include "pros/imu.hpp" #include "pros/llemu.hpp" #include "pros/misc.hpp" diff --git a/include/pros/apix.h b/include/pros/apix.h index 4727c9829..b28ad815a 100644 --- a/include/pros/apix.h +++ b/include/pros/apix.h @@ -370,6 +370,7 @@ typedef enum v5_device_e { E_DEVICE_NONE = 0, E_DEVICE_MOTOR = 2, E_DEVICE_IMU = 6, + E_DEVICE_DISTANCE = 7, E_DEVICE_RADIO = 8, E_DEVICE_VISION = 11, E_DEVICE_ADI = 12, diff --git a/include/pros/distance.h b/include/pros/distance.h new file mode 100644 index 000000000..115cf2adb --- /dev/null +++ b/include/pros/distance.h @@ -0,0 +1,101 @@ +/** + * \file pros/distance.h + * + * Contains prototypes for functions related to the VEX Distance sensor. + * + * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/distance.html to learn + * more. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * Copyright (c) 2017-2020, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef _PROS_DISTANCE_H_ +#define _PROS_DISTANCE_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +namespace pros { +namespace c { +#endif + +/** + * Get the currently measured distance from the sensor in mm + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Distance Sensor + * + * \param port The V5 Distance Sensor port number from 1-21 + * \return The distance value or PROS_ERR if the operation failed, setting + * errno. + */ +int32_t distance_get(uint8_t port); + +/** + * Get the confidence in the distance reading + * + * This is a value that has a range of 0 to 63. 63 means high confidence, + * lower values imply less confidence. Confidence is only available + * when distance is > 200mm (the value 10 is returned in this scenario). + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Distance Sensor + * + * \param port The V5 Distance Sensor port number from 1-21 + * \return The confidence value or PROS_ERR if the operation failed, setting + * errno. + */ +int32_t distance_get_confidence(uint8_t port); + +/** + * Get the current guess at relative object size + * + * This is a value that has a range of 0 to 400. + * A 18" x 30" grey card will return a value of approximately 75 + * in typical room lighting. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Distance Sensor + * + * \param port The V5 Distance Sensor port number from 1-21 + * \return The size value or PROS_ERR if the operation failed, setting + * errno. + */ +int32_t distance_get_object_size(uint8_t port); + +/** + * Get the object velocity in m/s + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Distance Sensor + * + * \param port The V5 Distance Sensor port number from 1-21 + * \return The velocity value or PROS_ERR if the operation failed, setting + * errno. + */ +double distance_get_object_velocity(uint8_t port); + +#ifdef __cplusplus +} +} +} +#endif + +#endif diff --git a/include/pros/distance.hpp b/include/pros/distance.hpp new file mode 100644 index 000000000..b584966aa --- /dev/null +++ b/include/pros/distance.hpp @@ -0,0 +1,114 @@ +/** + * \file pros/distance.hpp + * + * Contains prototypes for the V5 Distance Sensor-related functions. + * + * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/distance.html to learn + * more. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * \copyright (c) 2017-2018, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef _PROS_DISTANCE_HPP_ +#define _PROS_DISTANCE_HPP_ + +#include + +#include "pros/distance.h" + +namespace pros { +class Distance { + public: + /** + * Creates a Distance Sensor object for the given port. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as a Distance Sensor + * + * \param port + * The V5 port number from 1-21 + */ + explicit Distance(const std::uint8_t port); + + /** + * Get the currently measured distance from the sensor in mm + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Distance Sensor + * + * \return The distance value or PROS_ERR if the operation failed, setting + * errno. + */ + virtual std::int32_t get(); + + /** + * Get the confidence in the distance reading + * + * This is a value that has a range of 0 to 63. 63 means high confidence, + * lower values imply less confidence. Confidence is only available + * when distance is > 200mm. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Distance Sensor + * + * \return The confidence value or PROS_ERR if the operation failed, setting + * errno. + */ + virtual std::int32_t get_confidence(); + + /** + * Get the current guess at relative object size + * + * This is a value that has a range of 0 to 400. + * A 18" x 30" grey card will return a value of approximately 75 + * in typical room lighting. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Distance Sensor + * + * \return The size value or PROS_ERR if the operation failed, setting + * errno. + */ + virtual std::int32_t get_object_size(); + + /** + * Get the object velocity in m/s + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Distance Sensor + * + * \return The velocity value or PROS_ERR if the operation failed, setting + * errno. + */ + virtual double get_object_velocity(); + + /** + * Gets the port number of the distance sensor. + * + * \return The distance sensor's port number. + */ + std::uint8_t get_port(); + + private: + const std::uint8_t _port; +}; +} // namespace pros + +#endif diff --git a/src/devices/vdml_distance.c b/src/devices/vdml_distance.c new file mode 100644 index 000000000..3b560541d --- /dev/null +++ b/src/devices/vdml_distance.c @@ -0,0 +1,53 @@ +/** + * \file devices/vdml_imu.c + * + * Contains functions for interacting with the VEX Inertial sensor. + * + * Copyright (c) 2017-2019, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include "pros/distance.h" +#include "v5_api.h" +#include "vdml/registry.h" +#include "vdml/vdml.h" + +#define ERROR_DISTANCE_BAD_PORT(device, err_return) \ + if (!(vexDeviceDistanceStatusGet(device->device_info) == 0x82 || \ + vexDeviceDistanceStatusGet(device->device_info) == 0x86)) { \ + errno = EAGAIN; \ + return_port(port - 1, err_return); \ + } + +int32_t distance_get(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_DISTANCE); + ERROR_DISTANCE_BAD_PORT(device, PROS_ERR); + int32_t rtn = vexDeviceDistanceDistanceGet(device->device_info); + return_port(port - 1, rtn); +} + +int32_t distance_get_confidence(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_DISTANCE); + ERROR_DISTANCE_BAD_PORT(device, PROS_ERR); + int32_t rtn = vexDeviceDistanceConfidenceGet(device->device_info); + return_port(port - 1, rtn); +} + +int32_t distance_get_object_size(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_DISTANCE); + ERROR_DISTANCE_BAD_PORT(device, PROS_ERR); + int32_t rtn = vexDeviceDistanceObjectSizeGet(device->device_info); + return_port(port - 1, rtn); +} + +double distance_get_object_velocity(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_DISTANCE); + ERROR_DISTANCE_BAD_PORT(device, PROS_ERR); + double rtn = vexDeviceDistanceObjectVelocityGet(device->device_info); + return_port(port - 1, rtn); +} \ No newline at end of file diff --git a/src/devices/vdml_distance.cpp b/src/devices/vdml_distance.cpp new file mode 100644 index 000000000..bc2ae880b --- /dev/null +++ b/src/devices/vdml_distance.cpp @@ -0,0 +1,38 @@ +/** + * \file devices/vdml_distance.cpp + * + * Contains functions for interacting with the V5 ADI. + * + * Copyright (c) 2017-2020, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "pros/distance.hpp" + +namespace pros { + +Distance::Distance(const std::uint8_t port) : _port(port) {} + +std::int32_t Distance::get() { + return pros::c::distance_get(_port); +} + +std::int32_t Distance::get_confidence() { + return pros::c::distance_get_confidence(_port); +} + +std::int32_t Distance::get_object_size() { + return pros::c::distance_get_object_size(_port); +} + +double Distance::get_object_velocity() { + return pros::c::distance_get_object_velocity(_port); +} + +std::uint8_t Distance::get_port() { + return _port; +} +} // namespace pros \ No newline at end of file From 85b5dea06b900ec52592455a26f4d692454f8c52 Mon Sep 17 00:00:00 2001 From: Alex Brooke Date: Wed, 28 Oct 2020 22:57:28 -0400 Subject: [PATCH 3/5] =?UTF-8?q?=E2=9C=A8=20Add=20Support=20for=20the=20Rot?= =?UTF-8?q?ation=20Sensor=20(#258)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 5044d67dd2101d22ccc89b4b146c76b182689461 Author: WillXuCodes Date: Tue Oct 27 20:13:52 2020 -0400 Capitalize Rotation Sensor commit e7480bed9482d221628a6df6c034699280f89f93 Author: WillXuCodes Date: Tue Oct 27 19:15:28 2020 -0400 Fix documentation for rotation_reset. commit 878577890a743cc4d831737a3d3dcda4b987576e Author: WillXuCodes Date: Wed Oct 21 13:21:23 2020 -0400 Fixed documentation, removed periods, and used imperative tone. commit 066142e2c17087aee6ae59231a8dfbb3121f3d91 Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Wed Oct 21 02:12:12 2020 -0400 Update include/pros/rotation.h Co-authored-by: Alex Brooke commit 344709469ef4250db98b95d07e532cc67daa2ef1 Merge: 626a9be a696e72 Author: Will Xu Date: Tue Oct 20 09:29:21 2020 -0400 Merge branch 'feature/rotation-sensor' of https://github.com/purduesigbots/pros into feature/rotation-sensor commit 626a9be0174e694c95da4616a2dc08816ccbe029 Author: Will Xu Date: Tue Oct 20 09:27:35 2020 -0400 Added same reset documentation to C header commit 45445e62ca48ff8e60cea34e3f527688b310f8de Author: Will Xu Date: Tue Oct 20 09:27:03 2020 -0400 Added new documentation on reset function commit a696e722f05cf392c2ff21166d633bc4a1f170fe Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Tue Oct 20 09:24:44 2020 -0400 Update version commit 674cacffd30067308c2e059b0c2110a930347993 Author: Will Xu Date: Tue Oct 20 09:21:42 2020 -0400 Properly reverted version commit c5ce3de10042fd8e29bf3a5d2ddb6204d7f61ac6 Author: Will Xu Date: Tue Oct 20 09:19:07 2020 -0400 Revert version commit 4308a4dacd6ffe66e3e51809661175b4ce72fb68 Author: Will Xu Date: Tue Oct 20 09:18:06 2020 -0400 Revert accidental change in CPP file commit 312394da09cc8dd2a0adc503e2571117d4f5eae0 Author: Will Xu Date: Tue Oct 20 08:49:16 2020 -0400 Header documentation changes commit f93163fdd8823d892d68377b6398749bdea62372 Author: WillXuCodes Date: Sun Oct 18 23:36:26 2020 -0400 Added reverse functionality to C api. commit ab7d66f5d10240499652bcc8d4d28ac45f3d9aeb Author: WillXuCodes Date: Sun Oct 18 22:25:31 2020 -0400 Saved file properly commit 4b1b91db5e7891ea899b10e181885d4ff630869f Author: WillXuCodes Date: Sun Oct 18 22:19:09 2020 -0400 Fixed compilation error by reverting old change that wasn't cleanly taken out, changed reset_position in cpp to reflect the reset position in C. commit 20c6651d3eeda3d6356279f32e491db22743d217 Author: WillXuCodes Date: Sun Oct 18 21:50:14 2020 -0400 Added reset position functions to the rotation-sensor commit 20a559830c0198785f25ce849fcb08d27a448244 Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Fri Oct 16 17:15:50 2020 -0400 Update rotation.h commit e8a9cb3d6538f1a446926643718bca54f797ea54 Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Fri Oct 16 17:15:15 2020 -0400 Rotation.hpp documentation fixes commit 8b5bdd757c49df01aacf663ed631adfc870e5086 Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Fri Oct 16 17:10:40 2020 -0400 Rotation header documentation fixes commit ead6ce700fe85963b8dfaba497f23c58b5506351 Author: WillXuCodes Date: Wed Oct 14 01:09:33 2020 -0400 Fixed reverse(void) not working (earlier testing did not test it properly). commit eecf482bbb7ec8cac2b177e198734200e218d53a Author: Will Xu Date: Mon Oct 12 02:17:14 2020 -0400 Deleted extraneous newline commit b08b97d0fb9d8e307082b04294cbfb8d5bca9cd6 Author: Will Xu Date: Mon Oct 12 02:16:17 2020 -0400 Fixed documentation commit c7c8d06dbba2430173f09e349c54857055ad13a7 Author: Kunwar Sahni Date: Sun Oct 11 14:48:55 2020 -0400 Change to virtual commit df2f72e260dcaf861d5d18085eb134cbbe6fb447 Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Sat Oct 10 03:28:59 2020 -0400 Update version commit 7771dde1c3755417cc4ecb69e66123c52a9f151a Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Sat Oct 10 03:28:39 2020 -0400 Update version commit f8ea54746768cc4610f1166cd78d52f988425be4 Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Sat Oct 10 03:28:13 2020 -0400 Update version commit bd51044bf5b4af5dd445d19818711ab6c641f6b7 Author: Will Xu Date: Sat Oct 10 03:25:59 2020 -0400 Revert version commit 2b37525bd38bae301b1f17bc537056503ac960f6 Author: Will Xu Date: Sat Oct 10 03:24:43 2020 -0400 Finished documentation commit e1272be7bdd926e0e623451848a2863483dce249 Author: mooreBrendan Date: Fri Oct 9 18:41:50 2020 -0400 change get reversed to int32_t so that the error can be returned commit 0eb8a4f0bf4b238e12c9e0af3c3eb671a5952c85 Merge: 2918761 877680c Author: mooreBrendan Date: Fri Oct 9 18:33:44 2020 -0400 Merge branch 'feature/rotation-sensor' of https://github.com/purduesigbots/pros into feature/rotation-sensor commit 2918761541e2fd622a16b28b8c583f0431e60c47 Author: mooreBrendan Date: Fri Oct 9 18:32:33 2020 -0400 corrected return values in documentation commit 877680c4128874b3607a6dc28f48f07d116437c8 Author: WillXuCodes Date: Tue Oct 6 23:14:26 2020 -0400 Revert PROS_VERSION_PATCH commit 78760eeaaefa109c086e816baaefb69d0c49b12d Author: Will Xu Date: Tue Oct 6 17:30:15 2020 -0400 Revert Version commit 853f9bc80db43958dd5d5305296efe7193c942c6 Author: Will Xu Date: Tue Oct 6 16:31:02 2020 -0400 Documentation updates commit 7097a4528074c16f93f3a3a76cdfe5b02b7ff136 Author: Will Xu Date: Tue Oct 6 16:24:12 2020 -0400 Revert accidentally changed header for imu C file. commit 42ce52a6bf2f6f333fb1e1a98d639870f2216eee Author: Will Xu Date: Tue Oct 6 16:22:30 2020 -0400 Properly Reverted main.cpp commit 0be2e4a80737cee16cad4da01464f16694b1b947 Author: Will Xu Date: Tue Oct 6 16:17:37 2020 -0400 Reverted main.cpp, added rotation hpp file to api header, fixed issues with C file not returning proper value. TODO: Revert Version Value commit 64614ffb3913de7ad473bcf6712ff8527357ca90 Author: Will Xu Date: Sun Oct 4 02:06:24 2020 -0400 Added untracked files: commit fcb8d9cf2d786c95b0dbba58383a9ef4c81a962b Author: Will Xu Date: Sun Oct 4 02:05:40 2020 -0400 Finished cpp and hpp files, tested but didn't work. Also fixed wrong device type in C file. commit 717a838e501980f0baf0e4c03bc3d99d834cbabf Author: Will Xu Date: Sat Oct 3 21:05:58 2020 -0400 Finished up C file. commit 39fd11ec98a9fc3ced1b7807afc444c73031b1e8 Author: WillXuCodes Date: Wed Sep 30 20:38:18 2020 -0400 Started slightly with the rotation C file. commit 4db4b1bf662e490799fd4c00aa3204b743a576b1 Author: WillXuCodes Date: Tue Sep 29 18:44:01 2020 -0400 Added untracked file commit cf00b7fb5323e113f220a36ca4f08905930eaa79 Author: WillXuCodes Date: Tue Sep 29 18:43:45 2020 -0400 Finished header file for rotation sensor --- include/api.h | 2 + include/pros/apix.h | 1 + include/pros/rotation.h | 183 ++++++++++++++++++++++++++++++++++ include/pros/rotation.hpp | 165 ++++++++++++++++++++++++++++++ src/devices/vdml_rotation.c | 72 +++++++++++++ src/devices/vdml_rotation.cpp | 52 ++++++++++ 6 files changed, 475 insertions(+) create mode 100644 include/pros/rotation.h create mode 100644 include/pros/rotation.hpp create mode 100644 src/devices/vdml_rotation.c create mode 100644 src/devices/vdml_rotation.cpp diff --git a/include/api.h b/include/api.h index 066a6f1ce..76f032240 100644 --- a/include/api.h +++ b/include/api.h @@ -56,6 +56,7 @@ #include "pros/misc.h" #include "pros/motors.h" #include "pros/rtos.h" +#include "pros/rotation.h" #include "pros/vision.h" #ifdef __cplusplus @@ -65,6 +66,7 @@ #include "pros/llemu.hpp" #include "pros/misc.hpp" #include "pros/motors.hpp" +#include "pros/rotation.hpp" #include "pros/rtos.hpp" #include "pros/vision.hpp" #endif diff --git a/include/pros/apix.h b/include/pros/apix.h index b28ad815a..af59d40b5 100644 --- a/include/pros/apix.h +++ b/include/pros/apix.h @@ -369,6 +369,7 @@ void queue_reset(queue_t queue); typedef enum v5_device_e { E_DEVICE_NONE = 0, E_DEVICE_MOTOR = 2, + E_DEVICE_ROTATION = 4, E_DEVICE_IMU = 6, E_DEVICE_DISTANCE = 7, E_DEVICE_RADIO = 8, diff --git a/include/pros/rotation.h b/include/pros/rotation.h new file mode 100644 index 000000000..28c8e558e --- /dev/null +++ b/include/pros/rotation.h @@ -0,0 +1,183 @@ +/** + * \file pros/rotation.h + * + * Contains prototypes for functions related to the VEX Rotation Sensor. + * + * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/rotation.html to learn + * more. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * Copyright (c) 2017-2020, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef _PROS_ROTATION_H_ +#define _PROS_ROTATION_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +namespace pros { +namespace c { +#endif + +/** + * Reset Rotation Sensor + * + * Reset the current absolute position to be the same as the + * Rotation Sensor angle. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \param port + * The V5 Rotation Sensor port number from 1-21 + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ +int32_t rotation_reset(uint8_t port); + +/** + * Set the Rotation Sensor position reading to a desired rotation value + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \param port + * The V5 Rotation Sensor port number from 1-21 + * \param position + * The position in terms of ticks + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ +int32_t rotation_set_position(uint8_t port, uint32_t position); + +/** + * Reset the Rotation Sensor position to 0 + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \param port + * The V5 Rotation Sensor port number from 1-21 + + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ +int32_t rotation_reset_position(uint8_t port); + +/** + * Get the Rotation Sensor's current position in centidegrees + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \param port + * The V5 Rotation Sensor port number from 1-21 + * \return The position value or PROS_ERR_F if the operation failed, setting + * errno. + */ +int32_t rotation_get_position(uint8_t port); + +/** + * Get the Rotation Sensor's current velocity in centidegrees per second + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \param port + * The V5 Rotation Sensor port number from 1-21 + * \return The velocity value or PROS_ERR_F if the operation failed, setting + * errno. + */ +int32_t rotation_get_velocity(uint8_t port); + +/** + * Get the Rotation Sensor's current position in centidegrees + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \param port + * The V5 Rotation Sensor port number from 1-21 + * \return The angle value or PROS_ERR_F if the operation failed, setting + * errno. + */ +int32_t rotation_get_angle(uint8_t port); + +/** + * Set the Rotation Sensor's direction reversed flag + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \param port + * The V5 Rotation Sensor port number from 1-21 + * \param value + * Determines if the direction of the Rotation Sensor is reversed or not. + * + * \return 1 if operation succeeded or PROS_ERR if the operation failed, setting + * errno. + */ +int32_t rotation_set_reversed(uint8_t port, bool value); + +/** + * Reverse the Rotation Sensor's direction + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \param port + * The V5 Rotation Sensor port number from 1-21 + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ +int32_t rotation_reverse(uint8_t port); + +/** + * Get the Rotation Sensor's reversed flag + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \param port + * The V5 Rotation Sensor port number from 1-21 + * + * \return Boolean value of if the Rotation Sensor's direction is reversed or not + * or PROS_ERR if the operation failed, setting errno. + */ +int32_t rotation_get_reversed(uint8_t port); + +#ifdef __cplusplus +} //namespace C +} //namespace pros +} //extern "C" +#endif + +#endif diff --git a/include/pros/rotation.hpp b/include/pros/rotation.hpp new file mode 100644 index 000000000..58595f59c --- /dev/null +++ b/include/pros/rotation.hpp @@ -0,0 +1,165 @@ +/** + * \file pros/rotation.hpp + * + * Contains prototypes for functions related to the VEX Rotation Sensor. + * + * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/rotation.html to learn + * more. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * Copyright (c) 2017-2020, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +#ifndef _PROS_ROTATION_HPP_ +#define _PROS_ROTATION_HPP_ + +#include + +#include "pros/rotation.h" + +namespace pros { +class Rotation { + const std::uint8_t _port; + + public: + Rotation(const std::uint8_t port) : _port(port){}; + + /** + * Reset the Rotation Sensor + * + * Reset the current absolute position to be the same as the + * Rotation Sensor angle. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t reset(); + + /** + * Set the Rotation Sensor position reading to a desired rotation value + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \param position + * The position in terms of ticks + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_position(std::uint32_t position); + + /** + * Reset the Rotation Sensor to a desired rotation value + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \param position + * The position in terms of ticks + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t reset_position(void); + + /** + * Get the Rotation Sensor's current position in centidegrees + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \return The position value or PROS_ERR if the operation failed, setting + * errno. + */ + virtual std::int32_t get_position(); + + /** + * Get the Rotation Sensor's current velocity in centidegrees per second + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \param port + * The V5 Rotation Sensor port number from 1-21 + * \return The + value or PROS_ERR_F if the operation failed, setting + * errno. + */ + virtual std::int32_t get_velocity(); + + /** + * Get the Rotation Sensor's current position in centidegrees + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \return The angle value or PROS_ERR if the operation failed, setting + * errno. + */ + virtual std::int32_t get_angle(); + + /** + * Set the Rotation Sensor's direction reversed flag + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \param value + * Determines if the direction of the rotational sensor is + * reversed or not. + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t set_reversed(bool value); + + /** + * Reverse the Rotation Sensor's direction. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \return 1 if the operation was successful or PROS_ERR if the operation + * failed, setting errno. + */ + virtual std::int32_t reverse(); + + /** + * Get the Rotation Sensor's reversed flag + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Rotation Sensor + * + * \return Reversed value or PROS_ERR if the operation failed, setting + * errno. + */ + virtual std::int32_t get_reversed(); +}; +} // namespace pros + +#endif diff --git a/src/devices/vdml_rotation.c b/src/devices/vdml_rotation.c new file mode 100644 index 000000000..b76b3f440 --- /dev/null +++ b/src/devices/vdml_rotation.c @@ -0,0 +1,72 @@ +/** + * \file devices/vdml_rotation.c + * + * Contains functions for interacting with the VEX Rotation sensor. + * + * Copyright (c) 2017-2019, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include "pros/rotation.h" +#include "v5_api.h" +#include "vdml/registry.h" +#include "vdml/vdml.h" + +int32_t rotation_reset(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_ROTATION); + vexDeviceAbsEncReset(device->device_info); + return_port(port - 1, 1); +} + +int32_t rotation_reset_position(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_ROTATION); + vexDeviceAbsEncPositionSet(device->device_info, 0); + return_port(port - 1, 1); +} + +int32_t rotation_set_position(uint8_t port, uint32_t position) { + claim_port_i(port - 1, E_DEVICE_ROTATION); + vexDeviceAbsEncPositionSet(device->device_info, position); + return_port(port - 1, 1); +} + +int32_t rotation_get_position(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_ROTATION); + int32_t rtn = vexDeviceAbsEncPositionGet(device->device_info); + return_port(port - 1, rtn); +} + +int32_t rotation_get_velocity(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_ROTATION); + int32_t rtn = vexDeviceAbsEncVelocityGet(device->device_info); + return_port(port - 1, rtn); +} + +int32_t rotation_get_angle(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_ROTATION); + int32_t rtn = vexDeviceAbsEncAngleGet(device->device_info); + return_port(port - 1, rtn); +} + +int32_t rotation_set_reversed(uint8_t port, bool value) { + claim_port_i(port - 1, E_DEVICE_ROTATION); + vexDeviceAbsEncReverseFlagSet(device->device_info, value); + return_port(port - 1, 1); +} + +int32_t rotation_reverse(uint8_t port){ + claim_port_i(port - 1, E_DEVICE_ROTATION); + vexDeviceAbsEncReverseFlagSet(device->device_info, !vexDeviceAbsEncReverseFlagGet(device->device_info)); + return_port(port - 1, 1); +} + +int32_t rotation_get_reversed(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_ROTATION); + int32_t rtn = vexDeviceAbsEncReverseFlagGet(device->device_info); + return_port(port - 1, rtn); +} \ No newline at end of file diff --git a/src/devices/vdml_rotation.cpp b/src/devices/vdml_rotation.cpp new file mode 100644 index 000000000..dff0b3ba2 --- /dev/null +++ b/src/devices/vdml_rotation.cpp @@ -0,0 +1,52 @@ +/** + * \file devices/vdml_rotation.cpp + * + * Contains functions for interacting with the VEX Rotation sensor. + * + * Copyright (c) 2017-2019, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "pros/rotation.hpp" + +namespace pros { +std::int32_t Rotation::reset() { + return pros::c::rotation_reset(_port); +} + +std::int32_t Rotation::set_position(std::uint32_t position) { + return pros::c::rotation_set_position(_port, position); +} + +std::int32_t Rotation::reset_position(void) { + return pros::c::rotation_reset_position(_port); +} + +std::int32_t Rotation::get_position(void) { + return pros::c::rotation_get_position(_port); +} + +std::int32_t Rotation::get_velocity(void) { + return pros::c::rotation_get_velocity(_port); +} + +std::int32_t Rotation::get_angle(void) { + return pros::c::rotation_get_angle(_port); +} + +std::int32_t Rotation::set_reversed(bool value) { + return pros::c::rotation_set_reversed(_port, value); +} + +std::int32_t Rotation::reverse(void) { + return pros::c::rotation_reverse(_port); +} + +std::int32_t Rotation::get_reversed(void) { + return pros::c::rotation_get_reversed(_port); +} + +} // namespace pros From 2b96b87c0ca6e6d89c7a63d4bcfd6cdbcc92e004 Mon Sep 17 00:00:00 2001 From: Alex Brooke Date: Wed, 28 Oct 2020 22:59:43 -0400 Subject: [PATCH 4/5] =?UTF-8?q?=E2=9C=A8=20Add=20Support=20for=20Optical?= =?UTF-8?q?=20Sensor=20(#259)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit f8364d01d03ed6e6b340c67e06f5b7a4c08f4b33 Merge: a19c090 74c385f Author: Alex Brooke Date: Tue Oct 27 22:26:05 2020 -0400 Merge branch 'develop' into feature/optical-sensor commit a19c09007293523c7c12e02e0e7ee339d784c22a Merge: 0da4047 5b0269c Author: Kunwar Sahni Date: Tue Oct 27 21:06:46 2020 -0400 Merge remote-tracking branch 'purduesigbots/feature/optical-sensor' into feature/optical-sensor commit 0da40474feb30f53bcf1eba1174628cf7530a6d2 Author: Kunwar Sahni Date: Tue Oct 27 21:06:40 2020 -0400 Remove comment commit 5b0269c2a6eb11de6854331b408d595961b8aa25 Author: Kunwar Sahni Date: Tue Oct 27 21:05:15 2020 -0400 Update include/pros/optical.h Co-authored-by: Alex Brooke commit 1461d03070e7cb1b70b14090a528e43b310b21df Author: Kunwar Sahni Date: Tue Oct 27 21:01:30 2020 -0400 Editing comments commit 74c385fde950dac923279bba8ccc67d68da65f1a Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Tue Oct 27 20:18:57 2020 -0400 ✨ Add Support for the Rotation Sensor (#258) * Finished header file for rotation sensor * Added untracked file * Started slightly with the rotation C file. * Finished up C file. * Finished cpp and hpp files, tested but didn't work. Also fixed wrong device type in C file. * Added untracked files: * Reverted main.cpp, added rotation hpp file to api header, fixed issues with C file not returning proper value. TODO: Revert Version Value * Properly Reverted main.cpp * Revert accidentally changed header for imu C file. * Documentation updates * Revert Version * Revert PROS_VERSION_PATCH * corrected return values in documentation * change get reversed to int32_t so that the error can be returned * Finished documentation * Revert version * Update version * Update version * Update version * Change to virtual * Fixed documentation * Deleted extraneous newline * Fixed reverse(void) not working (earlier testing did not test it properly). * Rotation header documentation fixes * Rotation.hpp documentation fixes * Update rotation.h * Added reset position functions to the rotation-sensor * Fixed compilation error by reverting old change that wasn't cleanly taken out, changed reset_position in cpp to reflect the reset position in C. * Saved file properly * Added reverse functionality to C api. * Header documentation changes * Revert accidental change in CPP file * Revert version * Properly reverted version * Update version * Added new documentation on reset function * Added same reset documentation to C header * Update include/pros/rotation.h Co-authored-by: Alex Brooke * Fixed documentation, removed periods, and used imperative tone. * Fix documentation for rotation_reset. * Capitalize Rotation Sensor Co-authored-by: WillXuCodes Co-authored-by: mooreBrendan Co-authored-by: Kunwar Sahni Co-authored-by: Alex Brooke commit 355b567975878f6ebd7b531c53c958ad34e6d540 Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Tue Oct 27 20:17:16 2020 -0400 Update include/pros/optical.hpp Co-authored-by: Alex Brooke commit 330e3fe6c30b3229e764d67898575004119a376b Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Tue Oct 27 20:17:05 2020 -0400 Update include/pros/optical.hpp Co-authored-by: Alex Brooke commit 55efaf4d10485bafdbcca00b465a3542ddf1b15a Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Tue Oct 27 20:16:43 2020 -0400 Update include/pros/optical.hpp Co-authored-by: Alex Brooke commit 76758af63b614bbe0bd48b877e3f9782ea515b96 Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Tue Oct 27 20:16:24 2020 -0400 Update include/pros/optical.hpp Co-authored-by: Alex Brooke commit 95f5e81898d76f165587adebb9644cd67c9bba1e Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Tue Oct 27 20:16:14 2020 -0400 Update include/pros/optical.h Co-authored-by: Alex Brooke commit c2425dcd98d8b851c651b486393e20296761536a Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Tue Oct 27 20:15:44 2020 -0400 Update include/pros/optical.h Co-authored-by: Alex Brooke commit fa281b4af621dfb241193502ae5233af07bbb046 Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Tue Oct 27 20:14:35 2020 -0400 Update include/pros/optical.h Co-authored-by: Alex Brooke commit 493f5d1a6d32da9323ed200a353d981dd5b8f450 Author: Will Xu <54247087+WillXuCodes@users.noreply.github.com> Date: Tue Oct 27 20:14:25 2020 -0400 Update include/pros/optical.h Co-authored-by: Alex Brooke commit a35f6a4ae331cd545c4bebc4297f3d9b4c201d4e Author: mooreBrendan Date: Thu Oct 22 00:16:44 2020 -0400 fixed return value documentation commit b8d64fb32ce273165452f3126f46dcd69330f2e9 Merge: 8ecc51e 5a66cee Author: Kunwar Sahni Date: Tue Oct 20 08:48:42 2020 -0400 Merge pull request #257 from purduesigbots/feature/distance-sensor ✨ Add Support for the Distance Sensor commit 5a66cee62c5920d1440d174c63de6fc41f8c63c1 Author: Kunwar Sahni Date: Sun Oct 11 14:47:42 2020 -0400 Change to virtual commit 1c578778b0ede0b49a4a0837b87b0c78f655e8fa Author: Kunwar Sahni Date: Sun Oct 11 14:44:24 2020 -0400 Change to virtual commit 113abf98d4156099ef003f332f80803dc9bfe1e6 Author: Kunwar Sahni Date: Fri Oct 9 17:22:03 2020 -0400 Fix version commit 7e44d38643d6f57b6a5d6220f0d3cedb70ed4998 Author: Kunwar Sahni Date: Fri Oct 9 17:17:12 2020 -0400 Change err init commit b1c5131e31decfc21c2cd8aec74167e6790c8932 Author: Kunwar Sahni Date: Fri Oct 9 17:03:25 2020 -0400 Change enum back commit 0e277a02946aa124a217d9ed924b5623f4cd9139 Author: Kunwar Sahni Date: Fri Oct 9 16:59:10 2020 -0400 Lowercase enum commit 4b287c3b9c290a9a29b93fe391768322afe95925 Author: Kunwar Sahni Date: Fri Oct 9 16:56:54 2020 -0400 Formatting commit ac9b3f0f7004f09e32ab4f8d575531328ee588eb Author: Kunwar Sahni Date: Fri Oct 9 16:22:12 2020 -0400 Fix gesture disable commit fed36f6e2800d1e4a5643a6235c23cdf67998c4b Author: Will Xu Date: Fri Oct 9 11:26:03 2020 -0400 Revert main.cpp commit f0a8e0940ca2bbb4a1da4c9188e1be397f6168cd Author: Will Xu Date: Fri Oct 9 11:24:01 2020 -0400 Revert Version commit a60ce46c5fef9df31a8182dbce215518524b06b7 Author: Will Xu Date: Fri Oct 9 00:59:15 2020 -0400 Fixed up last of optical sensor errors by changing a function to the device sdk function. commit d75c68764d67a66ed74e1aaa760213ca5ee00b75 Author: Will Xu Date: Thu Oct 8 03:49:08 2020 -0400 Added new error system for optical sensor, cleaned up mutex related warnings by using claim_port instead of claim_port_i. (NOTE: I am aware this code may not compile, but I have no clue what I changed to make it stop compiling since a previous warning has now turned into an error for some reason :/) commit 803bf93b94207a880f15903fe4118c8fa55aca30 Author: mooreBrendan Date: Tue Oct 6 16:46:16 2020 -0400 changed get_size to int32_t in c++ commit af6768b2621c31a1bbcad30ffe81533c4cc7dc06 Author: Kunwar Sahni Date: Tue Oct 6 11:11:47 2020 -0400 Remove new line commit c46b79448ab417211c9684e69b7e7c12048e856d Author: Kunwar Sahni Date: Tue Oct 6 11:04:37 2020 -0400 Apply suggestions from code review Co-authored-by: Alex Brooke commit d39dd9961d8b55c5974dddefd0dec794d208f8c7 Author: mooreBrendan Date: Tue Oct 6 00:19:47 2020 -0400 fixed int32_t library inclusion, and added std:: commit 7e94cfd1e776f8254f3eff28fdd9319b47826be6 Author: Kunwar Sahni Date: Sat Oct 3 17:59:53 2020 -0400 Add confidence documentation commit ee2e87ffd1fefb6063cb009ab12be1ea1fe364ec Author: Kunwar Sahni Date: Sat Oct 3 14:00:17 2020 -0400 Change to device sdk function commit db589a9cc2fd8413e9c218e0d5c12459d8586dd3 Merge: 6c91e5d ad938e5 Author: WillXuCodes Date: Sat Oct 3 01:19:19 2020 -0400 Merge branch 'feature/distance-sensor' of https://github.com/purduesigbots/pros into feature/distance-sensor commit 6c91e5dc217a25d8ceb4ff29dd44d66ae5d3fc80 Author: WillXuCodes Date: Sat Oct 3 01:14:10 2020 -0400 Fixed bad macro and extraneous newline commit ad938e5c357bc979c87bf305e8d77035f175f5de Author: Kunwar Sahni Date: Fri Oct 2 19:52:04 2020 -0400 Fix Formatting issues commit bb2c816c705a9fbc09446241ea09ca3bf68c23e3 Author: Kunwar Sahni Date: Fri Oct 2 19:45:30 2020 -0400 Apply suggestions from code review Co-authored-by: Alex Brooke commit 3bc747e2f2aa0ac24c08cfb0794ecdfb65c1f5a5 Author: Kunwar Sahni Date: Fri Oct 2 19:44:54 2020 -0400 Update include/pros/distance.h Co-authored-by: Alex Brooke commit 6684e6ed3b3d1a7c77118b6ace410d8c7be8f47e Author: Kunwar Sahni Date: Fri Oct 2 19:44:33 2020 -0400 Update include/pros/distance.h Co-authored-by: Alex Brooke commit 7872b50c8fe7c517c9e8a4827277f6cd11ade812 Author: Kunwar Sahni Date: Fri Oct 2 19:44:22 2020 -0400 Update include/pros/distance.h Co-authored-by: Alex Brooke commit 19d032a6cee9c700f7cf81e44cc5ff88349634cb Author: Kunwar Sahni Date: Fri Oct 2 19:44:12 2020 -0400 Update include/pros/distance.h Co-authored-by: Alex Brooke commit 050ec1598bb824f4cd91c254fd69ecb8fd1f1629 Author: Kunwar Sahni Date: Fri Oct 2 18:12:33 2020 -0400 Change to Device over index commit 7ad19a2f6ab088c47f222debad3f58bc4fc21f54 Author: WillXuCodes Date: Tue Sep 29 18:16:35 2020 -0400 Saved file commit cfd8e38fd25846e71039aba7af64cc0fafb2dcfd Author: WillXuCodes Date: Tue Sep 29 18:15:11 2020 -0400 Removed unnecessary using namespace pros::c from cpp file. commit 7e73e49ca12a90ec0b23ef987ba8cdf9207c7c0c Author: WillXuCodes Date: Tue Sep 29 18:04:46 2020 -0400 Added std:: to cpp files, and return types in the cpp files themselves. commit 72b801686b915c2ebebb9fc771e5ea753afb2907 Author: WillXuCodes Date: Tue Sep 29 17:56:02 2020 -0400 Added missing semi colon commit 5fa435caa3ee7e79c4c9d81f33ecc8c6afba2326 Author: WillXuCodes Date: Tue Sep 29 17:50:08 2020 -0400 Fixed error handling function commit e2f474f73829c843d6fe3f239e7956b07d74993c Author: WillXuCodes Date: Tue Sep 29 17:35:00 2020 -0400 Added optical sensor header files to api.h commit b15afafa620e6ddee80c74ca8b194f4c946d0ebb Author: WillXuCodes Date: Tue Sep 29 17:28:48 2020 -0400 Added distance header files to api header. commit bdef884978e3d3cfd453fb9ea5ca55a818803e82 Author: WillXuCodes Date: Fri Sep 25 23:08:04 2020 -0400 Deleted unnecesary old comment regarding adding error handling commit 27f3b9801f02ac7db4192946ce78228f9e8380fd Author: mooreBrendan Date: Fri Sep 25 19:29:55 2020 -0400 removed optical_ from c++ files commit f4d8f53871701fa12acb815547b8c50570cf2b25 Author: mooreBrendan Date: Fri Sep 25 19:24:40 2020 -0400 added the cpp file for the distance sensor and reverted main commit 0868c74ccbfd99bdcfe57e1b3c6da0c55aeb19a0 Author: mooreBrendan Date: Fri Sep 25 19:06:45 2020 -0400 Added cpp file for optical sensor commit 7f66e9f04e7637ca3754ae430d045c20e7df0b1c Author: mooreBrendan Date: Fri Sep 25 18:48:29 2020 -0400 added optical hpp file commit dda2bbfbd96384f95f0c7db7fa6ea02358d0bfd0 Author: WillXuCodes Date: Fri Sep 25 18:29:42 2020 -0400 Added bad port or device error handling (Needs review) commit 3e1b6cd79838e1412047b34d6783b8582762cecc Author: Kunwar Sahni Date: Fri Sep 25 18:13:52 2020 -0400 Add gesture_raw and enum commit fd2a4e2fe0f78b9912948bfb2754d877ed03f1c0 Merge: 0a3d5f9 bfc5a35 Author: WillXuCodes Date: Fri Sep 25 18:11:31 2020 -0400 Merge branch 'feature/distance-sensor' of https://github.com/purduesigbots/pros into feature/distance-sensor commit 0a3d5f9ff53eaad9f112c088b6c2408035329437 Author: WillXuCodes Date: Fri Sep 25 18:00:00 2020 -0400 Added distance sensor to device type enum, also started C file for distance sensor. commit bfc5a3555d357ecbfec87e01f104edbec7c12cc4 Author: mooreBrendan Date: Fri Sep 25 17:58:49 2020 -0400 fixed the #ifndef in hpp file commit a07f393003b32ce4d5f9f339df9c1fef61fbd653 Author: mooreBrendan Date: Fri Sep 25 17:55:20 2020 -0400 added distance.hpp commit 3f1fbc6116563c6c2a7769cc69f54450ccd9b786 Author: Kunwar Sahni Date: Fri Sep 25 16:18:02 2020 -0400 Fix void functions commit b9bbeb95142d4c9b661fbb308c6fe0a3e89a6199 Author: Kunwar Sahni Date: Fri Sep 25 16:03:23 2020 -0400 Fix vdml_optical.c commit 630b9bd1f91d251fee87f513e5aff9eb07833aa2 Author: Kunwar Sahni Date: Fri Sep 25 16:01:44 2020 -0400 Add vdml_optical.c commit 27ff3c196836cf2afb93f754ec934aa83544f52e Author: Kunwar Sahni Date: Fri Sep 25 14:59:35 2020 -0400 Fix Comments and set_pwm commit 198f16185509031c7420181dda77a02a13f0c7fc Author: Kunwar Sahni Date: Fri Sep 25 14:54:05 2020 -0400 Add Optical Header commit 2ee04ea37b3b718cd0e049eb3f74d2e03371bacb Author: Kunwar Sahni Date: Fri Sep 25 11:40:51 2020 -0400 Add get confidence commit 0913f1ad71bddc5ade990d70784be0204a62f4d4 Author: Kunwar Sahni Date: Fri Sep 25 11:29:03 2020 -0400 Add Distance Header --- include/api.h | 2 + include/pros/apix.h | 1 + include/pros/optical.h | 267 +++++++++++++++++++++++++++++++++++ include/pros/optical.hpp | 234 ++++++++++++++++++++++++++++++ src/devices/vdml_optical.c | 136 ++++++++++++++++++ src/devices/vdml_optical.cpp | 71 ++++++++++ 6 files changed, 711 insertions(+) create mode 100644 include/pros/optical.h create mode 100644 include/pros/optical.hpp create mode 100644 src/devices/vdml_optical.c create mode 100644 src/devices/vdml_optical.cpp diff --git a/include/api.h b/include/api.h index 76f032240..91e31eff1 100644 --- a/include/api.h +++ b/include/api.h @@ -55,6 +55,7 @@ #include "pros/llemu.h" #include "pros/misc.h" #include "pros/motors.h" +#include "pros/optical.h" #include "pros/rtos.h" #include "pros/rotation.h" #include "pros/vision.h" @@ -66,6 +67,7 @@ #include "pros/llemu.hpp" #include "pros/misc.hpp" #include "pros/motors.hpp" +#include "pros/optical.hpp" #include "pros/rotation.hpp" #include "pros/rtos.hpp" #include "pros/vision.hpp" diff --git a/include/pros/apix.h b/include/pros/apix.h index af59d40b5..71146ada8 100644 --- a/include/pros/apix.h +++ b/include/pros/apix.h @@ -375,6 +375,7 @@ typedef enum v5_device_e { E_DEVICE_RADIO = 8, E_DEVICE_VISION = 11, E_DEVICE_ADI = 12, + E_DEVICE_OPTICAL = 16, E_DEVICE_GENERIC = 129, E_DEVICE_UNDEFINED = 255 } v5_device_e_t; diff --git a/include/pros/optical.h b/include/pros/optical.h new file mode 100644 index 000000000..18bacff71 --- /dev/null +++ b/include/pros/optical.h @@ -0,0 +1,267 @@ +/** + * \file pros/optical.h + * + * Contains prototypes for functions related to the VEX Optical sensor. + * + * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/imu.html to learn + * more. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * Copyright (c) 2017-2020, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef _PROS_OPTICAL_H_ +#define _PROS_OPTICAL_H_ + +#include +#include +#include "api.h" + +#define OPT_GESTURE_ERR (INT8_MAX) +#define OPT_COUNT_ERR (INT16_MAX) +#define OPT_TIME_ERR PROS_ERR + +#ifdef __cplusplus +extern "C" { +namespace pros { +namespace c { +#endif + + +typedef enum optical_direction_e { NO_GESTURE = 0, UP = 1, DOWN = 2, RIGHT = 3, LEFT = 4, ERROR = PROS_ERR } optical_direction_e_t; + +typedef struct optical_rgb_s { + double red; + double green; + double blue; + double brightness; +} optical_rgb_s_t; + +typedef struct optical_raw_s { + uint32_t clear; + uint32_t red; + uint32_t green; + uint32_t blue; +} optical_raw_s_t; + +typedef struct optical_gesture_s { + uint8_t udata; + uint8_t ddata; + uint8_t ldata; + uint8_t rdata; + uint8_t type; + uint8_t pad; + uint16_t count; + uint32_t time; +} optical_gesture_s_t; + +/** + * Get the detected color hue + * + * This is not available if gestures are being detected. Hue has a + * range of 0 to 359.999 + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \param port + * The V5 Optical Sensor port number from 1-21 + * \return hue value if the operation was successful or PROS_ERR_F if the operation + * failed, setting errno. + */ +double optical_get_hue(uint8_t port); + +/** + * Get the detected color saturation + * + * This is not available if gestures are being detected. Saturation has a + * range of 0 to 1.0 + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \param port + * The V5 Optical Sensor port number from 1-21 + * \return saturation value if the operation was successful or PROS_ERR_F if + * the operation failed, setting errno. + */ +double optical_get_saturation(uint8_t port); + +/** + * Get the detected color brightness + * + * This is not available if gestures are being detected. Brightness has a + * range of 0 to 1.0 + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \param port + * The V5 Optical Sensor port number from 1-21 + * \return brightness value if the operation was successful or PROS_ERR_F if + * the operation failed, setting errno. + */ +double optical_get_brightness(uint8_t port); + +/** + * Get the detected proximity value + * + * This is not available if gestures are being detected. proximity has + * a range of 0 to 255. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \param port + * The V5 Optical Sensor port number from 1-21 + * \return poximity value if the operation was successful or PROS_ERR if + * the operation failed, setting errno. + */ +int32_t optical_get_proximity(uint8_t port); + +/** + * Set the pwm value of the White LED + * + * value that ranges from 0 to 100 + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \param port + * The V5 Optical Sensor port number from 1-21 + * \return 1 if the operation is successful or PROS_ERR if the operation failed, + * setting errno. + */ +int32_t optical_set_led_pwm(uint8_t port, uint8_t value); + +/** + * Get the pwm value of the White LED + * + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \param port + * The V5 Optical Sensor port number from 1-21 + * \return LED pwm value that ranges from 0 to 100 if the operation was + * successful or PROS_ERR if the operation failed, setting errno. + */ +int32_t optical_get_led_pwm(uint8_t port); + +/** + * Get the processed RGBC data from the sensor + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \param port + * The V5 Optical Sensor port number from 1-21 + * \return rgb value if the operation was successful or an optical_rgb_s_t with + * all fields set to PROS_ERR if the operation failed, setting errno. + */ +optical_rgb_s_t optical_get_rgb(uint8_t port); + +/** + * Get the raw, unprocessed RGBC data from the sensor + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \param port + * The V5 Optical Sensor port number from 1-21 + * \return raw rgb value if the operation was successful or an optical_raw_s_t + * with all fields set to PROS_ERR if the operation failed, setting errno. + */ +optical_raw_s_t optical_get_raw(uint8_t port); + +/** + * Get the most recent gesture data from the sensor + * + * Gestures will be cleared after 500mS + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \param port + * The V5 Optical Sensor port number from 1-21 + * \return gesture value if the operation was successful or PROS_ERR if + * the operation failed, setting errno. + */ +optical_direction_e_t optical_get_gesture(uint8_t port); + +/** + * Get the most recent raw gesture data from the sensor + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \param port + * The V5 Optical Sensor port number from 1-21 + * \return gesture value if the operation was successful or an optical_gesture_s_t + * with all fields set to PROS_ERR if the operation failed, setting errno. + */ +optical_gesture_s_t optical_get_gesture_raw(uint8_t port); + +/** + * Enable gesture detection on the sensor + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \param port + * The V5 Optical Sensor port number from 1-21 + * \return 1 if the operation is successful or PROS_ERR if the operation failed, + * setting errno. + */ +int32_t optical_enable_gesture(uint8_t port); + +/** + * Disable gesture detection on the sensor + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \param port + * The V5 Optical Sensor port number from 1-21 + * \return 1 if the operation is successful or PROS_ERR if the operation failed, + * setting errno. + */ +int32_t optical_disable_gesture(uint8_t port); + +#ifdef __cplusplus +} +} +} +#endif + +#endif diff --git a/include/pros/optical.hpp b/include/pros/optical.hpp new file mode 100644 index 000000000..4b3c39da4 --- /dev/null +++ b/include/pros/optical.hpp @@ -0,0 +1,234 @@ +/** + * \file pros/optical.hpp + * + * Contains prototypes for functions related to the VEX Optical sensor. + * + * Visit https://pros.cs.purdue.edu/v5/tutorials/topical/imu.html to learn + * more. + * + * This file should not be modified by users, since it gets replaced whenever + * a kernel upgrade occurs. + * + * Copyright (c) 2017-2020, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef _PROS_OPTICAL_HPP_ +#define _PROS_OPTICAL_HPP_ + +#include + +#include + +#include "pros/optical.h" + +namespace pros { +class Optical { + public: + /** + * Creates an Optical Sensor object for the given port. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \param port + * The V5 port number from 1-21 + */ + explicit Optical(const std::uint8_t port); + + /** + * Get the detected color hue + * + * This is not available if gestures are being detected. Hue has a + * range of 0 to 359.999 + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \return hue value if the operation was successful or PROS_ERR_F if the operation + * failed, setting errno. + */ + virtual double get_hue(); + + /** + * Get the detected color saturation + * + * This is not available if gestures are being detected. Saturation has a + * range of 0 to 1.0 + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \return saturation value if the operation was successful or PROS_ERR_F if + * the operation failed, setting errno. + */ + virtual double get_saturation(); + + /** + * Get the detected color brightness + * + * This is not available if gestures are being detected. Brightness has a + * range of 0 to 1.0 + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \return brightness value if the operation was successful or PROS_ERR_F if + * the operation failed, setting errno. + */ + virtual double get_brightness(); + + /** + * Get the detected proximity value + * + * This is not available if gestures are being detected. proximity has + * a range of 0 to 255. + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \return poximity value if the operation was successful or PROS_ERR if + * the operation failed, setting errno. + */ + virtual std::int32_t get_proximity(); + + /** + * Set the pwm value of the White LED on the sensor + * + * value that ranges from 0 to 100 + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \return The Error code encountered + */ + virtual std::int32_t set_led_pwm(uint8_t value); + + /** + * Get the pwm value of the White LED on the sensor + * + * value that ranges from 0 to 100 + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \return LED pwm value if the operation was successful or PROS_ERR if + * the operation failed, setting errno. + */ + virtual std::int32_t get_led_pwm(); + + /** + * Get the processed RGBC data from the sensor + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \return rgb value if the operation was successful or an optical_rgb_s_t + * with all fields set to PROS_ERR if the operation failed, setting errno. + */ + virtual pros::c::optical_rgb_s_t get_rgb(); + + /** + * Get the raw un-processed RGBC data from the sensor + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \return raw rgb value if the operation was successful or an optical_raw_s_t + * with all fields set to PROS_ERR if the operation failed, setting errno. + */ + virtual pros::c::optical_raw_s_t get_raw(); + + /** + * Get the most recent gesture data from the sensor + * + * Gestures will be cleared after 500mS + * 0 = no gesture + * 1 = up (towards cable) + * 2 = down + * 3 = right + * 4 = left + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \return gesture value if the operation was successful or PROS_ERR if + * the operation failed, setting errno. + */ + virtual pros::c::optical_direction_e_t get_gesture(); + + /** + * Get the most recent raw gesture data from the sensor + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \return gesture value if the operation was successful or an optical_gesture_s_t + * with all fields set to PROS_ERR if the operation failed, setting errno. + */ + virtual pros::c::optical_gesture_s_t get_gesture_raw(); + + /** + * Enable gesture detection on the sensor + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \return 1 if the operation is successful or PROS_ERR if the operation failed, + * setting errno. + */ + virtual std::int32_t enable_gesture(); + + /** + * Disable gesture detection on the sensor + * + * This function uses the following values of errno when an error state is + * reached: + * ENXIO - The given value is not within the range of V5 ports (1-21). + * ENODEV - The port cannot be configured as an Optical Sensor + * + * \return 1 if the operation is successful or PROS_ERR if the operation failed, + * setting errno. + */ + virtual std::int32_t disable_gesture(); + + /** + * Gets the port number of the Optical Sensor. + * + * \return The Optical Sensor's port number. + */ + virtual std::uint8_t get_port(); + + private: + const std::uint8_t _port; +}; +} // namespace pros + +#endif diff --git a/src/devices/vdml_optical.c b/src/devices/vdml_optical.c new file mode 100644 index 000000000..5153fd315 --- /dev/null +++ b/src/devices/vdml_optical.c @@ -0,0 +1,136 @@ +/** + * \file devices/vdml_imu.c + * + * Contains functions for interacting with the VEX Inertial sensor. + * + * Copyright (c) 2017-2019, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include "pros/optical.h" +#include "v5_api.h" +#include "vdml/registry.h" +#include "vdml/vdml.h" + +double optical_get_hue(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_OPTICAL); + double rtn = vexDeviceOpticalHueGet(device->device_info); + return_port(port - 1, rtn); +} + +double optical_get_saturation(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_OPTICAL); + double rtn = vexDeviceOpticalSatGet(device->device_info); + return_port(port - 1, rtn); +} + +double optical_get_brightness(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_OPTICAL); + double rtn = vexDeviceOpticalBrightnessGet(device->device_info); + return_port(port - 1, rtn); +} + +int32_t optical_get_proximity(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_OPTICAL); + double rtn = vexDeviceOpticalProximityGet(device->device_info); + return_port(port - 1, rtn); +} + +int32_t optical_set_led_pwm(uint8_t port, uint8_t value) { + claim_port_i(port - 1, E_DEVICE_OPTICAL); + vexDeviceOpticalLedPwmSet(device->device_info, value); + return_port(port - 1, 1); +} + +int32_t optical_get_led_pwm(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_OPTICAL); + int32_t rtn = vexDeviceOpticalLedPwmGet(device->device_info); + return_port(port - 1, rtn); +} + +#define RGB_ERR_INIT \ + { .red = PROS_ERR_F, .green = PROS_ERR_F, .blue = PROS_ERR_F, .brightness = PROS_ERR_F } + +optical_rgb_s_t optical_get_rgb(uint8_t port) { + optical_rgb_s_t rtn = RGB_ERR_INIT; + v5_smart_device_s_t* device; + if (!claim_port_try(port - 1, E_DEVICE_OPTICAL)) { + return rtn; + } + device = registry_get_device(port - 1); + V5_DeviceOpticalRgb rgb; + vexDeviceOpticalRgbGet(device->device_info, &rgb); + rtn.red = rgb.red; + rtn.green = rgb.green; + rtn.blue = rgb.blue; + rtn.brightness = rgb.brightness; + return_port(port - 1, rtn); +} + +#define RAW_ERR_INIT \ + { .clear = PROS_ERR, .red = PROS_ERR, .green = PROS_ERR, .blue = PROS_ERR } + +optical_raw_s_t optical_get_raw(uint8_t port) { + optical_raw_s_t rtn = RAW_ERR_INIT; + v5_smart_device_s_t* device; + if (!claim_port_try(port - 1, E_DEVICE_OPTICAL)) { + return rtn; + } + device = registry_get_device(port - 1); + V5_DeviceOpticalRaw rgb; + vexDeviceOpticalRawGet(device->device_info, &rgb); + rtn.clear = rgb.clear; + rtn.red = rgb.red; + rtn.green = rgb.green; + rtn.blue = rgb.blue; + return_port(port - 1, rtn); +} + +optical_direction_e_t optical_get_gesture(uint8_t port) { + claim_port(port - 1, E_DEVICE_OPTICAL, OPT_GESTURE_ERR); + optical_direction_e_t rtn = vexDeviceOpticalGestureGet(device->device_info, NULL); + return_port(port - 1, rtn); +} + +#define GESTURE_ERR_INIT \ + { \ + .udata = OPT_GESTURE_ERR, .ddata = OPT_GESTURE_ERR, .ldata = OPT_GESTURE_ERR, .rdata = OPT_GESTURE_ERR, \ + .type = OPT_GESTURE_ERR, .pad = OPT_GESTURE_ERR, .count = OPT_COUNT_ERR, .time = OPT_TIME_ERR \ + } + +optical_gesture_s_t optical_get_gesture_raw(uint8_t port) { + optical_gesture_s_t rtn = GESTURE_ERR_INIT; + v5_smart_device_s_t* device; + if (!claim_port_try(port - 1, E_DEVICE_OPTICAL)) { + return rtn; + } + device = registry_get_device(port - 1); + V5_DeviceOpticalGesture gesture; + vexDeviceOpticalGestureGet(device->device_info, &gesture); + rtn.udata = gesture.udata; + rtn.ddata = gesture.ddata; + rtn.ldata = gesture.ldata; + rtn.rdata = gesture.rdata; + rtn.type = gesture.type; + rtn.pad = gesture.pad; + rtn.count = gesture.count; + rtn.time = gesture.time; + return_port(port - 1, rtn); +} + +int32_t optical_enable_gesture(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_OPTICAL); + vexDeviceOpticalGestureEnable(device->device_info); + return_port(port - 1, 1); +} + +int32_t optical_disable_gesture(uint8_t port) { + claim_port_i(port - 1, E_DEVICE_OPTICAL); + vexDeviceOpticalGestureDisable(device->device_info); + return_port(port - 1, 1); +} diff --git a/src/devices/vdml_optical.cpp b/src/devices/vdml_optical.cpp new file mode 100644 index 000000000..b5c5ad9e3 --- /dev/null +++ b/src/devices/vdml_optical.cpp @@ -0,0 +1,71 @@ +/** + * \file devices/vdml_optical.cpp + * + * Contains functions for interacting with the VEX Inertial sensor. + * + * Copyright (c) 2017-2019, Purdue University ACM SIGBots. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "pros/optical.hpp" + +namespace pros { +using namespace pros::c; + +Optical::Optical(std::uint8_t port): _port(port){} + +double Optical::get_hue(){ + return optical_get_hue(_port); +} + +double Optical::get_saturation(){ + return optical_get_saturation(_port); +} + +double Optical::get_brightness(){ + return optical_get_brightness(_port); +} + +std::int32_t Optical::get_proximity(){ + return optical_get_proximity(_port); +} + +std::int32_t Optical::set_led_pwm(std::uint8_t value){ + return optical_set_led_pwm(_port, value); +} + +std::int32_t Optical::get_led_pwm(){ + return optical_get_led_pwm(_port); +} + +optical_rgb_s_t Optical::get_rgb(){ + return optical_get_rgb(_port); +} + +optical_raw_s_t Optical::get_raw(){ + return optical_get_raw(_port); +} + +optical_direction_e_t Optical::get_gesture(){ + return optical_get_gesture(_port); +} + +optical_gesture_s_t Optical::get_gesture_raw(){ + return optical_get_gesture_raw(_port); +} + +std::int32_t Optical::enable_gesture(){ + return optical_enable_gesture(_port); +} + +std::int32_t Optical::disable_gesture(){ + return optical_disable_gesture(_port); +} + +std::uint8_t Optical::get_port(){ + return _port; +} +} \ No newline at end of file From 4be77c6385dc2ea57d9157b4f4453543436d737a Mon Sep 17 00:00:00 2001 From: WillXuCodes Date: Wed, 28 Oct 2020 23:21:12 -0400 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=94=96Bump=20to=203.3.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/api.h | 4 ++-- version | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/api.h b/include/api.h index 91e31eff1..70af8173d 100644 --- a/include/api.h +++ b/include/api.h @@ -41,8 +41,8 @@ #define PROS_VERSION_MAJOR 3 #define PROS_VERSION_MINOR 3 -#define PROS_VERSION_PATCH 0 -#define PROS_VERSION_STRING "3.3.0" +#define PROS_VERSION_PATCH 1 +#define PROS_VERSION_STRING "3.3.1" #define PROS_ERR (INT32_MAX) #define PROS_ERR_F (INFINITY) diff --git a/version b/version index 15a279981..bea438e9a 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.3.0 +3.3.1