Uploading the first files
This commit is contained in:
commit
eab3a5dd48
356 files changed
+78694
No files matched your search
File diff suppressed because it is too large.
Load diff
+1383
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,939 @@
|
||||
/**
|
||||
* \file pros/apix.h
|
||||
* \ingroup apix
|
||||
*
|
||||
* PROS Extended API header
|
||||
*
|
||||
* Contains additional declarations for use by advaned users of PROS. These
|
||||
* functions do not typically have as much error handling or require deeper
|
||||
* knowledge of real time operating systems.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, Purdue University ACM SIGBots.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
* \defgroup apix Extended API
|
||||
* \note Also included in the Extended API is [LVGL.](https://lvgl.io/)
|
||||
*/
|
||||
|
||||
#ifndef _PROS_API_EXTENDED_H_
|
||||
#define _PROS_API_EXTENDED_H_
|
||||
|
||||
#include "api.h"
|
||||
#include "pros/device.h"
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wall"
|
||||
#pragma GCC diagnostic pop
|
||||
#include "pros/serial.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "pros/serial.hpp"
|
||||
namespace pros::c {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \ingroup apix
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup apix
|
||||
* @{
|
||||
*/
|
||||
|
||||
/// \name RTOS Facilities
|
||||
///@{
|
||||
|
||||
typedef void* queue_t;
|
||||
typedef void* sem_t;
|
||||
|
||||
/**
|
||||
* Unblocks a task in the Blocked state (e.g. waiting for a delay, on a
|
||||
* semaphore, etc.).
|
||||
*
|
||||
* \param task
|
||||
* The task to unblock
|
||||
*
|
||||
* \return True if the task was unblocked, false otherwise
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* task_t task = task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT,
|
||||
* TASK_STACK_DEPTH_DEFAULT, "task_fn");
|
||||
* task_delay(1000);
|
||||
* // in another task somewhere else, this will abort the task_delay bove:
|
||||
* task_abort_delay(task);
|
||||
* \endcode
|
||||
*/
|
||||
bool task_abort_delay(task_t task);
|
||||
|
||||
/**
|
||||
* Notify a task when a target task is being deleted.
|
||||
*
|
||||
* \param target_task
|
||||
* The task being watched for deletion
|
||||
* \param task_to_notify
|
||||
* The task to notify when target_task is deleted
|
||||
* \param value
|
||||
* The value to supply to task_notify_ext
|
||||
* \param notify_action
|
||||
* The action to supply to task_notify_ext
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* task_t task_to_delete = task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT,
|
||||
* TASK_STACK_DEPTH_DEFAULT, "task_fn");
|
||||
* task_t task_to_notify = task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT,
|
||||
* TASK_STACK_DEPTH_DEFAULT, "task_fn2");
|
||||
*
|
||||
* task_notify_ext(task_to_notify, 0, NOTIFY_ACTION_INCREMENT, NULL);
|
||||
*
|
||||
* task_notify_when_deleting(task_to_delete, task_get_current(), 0, NOTIFY_ACTION_NONE);
|
||||
* task_delete(task_to_delete);
|
||||
* \endcode
|
||||
*/
|
||||
void task_notify_when_deleting(task_t target_task, task_t task_to_notify, uint32_t value,
|
||||
notify_action_e_t notify_action);
|
||||
|
||||
/**
|
||||
* Creates a recursive mutex which can be locked recursively by the owner.
|
||||
*
|
||||
* \return A newly created recursive mutex.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* mutex_t mutex = mutex_recursive_create();
|
||||
*
|
||||
* void task_fn(void* param) {
|
||||
* while(1) {
|
||||
* mutex_recursive_take(mutex, 1000);
|
||||
* // critical section
|
||||
* mutex_recursive_give(mutex);
|
||||
* task_delay(1000);
|
||||
* }
|
||||
* }
|
||||
* task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT,
|
||||
* TASK_STACK_DEPTH_DEFAULT, "task_fn");
|
||||
*
|
||||
* \endcode
|
||||
*/
|
||||
mutex_t mutex_recursive_create(void);
|
||||
|
||||
/**
|
||||
* Takes a recursive mutex.
|
||||
*
|
||||
* \param mutex
|
||||
* A mutex handle created by mutex_recursive_create
|
||||
* \param wait_time
|
||||
* Amount of time to wait before timing out
|
||||
*
|
||||
* \return 1 if the mutex was obtained, 0 otherwise
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* mutex_t mutex = mutex_recursive_create();
|
||||
*
|
||||
* void task_fn(void* param) {
|
||||
* while(1) {
|
||||
* mutex_recursive_take(mutex, 1000);
|
||||
* // critical section
|
||||
* mutex_recursive_give(mutex);
|
||||
* task_delay(1000);
|
||||
* }
|
||||
* }
|
||||
* task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT,
|
||||
* TASK_STACK_DEPTH_DEFAULT, "task_fn");
|
||||
*
|
||||
* \endcode
|
||||
*/
|
||||
bool mutex_recursive_take(mutex_t mutex, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Gives a recursive mutex.
|
||||
*
|
||||
* \param mutex
|
||||
* A mutex handle created by mutex_recursive_create
|
||||
*
|
||||
* \return 1 if the mutex was obtained, 0 otherwise
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* mutex_t mutex = mutex_recursive_create();
|
||||
*
|
||||
* void task_fn(void* param) {
|
||||
* while(1) {
|
||||
* mutex_recursive_take(mutex, 1000);
|
||||
* // critical section
|
||||
* mutex_recursive_give(mutex);
|
||||
* task_delay(1000);
|
||||
* }
|
||||
* }
|
||||
* task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT,
|
||||
* TASK_STACK_DEPTH_DEFAULT, "task_fn");
|
||||
*
|
||||
* \endcode
|
||||
*/
|
||||
bool mutex_recursive_give(mutex_t mutex);
|
||||
|
||||
/**
|
||||
* Returns a handle to the current owner of a mutex.
|
||||
*
|
||||
* \param mutex
|
||||
* A mutex handle
|
||||
*
|
||||
* \return A handle to the current task that owns the mutex, or NULL if the
|
||||
* mutex isn't owned.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* mutex_t mutex = mutex_create();
|
||||
*
|
||||
* void task_fn(void* param) {
|
||||
* while(1) {
|
||||
* mutex_take(mutex, 1000);
|
||||
* // critical section
|
||||
* mutex_give(mutex);
|
||||
* task_delay(1000);
|
||||
* }
|
||||
* }
|
||||
* task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT,
|
||||
* TASK_STACK_DEPTH_DEFAULT, "task_fn");
|
||||
*
|
||||
* void opcontrol(void) {
|
||||
* while (1) {
|
||||
* if (joystick_get_digital(1, 7, JOY_UP)) {
|
||||
* task_t owner = mutex_get_owner(mutex);
|
||||
* if (owner != NULL) {
|
||||
* printf("Mutex is owned by task %s", task_get_name(owner));
|
||||
* } else {
|
||||
* printf("Mutex is not owned");
|
||||
* }
|
||||
* }
|
||||
* task_delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
task_t mutex_get_owner(mutex_t mutex);
|
||||
|
||||
/**
|
||||
* Creates a counting sempahore.
|
||||
*
|
||||
* \param max_count
|
||||
* The maximum count value that can be reached.
|
||||
* \param init_count
|
||||
* The initial count value assigned to the new semaphore.
|
||||
*
|
||||
* \return A newly created semaphore. If an error occurred, NULL will be
|
||||
* returned and errno can be checked for hints as to why sem_create failed.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* // Binary semaphore acts as a mutex
|
||||
* sem_t sem = sem_create(1, 0);
|
||||
*
|
||||
* void task_fn(void* param) {
|
||||
* while(1) {
|
||||
* sem_take(sem, 1000);
|
||||
* // critical section
|
||||
* sem_give(sem);
|
||||
* task_delay(1000);
|
||||
* }
|
||||
* }
|
||||
* task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT,
|
||||
* TASK_STACK_DEPTH_DEFAULT, "task_fn");
|
||||
*
|
||||
* \endcode
|
||||
*/
|
||||
sem_t sem_create(uint32_t max_count, uint32_t init_count);
|
||||
|
||||
/**
|
||||
* Deletes a semaphore (or binary semaphore)
|
||||
*
|
||||
* \param sem
|
||||
* Semaphore to delete
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* // Binary semaphore acts as a mutex
|
||||
* sem_t sem = sem_create(1, 0);
|
||||
*
|
||||
* void task_fn(void* param) {
|
||||
* while(1) {
|
||||
* sem_take(sem, 1000);
|
||||
* // critical section
|
||||
* sem_give(sem);
|
||||
* task_delay(1000);
|
||||
* }
|
||||
* }
|
||||
* task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT,
|
||||
* TASK_STACK_DEPTH_DEFAULT, "task_fn");
|
||||
*
|
||||
* void opcontrol(void) {
|
||||
* while (1) {
|
||||
* if (joystick_get_digital(1, 7, JOY_UP)) {
|
||||
* // honestly this is a bad example because you should never
|
||||
* // delete a semaphore like this
|
||||
* sem_delete(sem);
|
||||
* }
|
||||
* task_delay(20);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* \endcode
|
||||
*/
|
||||
void sem_delete(sem_t sem);
|
||||
|
||||
/**
|
||||
* Creates a binary semaphore.
|
||||
*
|
||||
* \return A newly created semaphore.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* // Binary semaphore acts as a mutex
|
||||
* sem_t sem = sem_binary_create();
|
||||
*
|
||||
* void task_fn(void* param) {
|
||||
* while(1) {
|
||||
* sem_take(sem, 1000);
|
||||
* // critical section
|
||||
* sem_give(sem);
|
||||
* task_delay(1000);
|
||||
* }
|
||||
* }
|
||||
* task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT,
|
||||
* TASK_STACK_DEPTH_DEFAULT, "task_fn");
|
||||
*
|
||||
* \endcode
|
||||
*/
|
||||
sem_t sem_binary_create(void);
|
||||
|
||||
/**
|
||||
* Waits for the semaphore's value to be greater than 0. If the value is already
|
||||
* greater than 0, this function immediately returns.
|
||||
*
|
||||
* \param sem
|
||||
* Semaphore to wait on
|
||||
* \param timeout
|
||||
* Time to wait before the semaphore's becomes available. A timeout of 0
|
||||
* can be used to poll the sempahore. TIMEOUT_MAX can be used to block
|
||||
* indefinitely.
|
||||
*
|
||||
* \return True if the semaphore was successfully take, false otherwise. If
|
||||
* false is returned, then errno is set with a hint about why the sempahore
|
||||
* couldn't be taken.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* // Binary semaphore acts as a mutex
|
||||
* sem_t sem = sem_create(1, 0);
|
||||
*
|
||||
* void task_fn(void* param) {
|
||||
* while(1) {
|
||||
* if(!sem_wait(sem, 1000)) {
|
||||
* printf("Failed to take semaphore");
|
||||
* task_delay(1000);
|
||||
* continue;
|
||||
* }
|
||||
* // critical section
|
||||
* sem_give(sem);
|
||||
* task_delay(1000);
|
||||
* }
|
||||
* }
|
||||
* task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT,
|
||||
* TASK_STACK_DEPTH_DEFAULT, "task_fn");
|
||||
*
|
||||
* void opcontrol(void) {
|
||||
* while (1) {
|
||||
* if (sem_wait(sem, 0))) {
|
||||
* printf("Semaphore is available");
|
||||
* }
|
||||
* task_delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
bool sem_wait(sem_t sem, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Increments a semaphore's value.
|
||||
*
|
||||
* \param sem
|
||||
* Semaphore to post
|
||||
*
|
||||
* \return True if the value was incremented, false otherwise. If false is
|
||||
* returned, then errno is set with a hint about why the semaphore couldn't be
|
||||
* taken.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* // Binary semaphore acts as a mutex
|
||||
* sem_t sem = sem_create(1, 0);
|
||||
*
|
||||
* void task_fn(void* param) {
|
||||
* while(1) {
|
||||
* sem_post(sem); // increments, mimicking to "claim"
|
||||
* // critical section
|
||||
* sem_give(sem);
|
||||
* task_delay(1000);
|
||||
* }
|
||||
* }
|
||||
* task_create(task_fn, (void*)"PROS", TASK_PRIORITY_DEFAULT,
|
||||
* TASK_STACK_DEPTH_DEFAULT, "task_fn");
|
||||
*
|
||||
* \endcode
|
||||
*/
|
||||
bool sem_post(sem_t sem);
|
||||
|
||||
/**
|
||||
* Returns the current value of the semaphore.
|
||||
*
|
||||
* \param sem
|
||||
* A semaphore handle
|
||||
*
|
||||
* \return The current value of the semaphore (e.g. the number of resources
|
||||
* available)
|
||||
*
|
||||
* \b Example of sem_get_count:
|
||||
* \code
|
||||
* // Binary semaphore acts as a mutex
|
||||
* sem_t sem = sem_create(1, 0);
|
||||
* printf("semaphore count: %d", sem_get_count(sem));
|
||||
* // semaphore count: 0
|
||||
* sem_take(sem, 1000);
|
||||
* printf("semaphore count: %d", sem_get_count(sem));
|
||||
* // semaphore count: 1
|
||||
* sem_give(sem);
|
||||
* printf("semaphore count: %d", sem_get_count(sem));
|
||||
* // semaphore count: 0
|
||||
*
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t sem_get_count(sem_t sem);
|
||||
|
||||
/**
|
||||
* Creates a queue.
|
||||
*
|
||||
* \param length
|
||||
* The maximum number of items that the queue can contain.
|
||||
* \param item_size
|
||||
* The number of bytes each item in the queue will require.
|
||||
*
|
||||
* \return A handle to a newly created queue, or NULL if the queue cannot be
|
||||
* created.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* queue_t queue = queue_create(10, sizeof(int));
|
||||
* int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
* queue_prepend(queue, item, 1000);
|
||||
* queue_append(queue, item, 1000);
|
||||
* printf("queue length: %d", queue_get_length(queue));
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
queue_t queue_create(uint32_t length, uint32_t item_size);
|
||||
|
||||
/**
|
||||
* Posts an item to the front of a queue. The item is queued by copy, not by
|
||||
* reference.
|
||||
*
|
||||
* \param queue
|
||||
* The queue handle
|
||||
* \param item
|
||||
* A pointer to the item that will be placed on the queue.
|
||||
* \param timeout
|
||||
* Time to wait for space to become available. A timeout of 0 can be used
|
||||
* to attempt to post without blocking. TIMEOUT_MAX can be used to block
|
||||
* indefinitely.
|
||||
*
|
||||
* \return True if the item was preprended, false otherwise.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* queue_t queue = queue_create(10, sizeof(int));
|
||||
* int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
* queue_prepend(queue, item, 1000);
|
||||
* queue_append(queue, item, 1000);
|
||||
* printf("queue length: %d", queue_get_length(queue));
|
||||
* }
|
||||
*/
|
||||
bool queue_prepend(queue_t queue, const void* item, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Posts an item to the end of a queue. The item is queued by copy, not by
|
||||
* reference.
|
||||
*
|
||||
* \param queue
|
||||
* The queue handle
|
||||
* \param item
|
||||
* A pointer to the item that will be placed on the queue.
|
||||
* \param timeout
|
||||
* Time to wait for space to become available. A timeout of 0 can be used
|
||||
* to attempt to post without blocking. TIMEOUT_MAX can be used to block
|
||||
* indefinitely.
|
||||
*
|
||||
* \return True if the item was preprended, false otherwise.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* queue_t queue = queue_create(10, sizeof(int));
|
||||
* int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
* queue_prepend(queue, item, 1000);
|
||||
* queue_append(queue, item, 1000);
|
||||
* printf("queue length: %d", queue_get_length(queue));
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
bool queue_append(queue_t queue, const void* item, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Receive an item from a queue without removing the item from the queue.
|
||||
*
|
||||
* \param queue
|
||||
* The queue handle
|
||||
* \param buffer
|
||||
* Pointer to a buffer to which the received item will be copied
|
||||
* \param timeout
|
||||
* The maximum amount of time the task should block waiting for an item to receive should the queue be empty at
|
||||
* the time of the call. TIMEOUT_MAX can be used to block indefinitely.
|
||||
*
|
||||
* \return True if an item was copied into the buffer, false otherwise.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* queue_t queue = queue_create(10, sizeof(int));
|
||||
* char* item = "Hello! this is a test";
|
||||
* queue_prepend(queue, item, 1000);
|
||||
* queue_append(queue, item, 1000);
|
||||
* char* recv = malloc(sizeof("Hello! this is a test"));
|
||||
* queue_peek(queue, recv, 1000);
|
||||
* printf("Queue: %s", recv);
|
||||
* free(recv);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
bool queue_peek(queue_t queue, void* const buffer, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Receive an item from the queue.
|
||||
*
|
||||
* \param queue
|
||||
* The queue handle
|
||||
* \param buffer
|
||||
* Pointer to a buffer to which the received item will be copied
|
||||
* \param timeout
|
||||
* The maximum amount of time the task should block
|
||||
* waiting for an item to receive should the queue be empty at the time
|
||||
* of the call. queue_recv() will return immediately if timeout
|
||||
* is zero and the queue is empty.
|
||||
*
|
||||
* \return True if an item was copied into the buffer, false otherwise.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* queue_t queue = queue_create(10, sizeof(int));
|
||||
* char* item = "Hello! this is a test";
|
||||
* queue_prepend(queue, item, 1000);
|
||||
* queue_append(queue, item, 1000);
|
||||
* char* recv = malloc(sizeof("Hello! this is a test"));
|
||||
* queue_recv(queue, recv, 1000);
|
||||
* printf("Queue: %s", recv);
|
||||
* free(recv);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
bool queue_recv(queue_t queue, void* const buffer, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Return the number of messages stored in a queue.
|
||||
*
|
||||
* \param queue
|
||||
* The queue handle.
|
||||
*
|
||||
* \return The number of messages available in the queue.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* queue_t queue = queue_create(10, sizeof(int));
|
||||
*
|
||||
* int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
* queue_prepend(queue, item, 1000);
|
||||
* queue_append(queue, item, 1000);
|
||||
* printf("queue waiting: %d", queue_get_waiting(queue));
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t queue_get_waiting(const queue_t queue);
|
||||
|
||||
/**
|
||||
* Return the number of spaces left in a queue.
|
||||
*
|
||||
* \param queue
|
||||
* The queue handle.
|
||||
*
|
||||
* \return The number of spaces available in the queue.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* queue_t queue = queue_create(10, sizeof(int));
|
||||
*
|
||||
* int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
* queue_prepend(queue, item, 1000);
|
||||
* queue_append(queue, item, 1000);
|
||||
* printf("queue available: %d", queue_get_available(queue));
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t queue_get_available(const queue_t queue);
|
||||
|
||||
/**
|
||||
* Delete a queue.
|
||||
*
|
||||
* \param queue
|
||||
* Queue handle to delete
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* queue_t queue = queue_create(10, sizeof(int));
|
||||
* queue_delete(queue);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
void queue_delete(queue_t queue);
|
||||
|
||||
/**
|
||||
* Resets a queue to an empty state
|
||||
*
|
||||
* \param queue
|
||||
* Queue handle to reset
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* queue_t queue = queue_create(10, sizeof(int));
|
||||
* int item[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
* queue_prepend(queue, item, 1000);
|
||||
* queue_append(queue, item, 1000);
|
||||
* queue_reset(queue);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
void queue_reset(queue_t queue);
|
||||
|
||||
///@}
|
||||
|
||||
/// \name Device Registration
|
||||
///@{
|
||||
|
||||
/**
|
||||
* Registers a device in the given zero-indexed port
|
||||
*
|
||||
* Registers a device of the given type in the given port into the registry, if
|
||||
* that type of device is detected to be plugged in to that 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 (0-20), or a
|
||||
* a different device than specified is plugged in.
|
||||
* EADDRINUSE - The port is already registered to another device.
|
||||
*
|
||||
* \param port
|
||||
* The port number to register the device
|
||||
* \param device
|
||||
* The type of device to register
|
||||
*
|
||||
* \return 1 upon success, PROS_ERR upon failure
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* registry_bind_port(1, E_DEVICE_MOTOR);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int registry_bind_port(uint8_t port, v5_device_e_t device_type);
|
||||
|
||||
/**
|
||||
* Deregisters a devices from the given zero-indexed port
|
||||
*
|
||||
* Removes the device registed in the given port, if there is one.
|
||||
*
|
||||
* 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 (0-20).
|
||||
*
|
||||
* \param port
|
||||
* The port number to deregister
|
||||
*
|
||||
* \return 1 upon success, PROS_ERR upon failure
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* registry_bind_port(1, E_DEVICE_MOTOR);
|
||||
* registry_unbind_port(1);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int registry_unbind_port(uint8_t port);
|
||||
|
||||
/**
|
||||
* Returns the type of device registered to the zero-indexed 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 (0-20).
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 0-20
|
||||
*
|
||||
* \return The type of device that is registered into the port (NOT what is
|
||||
* plugged in)
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* registry_bind_port(1, E_DEVICE_MOTOR);
|
||||
* printf("port 1 is registered to a motor: %d", registry_get_bound_type(1) == E_DEVICE_MOTOR);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
v5_device_e_t registry_get_bound_type(uint8_t port);
|
||||
|
||||
/**
|
||||
* Returns the type of the device plugged into the zero-indexed 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 (0-20).
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 0-20
|
||||
*
|
||||
* \return The type of device that is plugged into the port (NOT what is
|
||||
* registered)
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* registry_bind_port(1, E_DEVICE_MOTOR);
|
||||
* printf("port 1 is registered to a motor: %d", registry_get_plugged_type(1) == E_DEVICE_MOTOR);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
v5_device_e_t registry_get_plugged_type(uint8_t port);
|
||||
|
||||
///@}
|
||||
|
||||
/// \name Filesystem
|
||||
///@{
|
||||
|
||||
/**
|
||||
* Control settings of the serial driver.
|
||||
*
|
||||
* \param action
|
||||
* An action to perform on the serial driver. See the SERCTL_* macros for
|
||||
* details on the different actions.
|
||||
* \param extra_arg
|
||||
* An argument to pass in based on the action
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* serctl(SERCTL_SET_BAUDRATE, (void*) 9600);
|
||||
* }
|
||||
*/
|
||||
int32_t serctl(const uint32_t action, void* const extra_arg);
|
||||
|
||||
/*
|
||||
* Control settings of the microSD card driver.
|
||||
*
|
||||
* \param action
|
||||
* An action to perform on the microSD card driver. See the USDCTL_* macros
|
||||
* for details on the different actions.
|
||||
* \param extra_arg
|
||||
* An argument to pass in based on the action
|
||||
*/
|
||||
// Not yet implemented
|
||||
// int32_t usdctl(const uint32_t action, void* const extra_arg);
|
||||
|
||||
/**
|
||||
* Control settings of the way the file's driver treats the file
|
||||
*
|
||||
* \param file
|
||||
* A valid file descriptor number
|
||||
* \param action
|
||||
* An action to perform on the file's driver. See the *CTL_* macros for
|
||||
* details on the different actions. Note that the action passed in must
|
||||
* match the correct driver (e.g. don't perform a SERCTL_* action on a
|
||||
* microSD card file)
|
||||
* \param extra_arg
|
||||
* An argument to pass in based on the action
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol(void) {
|
||||
* int32_t fd = open("serial", O_RDWR);
|
||||
* fdctl(fd, SERCTL_SET_BAUDRATE, (void*) 9600);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t fdctl(int file, const uint32_t action, void* const extra_arg);
|
||||
|
||||
/**
|
||||
* Sets the reverse flag for the motor.
|
||||
*
|
||||
* This will invert its movements and the values returned for its position.
|
||||
*
|
||||
* 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 motor
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param reverse
|
||||
* True reverses the motor, false is default
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void autonomous() {
|
||||
* motor_set_reversed(1, true);
|
||||
* printf("Is this motor reversed? %d\n", motor_is_reversed(1));
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t motor_set_reversed(int8_t port, const bool reverse);
|
||||
|
||||
/**
|
||||
* Gets the operation direction of the motor as set by the user.
|
||||
*
|
||||
* 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 motor
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
*
|
||||
* \return 1 if the motor has been reversed and 0 if the motor was not reversed,
|
||||
* or PROS_ERR if the operation failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* printf("Is the motor reversed? %d\n", motor_is_reversed(1));
|
||||
* // Prints "Is the motor reversed? 0"
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t motor_is_reversed(int8_t port);
|
||||
|
||||
/**
|
||||
* Action macro to pass into serctl or fdctl that activates the stream
|
||||
* identifier.
|
||||
*
|
||||
* When used with serctl, the extra argument must be the little endian
|
||||
* representation of the stream identifier (e.g. "sout" -> 0x74756f73)
|
||||
*
|
||||
*/
|
||||
#define SERCTL_ACTIVATE 10
|
||||
|
||||
/**
|
||||
* Action macro to pass into serctl or fdctl that deactivates the stream
|
||||
* identifier.
|
||||
*
|
||||
* When used with serctl, the extra argument must be the little endian
|
||||
* representation of the stream identifier (e.g. "sout" -> 0x74756f73)
|
||||
*
|
||||
*/
|
||||
#define SERCTL_DEACTIVATE 11
|
||||
|
||||
/**
|
||||
* Action macro to pass into fdctl that enables blocking writes for the file
|
||||
*
|
||||
* The extra argument is not used with this action, provide any value (e.g.
|
||||
* NULL) instead
|
||||
*
|
||||
*/
|
||||
#define SERCTL_BLKWRITE 12
|
||||
|
||||
/**
|
||||
* Action macro to pass into fdctl that makes writes non-blocking for the file
|
||||
*
|
||||
* The extra argument is not used with this action, provide any value (e.g.
|
||||
* NULL) instead
|
||||
*
|
||||
*/
|
||||
#define SERCTL_NOBLKWRITE 13
|
||||
|
||||
/**
|
||||
* Action macro to pass into serctl that enables advanced stream multiplexing
|
||||
* capabilities
|
||||
*
|
||||
* The extra argument is not used with this action, provide any value (e.g.
|
||||
* NULL) instead
|
||||
*
|
||||
*/
|
||||
#define SERCTL_ENABLE_COBS 14
|
||||
|
||||
/**
|
||||
* Action macro to pass into serctl that disables advanced stream multiplexing
|
||||
* capabilities
|
||||
*
|
||||
* The extra argument is not used with this action, provide any value (e.g.
|
||||
* NULL) instead
|
||||
*
|
||||
*/
|
||||
#define SERCTL_DISABLE_COBS 15
|
||||
|
||||
/**
|
||||
* Action macro to check if there is data available from the Generic Serial
|
||||
* Device
|
||||
*
|
||||
*/
|
||||
#define DEVCTL_FIONREAD 16
|
||||
|
||||
/**
|
||||
* Action macro to check if there is space available in the Generic Serial
|
||||
* Device's output buffer
|
||||
*
|
||||
*/
|
||||
#define DEVCTL_FIONWRITE 18
|
||||
|
||||
/**
|
||||
* Action macro to set the Generic Serial Device's baudrate.
|
||||
*
|
||||
* The extra argument is the baudrate.
|
||||
*/
|
||||
#define DEVCTL_SET_BAUDRATE 17
|
||||
|
||||
///@}
|
||||
|
||||
///@}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _PROS_API_EXTENDED_H_
|
||||
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
* \file pros/colors.h
|
||||
*
|
||||
* Contains macro definitions of colors (as `uint32_t`)
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
* \defgroup c-colors Colors C API
|
||||
*/
|
||||
|
||||
/**
|
||||
* \ingroup c-colors
|
||||
* \note These functions can be used for dynamic device instantiation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup c-colors
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef _PROS_COLORS_H_
|
||||
#define _PROS_COLORS_H_
|
||||
|
||||
#define RGB2COLOR(R, G, B) ((R & 0xff) << 16 | (G & 0xff) << 8 | (B & 0xff))
|
||||
#define COLOR2R(COLOR) ((COLOR >> 16) & 0xff)
|
||||
#define COLOR2G(COLOR) ((COLOR >> 8) & 0xff)
|
||||
#define COLOR2B(COLOR) (COLOR & 0xff)
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace pros {
|
||||
namespace c {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \enum color_e_t
|
||||
* @brief
|
||||
* Enum of possible colors
|
||||
*
|
||||
* Contains common colors, all members are self descriptive.
|
||||
*/
|
||||
typedef enum color_e {
|
||||
COLOR_ALICE_BLUE = 0x00F0F8FF,
|
||||
COLOR_ANTIQUE_WHITE = 0x00FAEBD7,
|
||||
COLOR_AQUA = 0x0000FFFF,
|
||||
COLOR_AQUAMARINE = 0x007FFFD4,
|
||||
COLOR_AZURE = 0x00F0FFFF,
|
||||
COLOR_BEIGE = 0x00F5F5DC,
|
||||
COLOR_BISQUE = 0x00FFE4C4,
|
||||
COLOR_BLACK = 0x00000000,
|
||||
COLOR_BLANCHED_ALMOND = 0x00FFEBCD,
|
||||
COLOR_BLUE = 0x000000FF,
|
||||
COLOR_BLUE_VIOLET = 0x008A2BE2,
|
||||
COLOR_BROWN = 0x00A52A2A,
|
||||
COLOR_BURLY_WOOD = 0x00DEB887,
|
||||
COLOR_CADET_BLUE = 0x005F9EA0,
|
||||
COLOR_CHARTREUSE = 0x007FFF00,
|
||||
COLOR_CHOCOLATE = 0x00D2691E,
|
||||
COLOR_CORAL = 0x00FF7F50,
|
||||
COLOR_CORNFLOWER_BLUE = 0x006495ED,
|
||||
COLOR_CORNSILK = 0x00FFF8DC,
|
||||
COLOR_CRIMSON = 0x00DC143C,
|
||||
COLOR_CYAN = 0x0000FFFF,
|
||||
COLOR_DARK_BLUE = 0x0000008B,
|
||||
COLOR_DARK_CYAN = 0x00008B8B,
|
||||
COLOR_DARK_GOLDENROD = 0x00B8860B,
|
||||
COLOR_DARK_GRAY = 0x00A9A9A9,
|
||||
COLOR_DARK_GREY = COLOR_DARK_GRAY,
|
||||
COLOR_DARK_GREEN = 0x00006400,
|
||||
COLOR_DARK_KHAKI = 0x00BDB76B,
|
||||
COLOR_DARK_MAGENTA = 0x008B008B,
|
||||
COLOR_DARK_OLIVE_GREEN = 0x00556B2F,
|
||||
COLOR_DARK_ORANGE = 0x00FF8C00,
|
||||
COLOR_DARK_ORCHID = 0x009932CC,
|
||||
COLOR_DARK_RED = 0x008B0000,
|
||||
COLOR_DARK_SALMON = 0x00E9967A,
|
||||
COLOR_DARK_SEA_GREEN = 0x008FBC8F,
|
||||
COLOR_DARK_SLATE_GRAY = 0x002F4F4F,
|
||||
COLOR_DARK_SLATE_GREY = COLOR_DARK_SLATE_GRAY,
|
||||
COLOR_DARK_TURQUOISE = 0x0000CED1,
|
||||
COLOR_DARK_VIOLET = 0x009400D3,
|
||||
COLOR_DEEP_PINK = 0x00FF1493,
|
||||
COLOR_DEEP_SKY_BLUE = 0x0000BFFF,
|
||||
COLOR_DIM_GRAY = 0x00696969,
|
||||
COLOR_DIM_GREY = COLOR_DIM_GRAY,
|
||||
COLOR_DODGER_BLUE = 0x001E90FF,
|
||||
COLOR_FIRE_BRICK = 0x00B22222,
|
||||
COLOR_FLORAL_WHITE = 0x00FFFAF0,
|
||||
COLOR_FOREST_GREEN = 0x00228B22,
|
||||
COLOR_FUCHSIA = 0x00FF00FF,
|
||||
COLOR_GAINSBORO = 0x00DCDCDC,
|
||||
COLOR_GHOST_WHITE = 0x00F8F8FF,
|
||||
COLOR_GOLD = 0x00FFD700,
|
||||
COLOR_GOLDENROD = 0x00DAA520,
|
||||
COLOR_GRAY = 0x00808080,
|
||||
COLOR_GREY = COLOR_GRAY,
|
||||
COLOR_GREEN = 0x00008000,
|
||||
COLOR_GREEN_YELLOW = 0x00ADFF2F,
|
||||
COLOR_HONEYDEW = 0x00F0FFF0,
|
||||
COLOR_HOT_PINK = 0x00FF69B4,
|
||||
COLOR_INDIAN_RED = 0x00CD5C5C,
|
||||
COLOR_INDIGO = 0x004B0082,
|
||||
COLOR_IVORY = 0x00FFFFF0,
|
||||
COLOR_KHAKI = 0x00F0E68C,
|
||||
COLOR_LAVENDER = 0x00E6E6FA,
|
||||
COLOR_LAVENDER_BLUSH = 0x00FFF0F5,
|
||||
COLOR_LAWN_GREEN = 0x007CFC00,
|
||||
COLOR_LEMON_CHIFFON = 0x00FFFACD,
|
||||
COLOR_LIGHT_BLUE = 0x00ADD8E6,
|
||||
COLOR_LIGHT_CORAL = 0x00F08080,
|
||||
COLOR_LIGHT_CYAN = 0x00E0FFFF,
|
||||
COLOR_LIGHT_GOLDENROD_YELLOW = 0x00FAFAD2,
|
||||
COLOR_LIGHT_GREEN = 0x0090EE90,
|
||||
COLOR_LIGHT_GRAY = 0x00D3D3D3,
|
||||
COLOR_LIGHT_GREY = COLOR_LIGHT_GRAY,
|
||||
COLOR_LIGHT_PINK = 0x00FFB6C1,
|
||||
COLOR_LIGHT_SALMON = 0x00FFA07A,
|
||||
COLOR_LIGHT_SEA_GREEN = 0x0020B2AA,
|
||||
COLOR_LIGHT_SKY_BLUE = 0x0087CEFA,
|
||||
COLOR_LIGHT_SLATE_GRAY = 0x00778899,
|
||||
COLOR_LIGHT_SLATE_GREY = COLOR_LIGHT_SLATE_GRAY,
|
||||
COLOR_LIGHT_STEEL_BLUE = 0x00B0C4DE,
|
||||
COLOR_LIGHT_YELLOW = 0x00FFFFE0,
|
||||
COLOR_LIME = 0x0000FF00,
|
||||
COLOR_LIME_GREEN = 0x0032CD32,
|
||||
COLOR_LINEN = 0x00FAF0E6,
|
||||
COLOR_MAGENTA = 0x00FF00FF,
|
||||
COLOR_MAROON = 0x00800000,
|
||||
COLOR_MEDIUM_AQUAMARINE = 0x0066CDAA,
|
||||
COLOR_MEDIUM_BLUE = 0x000000CD,
|
||||
COLOR_MEDIUM_ORCHID = 0x00BA55D3,
|
||||
COLOR_MEDIUM_PURPLE = 0x009370DB,
|
||||
COLOR_MEDIUM_SEA_GREEN = 0x003CB371,
|
||||
COLOR_MEDIUM_SLATE_BLUE = 0x007B68EE,
|
||||
COLOR_MEDIUM_SPRING_GREEN = 0x0000FA9A,
|
||||
COLOR_MEDIUM_TURQUOISE = 0x0048D1CC,
|
||||
COLOR_MEDIUM_VIOLET_RED = 0x00C71585,
|
||||
COLOR_MIDNIGHT_BLUE = 0x00191970,
|
||||
COLOR_MINT_CREAM = 0x00F5FFFA,
|
||||
COLOR_MISTY_ROSE = 0x00FFE4E1,
|
||||
COLOR_MOCCASIN = 0x00FFE4B5,
|
||||
COLOR_NAVAJO_WHITE = 0x00FFDEAD,
|
||||
COLOR_NAVY = 0x00000080,
|
||||
COLOR_OLD_LACE = 0x00FDF5E6,
|
||||
COLOR_OLIVE = 0x00808000,
|
||||
COLOR_OLIVE_DRAB = 0x006B8E23,
|
||||
COLOR_ORANGE = 0x00FFA500,
|
||||
COLOR_ORANGE_RED = 0x00FF4500,
|
||||
COLOR_ORCHID = 0x00DA70D6,
|
||||
COLOR_PALE_GOLDENROD = 0x00EEE8AA,
|
||||
COLOR_PALE_GREEN = 0x0098FB98,
|
||||
COLOR_PALE_TURQUOISE = 0x00AFEEEE,
|
||||
COLOR_PALE_VIOLET_RED = 0x00DB7093,
|
||||
COLOR_PAPAY_WHIP = 0x00FFEFD5,
|
||||
COLOR_PEACH_PUFF = 0x00FFDAB9,
|
||||
COLOR_PERU = 0x00CD853F,
|
||||
COLOR_PINK = 0x00FFC0CB,
|
||||
COLOR_PLUM = 0x00DDA0DD,
|
||||
COLOR_POWDER_BLUE = 0x00B0E0E6,
|
||||
COLOR_PURPLE = 0x00800080,
|
||||
COLOR_RED = 0x00FF0000,
|
||||
COLOR_ROSY_BROWN = 0x00BC8F8F,
|
||||
COLOR_ROYAL_BLUE = 0x004169E1,
|
||||
COLOR_SADDLE_BROWN = 0x008B4513,
|
||||
COLOR_SALMON = 0x00FA8072,
|
||||
COLOR_SANDY_BROWN = 0x00F4A460,
|
||||
COLOR_SEA_GREEN = 0x002E8B57,
|
||||
COLOR_SEASHELL = 0x00FFF5EE,
|
||||
COLOR_SIENNA = 0x00A0522D,
|
||||
COLOR_SILVER = 0x00C0C0C0,
|
||||
COLOR_SKY_BLUE = 0x0087CEEB,
|
||||
COLOR_SLATE_BLUE = 0x006A5ACD,
|
||||
COLOR_SLATE_GRAY = 0x00708090,
|
||||
COLOR_SLATE_GREY = COLOR_SLATE_GRAY,
|
||||
COLOR_SNOW = 0x00FFFAFA,
|
||||
COLOR_SPRING_GREEN = 0x0000FF7F,
|
||||
COLOR_STEEL_BLUE = 0x004682B4,
|
||||
COLOR_TAN = 0x00D2B48C,
|
||||
COLOR_TEAL = 0x00008080,
|
||||
COLOR_THISTLE = 0x00D8BFD8,
|
||||
COLOR_TOMATO = 0x00FF6347,
|
||||
COLOR_TURQUOISE = 0x0040E0D0,
|
||||
COLOR_VIOLET = 0x00EE82EE,
|
||||
COLOR_WHEAT = 0x00F5DEB3,
|
||||
COLOR_WHITE = 0x00FFFFFF,
|
||||
COLOR_WHITE_SMOKE = 0x00F5F5F5,
|
||||
COLOR_YELLOW = 0x00FFFF00,
|
||||
COLOR_YELLOW_GREEN = 0x009ACD32,
|
||||
} color_e_t;
|
||||
|
||||
///@}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // namespace c
|
||||
} // namespace pros
|
||||
#endif
|
||||
|
||||
#endif // _PROS_COLORS_H_
|
||||
@@ -0,0 +1,190 @@
|
||||
/**
|
||||
* \file pros/colors.hpp
|
||||
*
|
||||
* Contains enum class definitions of colors
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* Copyright (c) 2017-2022 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/.
|
||||
*
|
||||
* \defgroup cpp-colors C++ Color API
|
||||
*/
|
||||
#ifndef _PROS_COLORS_HPP_
|
||||
#define _PROS_COLORS_HPP_
|
||||
|
||||
|
||||
namespace pros{
|
||||
/**
|
||||
* \ingroup cpp-colors
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup cpp-colors
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \enum Color
|
||||
* @brief
|
||||
* Enum class of possible colors
|
||||
*
|
||||
* Contains common colors, all members are self descriptive.
|
||||
*/
|
||||
enum class Color {
|
||||
alice_blue = 0x00F0F8FF,
|
||||
antique_white = 0x00FAEBD7,
|
||||
aqua = 0x0000FFFF,
|
||||
aquamarine = 0x007FFFD4,
|
||||
azure = 0x00F0FFFF,
|
||||
beige = 0x00F5F5DC,
|
||||
bisque = 0x00FFE4C4,
|
||||
black = 0x00000000,
|
||||
blanched_almond = 0x00FFEBCD,
|
||||
blue = 0x000000FF,
|
||||
blue_violet = 0x008A2BE2,
|
||||
brown = 0x00A52A2A,
|
||||
burly_wood = 0x00DEB887,
|
||||
cadet_blue = 0x005F9EA0,
|
||||
chartreuse = 0x007FFF00,
|
||||
chocolate = 0x00D2691E,
|
||||
coral = 0x00FF7F50,
|
||||
cornflower_blue = 0x006495ED,
|
||||
cornsilk = 0x00FFF8DC,
|
||||
crimson = 0x00DC143C,
|
||||
cyan = 0x0000FFFF,
|
||||
dark_blue = 0x0000008B,
|
||||
dark_cyan = 0x00008B8B,
|
||||
dark_goldenrod = 0x00B8860B,
|
||||
dark_gray = 0x00A9A9A9,
|
||||
dark_grey = dark_gray,
|
||||
dark_green = 0x00006400,
|
||||
dark_khaki = 0x00BDB76B,
|
||||
dark_magenta = 0x008B008B,
|
||||
dark_olive_green = 0x00556B2F,
|
||||
dark_orange = 0x00FF8C00,
|
||||
dark_orchid = 0x009932CC,
|
||||
dark_red = 0x008B0000,
|
||||
dark_salmon = 0x00E9967A,
|
||||
dark_sea_green = 0x008FBC8F,
|
||||
dark_slate_gray = 0x002F4F4F,
|
||||
dark_slate_grey = dark_slate_gray,
|
||||
dark_turquoise = 0x0000CED1,
|
||||
dark_violet = 0x009400D3,
|
||||
deep_pink = 0x00FF1493,
|
||||
deep_sky_blue = 0x0000BFFF,
|
||||
dim_gray = 0x00696969,
|
||||
dim_grey = dim_gray,
|
||||
dodger_blue = 0x001E90FF,
|
||||
fire_brick = 0x00B22222,
|
||||
floral_white = 0x00FFFAF0,
|
||||
forest_green = 0x00228B22,
|
||||
fuchsia = 0x00FF00FF,
|
||||
gainsboro = 0x00DCDCDC,
|
||||
ghost_white = 0x00F8F8FF,
|
||||
gold = 0x00FFD700,
|
||||
goldenrod = 0x00DAA520,
|
||||
gray = 0x00808080,
|
||||
grey = gray,
|
||||
green = 0x00008000,
|
||||
green_yellow = 0x00ADFF2F,
|
||||
honeydew = 0x00F0FFF0,
|
||||
hot_pink = 0x00FF69B4,
|
||||
indian_red = 0x00CD5C5C,
|
||||
indigo = 0x004B0082,
|
||||
ivory = 0x00FFFFF0,
|
||||
khaki = 0x00F0E68C,
|
||||
lavender = 0x00E6E6FA,
|
||||
lavender_blush = 0x00FFF0F5,
|
||||
lawn_green = 0x007CFC00,
|
||||
lemon_chiffon = 0x00FFFACD,
|
||||
light_blue = 0x00ADD8E6,
|
||||
light_coral = 0x00F08080,
|
||||
light_cyan = 0x00E0FFFF,
|
||||
light_goldenrod_yellow = 0x00FAFAD2,
|
||||
light_green = 0x0090EE90,
|
||||
light_gray = 0x00D3D3D3,
|
||||
light_grey = light_gray,
|
||||
light_pink = 0x00FFB6C1,
|
||||
light_salmon = 0x00FFA07A,
|
||||
light_sea_green = 0x0020B2AA,
|
||||
light_sky_blue = 0x0087CEFA,
|
||||
light_slate_gray = 0x00778899,
|
||||
light_slate_grey = light_slate_gray,
|
||||
light_steel_blue = 0x00B0C4DE,
|
||||
light_yellow = 0x00FFFFE0,
|
||||
lime = 0x0000FF00,
|
||||
lime_green = 0x0032CD32,
|
||||
linen = 0x00FAF0E6,
|
||||
magenta = 0x00FF00FF,
|
||||
maroon = 0x00800000,
|
||||
medium_aquamarine = 0x0066CDAA,
|
||||
medium_blue = 0x000000CD,
|
||||
medium_orchid = 0x00BA55D3,
|
||||
medium_purple = 0x009370DB,
|
||||
medium_sea_green = 0x003CB371,
|
||||
medium_slate_blue = 0x007B68EE,
|
||||
medium_spring_green = 0x0000FA9A,
|
||||
medium_turquoise = 0x0048D1CC,
|
||||
medium_violet_red = 0x00C71585,
|
||||
midnight_blue = 0x00191970,
|
||||
mint_cream = 0x00F5FFFA,
|
||||
misty_rose = 0x00FFE4E1,
|
||||
moccasin = 0x00FFE4B5,
|
||||
navajo_white = 0x00FFDEAD,
|
||||
navy = 0x00000080,
|
||||
old_lace = 0x00FDF5E6,
|
||||
olive = 0x00808000,
|
||||
olive_drab = 0x006B8E23,
|
||||
orange = 0x00FFA500,
|
||||
orange_red = 0x00FF4500,
|
||||
orchid = 0x00DA70D6,
|
||||
pale_goldenrod = 0x00EEE8AA,
|
||||
pale_green = 0x0098FB98,
|
||||
pale_turquoise = 0x00AFEEEE,
|
||||
pale_violet_red = 0x00DB7093,
|
||||
papay_whip = 0x00FFEFD5,
|
||||
peach_puff = 0x00FFDAB9,
|
||||
peru = 0x00CD853F,
|
||||
pink = 0x00FFC0CB,
|
||||
plum = 0x00DDA0DD,
|
||||
powder_blue = 0x00B0E0E6,
|
||||
purple = 0x00800080,
|
||||
red = 0x00FF0000,
|
||||
rosy_brown = 0x00BC8F8F,
|
||||
royal_blue = 0x004169E1,
|
||||
saddle_brown = 0x008B4513,
|
||||
salmon = 0x00FA8072,
|
||||
sandy_brown = 0x00F4A460,
|
||||
sea_green = 0x002E8B57,
|
||||
seashell = 0x00FFF5EE,
|
||||
sienna = 0x00A0522D,
|
||||
silver = 0x00C0C0C0,
|
||||
sky_blue = 0x0087CEEB,
|
||||
slate_blue = 0x006A5ACD,
|
||||
slate_gray = 0x00708090,
|
||||
slate_grey = slate_gray,
|
||||
snow = 0x00FFFAFA,
|
||||
spring_green = 0x0000FF7F,
|
||||
steel_blue = 0x004682B4,
|
||||
tan = 0x00D2B48C,
|
||||
teal = 0x00008080,
|
||||
thistle = 0x00D8BFD8,
|
||||
tomato = 0x00FF6347,
|
||||
turquoise = 0x0040E0D0,
|
||||
violet = 0x00EE82EE,
|
||||
wheat = 0x00F5DEB3,
|
||||
white = 0x00FFFFFF,
|
||||
white_smoke = 0x00F5F5F5,
|
||||
yellow = 0x00FFFF00,
|
||||
yellow_green = 0x009ACD32,
|
||||
};
|
||||
} // namespace pros
|
||||
|
||||
///@}
|
||||
|
||||
#endif //_PROS_COLORS_HPP_
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* \file pros/device.h
|
||||
*
|
||||
* Contains functions for interacting with VEX devices.
|
||||
*
|
||||
*
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2021, 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/.
|
||||
*
|
||||
* \defgroup c-device VEX Generic Device C API (For Advanced Users)
|
||||
*/
|
||||
|
||||
#ifndef _PROS_DEVICE_H_
|
||||
#define _PROS_DEVICE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace pros::c {
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \ingroup c-device
|
||||
* \note These functions can be used for dynamic device instantiation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup c-device
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \enum v5_device_e
|
||||
* \brief
|
||||
* List of possible v5 devices
|
||||
*
|
||||
* This list contains all current V5 Devices, and mirrors V5_DeviceType from the
|
||||
* api.
|
||||
*/
|
||||
typedef enum v5_device_e {
|
||||
E_DEVICE_NONE = 0, ///< No device is plugged into the port
|
||||
E_DEVICE_MOTOR = 2, ///< A motor is plugged into the port
|
||||
E_DEVICE_ROTATION = 4, ///< A rotation sensor is plugged into the port
|
||||
E_DEVICE_IMU = 6, ///< An inertial sensor is plugged into the port
|
||||
E_DEVICE_DISTANCE = 7, ///< A distance sensor is plugged into the port
|
||||
E_DEVICE_RADIO = 8, ///< A radio is plugged into the port
|
||||
E_DEVICE_VISION = 11, ///< A vision sensor is plugged into the port
|
||||
E_DEVICE_ADI = 12, ///< This port is an ADI expander
|
||||
E_DEVICE_OPTICAL = 16, ///< An optical sensor is plugged into the port
|
||||
E_DEVICE_GPS = 20, ///< A GPS sensor is plugged into the port
|
||||
E_DEVICE_SERIAL = 129, ///< A serial device is plugged into the port
|
||||
E_DEVICE_GENERIC __attribute__((deprecated("use E_DEVICE_SERIAL instead"))) = E_DEVICE_SERIAL,
|
||||
E_DEVICE_UNDEFINED = 255 ///< The device type is not defined, or is not a valid device
|
||||
} v5_device_e_t;
|
||||
|
||||
/**
|
||||
* Gets the type of device on given port.
|
||||
*
|
||||
* \return The device type as an enum.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define DEVICE_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* v5_device_e_t pt = get_plugged_type(DEVICE_PORT);
|
||||
* printf("device plugged type: {plugged type: %d}\n", pt);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
v5_device_e_t get_plugged_type(uint8_t port);
|
||||
|
||||
///@}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // namespace c
|
||||
} // namespace pros
|
||||
#endif
|
||||
|
||||
#endif // _PROS_DEVICE_H_
|
||||
@@ -0,0 +1,205 @@
|
||||
/**
|
||||
* \file pros/device.hpp
|
||||
*
|
||||
* Base class for all smart devices.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2021, 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/.
|
||||
*
|
||||
* \defgroup cpp-device VEX Generic Device C++ API (For Advanced Users)
|
||||
*/
|
||||
|
||||
#ifndef _PROS_DEVICE_HPP_
|
||||
#define _PROS_DEVICE_HPP_
|
||||
|
||||
#include "pros/misc.hpp"
|
||||
#include "pros/rtos.hpp"
|
||||
|
||||
namespace pros {
|
||||
inline namespace v5 {
|
||||
/**
|
||||
* \ingroup cpp-device
|
||||
* \note These functions can be used for dynamic device instantiation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup cpp-device
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \enum DeviceType
|
||||
* \brief
|
||||
* Enum of possible v5 devices.
|
||||
*
|
||||
* Contains all current V5 Devices.
|
||||
*/
|
||||
enum class DeviceType {
|
||||
none = 0, ///< No device is plugged into the port
|
||||
motor = 2, ///< A motor is plugged into the port
|
||||
rotation = 4, ///< A rotation sensor is plugged into the port
|
||||
imu = 6, ///< An inertial sensor is plugged into the port
|
||||
distance = 7, ///< A distance sensor is plugged into the port
|
||||
radio = 8, ///< A radio is plugged into the port
|
||||
vision = 11, ///< A vision sensor is plugged into the port
|
||||
adi = 12, ///< This port is an ADI expander
|
||||
optical = 16, ///< An optical sensor is plugged into the port
|
||||
gps = 20, ///< A GPS sensor is plugged into the port
|
||||
serial = 129, ///< A serial device is plugged into the port
|
||||
undefined = 255 ///< The device type is not defined, or is not a valid device
|
||||
};
|
||||
|
||||
class Device {
|
||||
public:
|
||||
/**
|
||||
* Creates a Device object.
|
||||
*
|
||||
* \param port The V5 port number from 1-21
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define DEVICE_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Device device(DEVICE_PORT);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
explicit Device(const std::uint8_t port);
|
||||
|
||||
/**
|
||||
* Gets the port number of the Smart Device.
|
||||
*
|
||||
* \return The smart device's port number.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* #define DEVICE_PORT 1
|
||||
* while (true) {
|
||||
* Device device(DEVICE_PORT);
|
||||
* printf("device plugged type: {port: %d}\n", device.get_port());
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint8_t get_port(void) const;
|
||||
|
||||
/**
|
||||
* Checks if the device is installed.
|
||||
*
|
||||
* \return true if the corresponding device is installed, false otherwise.
|
||||
* \b Example
|
||||
*
|
||||
* \code
|
||||
* #define DEVICE_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Device device(DEVICE_PORT);
|
||||
* while (true) {
|
||||
* printf("device plugged type: {is_installed: %d}\n", device.is_installed());
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual bool is_installed();
|
||||
|
||||
/**
|
||||
* Gets the type of device.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Mutex of port cannot be taken (access denied).
|
||||
*
|
||||
* \return The device type as an enum.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define DEVICE_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
Device device(DEVICE_PORT);
|
||||
* while (true) {
|
||||
* DeviceType dt = device.get_plugged_type();
|
||||
* printf("device plugged type: {plugged type: %d}\n", dt);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
pros::DeviceType get_plugged_type() const;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the type of device on a given port.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Mutex of port cannot be taken (access denied).
|
||||
*
|
||||
* \param port The V5 port number from 1-21
|
||||
*
|
||||
* \return The device type as an enum.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define DEVICE_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* DeviceType dt = pros::Device::get_plugged_type(DEVICE_PORT);
|
||||
* printf("device plugged type: {plugged type: %d}\n", dt);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
static pros::DeviceType get_plugged_type(std::uint8_t port);
|
||||
|
||||
/**
|
||||
* Gets all devices of a given device type.
|
||||
*
|
||||
* \param device_type The pros::DeviceType enum that matches the type of device desired.
|
||||
*
|
||||
* \return A vector of Device objects for the given device type.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* std::vector<Device> motor_devices = pros::Device::get_all_devices(pros::DeviceType::motor); // All Device objects are motors
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
|
||||
static std::vector<Device> get_all_devices(pros::DeviceType device_type = pros::DeviceType::undefined);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Creates a Device object.
|
||||
*
|
||||
* \param port The V5 port number from 1-21
|
||||
*
|
||||
* \param deviceType The type of the constructed device
|
||||
*/
|
||||
Device(const std::uint8_t port, const enum DeviceType deviceType) :
|
||||
_port(port),
|
||||
_deviceType(deviceType) {}
|
||||
|
||||
protected:
|
||||
const std::uint8_t _port;
|
||||
const enum DeviceType _deviceType = pros::DeviceType::none;
|
||||
|
||||
///@}
|
||||
};
|
||||
} // namespace v5
|
||||
} // namespace pros
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,160 @@
|
||||
/**
|
||||
* \file pros/distance.h
|
||||
* \ingroup c-distance
|
||||
*
|
||||
* Contains prototypes for functions related to the VEX Distance sensor.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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/.
|
||||
*
|
||||
* \defgroup c-distance VEX Distance Sensor C API
|
||||
*/
|
||||
|
||||
#ifndef _PROS_DISTANCE_H_
|
||||
#define _PROS_DISTANCE_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
namespace pros {
|
||||
namespace c {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \ingroup c-distance
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup c-distance
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define DISTANCE_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("Distance Value: %d mm\n", distance_get(DISTANCE_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define DISTANCE_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("Distance Confidence Value: %d\n", distance_get_confidence(DISTANCE_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define DISTANCE_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("Distance Object Size: %d\n", distance_get_object_size(DISTANCE_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define DISTANCE_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("Distance Object Velocity: %f\n", distance_get_object_velocity(DISTANCE_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double distance_get_object_velocity(uint8_t port);
|
||||
|
||||
///@}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,247 @@
|
||||
/**
|
||||
* \file pros/distance.hpp
|
||||
* \ingroup cpp-distance
|
||||
*
|
||||
* Contains prototypes for the V5 Distance Sensor-related functions.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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/.
|
||||
*
|
||||
* \defgroup cpp-distance VEX Distance Sensor C++ API
|
||||
*/
|
||||
|
||||
#ifndef _PROS_DISTANCE_HPP_
|
||||
#define _PROS_DISTANCE_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
#include "pros/device.hpp"
|
||||
#include "pros/distance.h"
|
||||
|
||||
namespace pros {
|
||||
inline namespace v5 {
|
||||
/**
|
||||
* \ingroup cpp-distance
|
||||
*/
|
||||
class Distance : public Device {
|
||||
/**
|
||||
* \addtogroup cpp-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
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define DISTANCE_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Distance distance(DISTANCE_PORT);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
Distance(const std::uint8_t port);
|
||||
|
||||
Distance(const Device& device) : Distance(device.get_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. Will return 9999 if the sensor can not detect an object.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define DISTANCE_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
Distance distance(DISTANCE_PORT);
|
||||
* while (true) {
|
||||
* printf("Distance confidence: %d\n", distance.get());
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t get();
|
||||
|
||||
/**
|
||||
* Get the currently measured distance from the sensor in mm.
|
||||
* \note This function is identical to get().
|
||||
*
|
||||
* 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. Will return 9999 if the sensor can not detect an object.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define DISTANCE_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
Distance distance(DISTANCE_PORT);
|
||||
* while (true) {
|
||||
* printf("Distance confidence: %d\n", distance.get_distance());
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t get_distance();
|
||||
|
||||
/**
|
||||
* Gets all distance sensors.
|
||||
*
|
||||
* \return A vector of Distance sensor objects.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* std::vector<Distance> distance_all = pros::Distance::get_all_devices(); // All distance sensors that are
|
||||
* connected
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
static std::vector<Distance> get_all_devices();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define DISTANCE_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
Distance distance(DISTANCE_PORT);
|
||||
* while (true) {
|
||||
* printf("Distance confidence: %d\n", distance.get_confidence());
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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. Will return -1 if the sensor is not able to determine object size.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define DISTANCE_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
Distance distance(DISTANCE_PORT);
|
||||
* while (true) {
|
||||
* printf("Distance confidence: %d\n", distance.get_object_size());
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Distance distance(DISTANCE_PORT);
|
||||
* while (true) {
|
||||
* printf("Distance Object velocity: %f\n", distance.get_object_velocity());
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_object_velocity();
|
||||
|
||||
/**
|
||||
* This is the overload for the << operator for printing to streams
|
||||
*
|
||||
* Prints in format(this below is all in one line with no new line):
|
||||
* Distance [port: (port number), distance: (distance), confidence: (confidence),
|
||||
* object size: (object size), object velocity: (object velocity)]
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& os, pros::Distance& distance);
|
||||
|
||||
private:
|
||||
///@}
|
||||
};
|
||||
|
||||
namespace literals {
|
||||
/**
|
||||
* Constructs a Distance sensor object from a literal ending in _dist via calling the constructor
|
||||
*
|
||||
* \return a pros::Distance for the corresponding port
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* using namespace pros::literals;
|
||||
* void opcontrol() {
|
||||
* pros::Distance dist = 2_dist; //Makes an dist object on port 2
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
const pros::Distance operator"" _dist(const unsigned long long int d);
|
||||
} // namespace literals
|
||||
} // namespace v5
|
||||
} // namespace pros
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* \file pros/error.h
|
||||
*
|
||||
* Contains macro definitions for return types, mostly errors
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright Copyright (c) 2017-2023, 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_ERROR_H_
|
||||
#define _PROS_ERROR_H_
|
||||
|
||||
#include "limits.h"
|
||||
|
||||
// Different Byte Size Errors
|
||||
|
||||
/// @brief
|
||||
/// Return This on Byte Sized Return Error
|
||||
#define PROS_ERR_BYTE (INT8_MAX)
|
||||
|
||||
/// @brief
|
||||
/// Return This on 2 Byte Sized Return Error
|
||||
#define PROS_ERR_2_BYTE (INT16_MAX)
|
||||
|
||||
/// @brief
|
||||
/// Return This on 4 Byte Sized Return Error
|
||||
#define PROS_ERR (INT32_MAX)
|
||||
|
||||
/// @brief
|
||||
/// Return This on 8 Byte Sized Return Error
|
||||
#define PROS_ERR_F (INFINITY)
|
||||
|
||||
/// @brief
|
||||
/// Return This on Success (1)
|
||||
#define PROS_SUCCESS (1)
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,884 @@
|
||||
/**
|
||||
* \file pros/gps.h
|
||||
* \ingroup c-gps
|
||||
*
|
||||
* Contains prototypes for functions related to the VEX GPS.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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/.
|
||||
*
|
||||
* \defgroup c-gps VEX GPS Sensor C API
|
||||
* \note For a pros-specific usage guide on the GPS, please check out our article [here.](@ref gps)
|
||||
*/
|
||||
|
||||
#ifndef _PROS_GPS_H_
|
||||
#define _PROS_GPS_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
namespace pros {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \ingroup c-gps
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup c-gps
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \struct gps_position_s_t
|
||||
*/
|
||||
typedef struct __attribute__((__packed__)) gps_position_s {
|
||||
/// X Position (meters)
|
||||
double x;
|
||||
/// Y Position (meters)
|
||||
double y;
|
||||
} gps_position_s_t;
|
||||
|
||||
/**
|
||||
* \struct gps_status_s_t
|
||||
*/
|
||||
typedef struct __attribute__((__packed__)) gps_status_s {
|
||||
/// X Position (meters)
|
||||
double x;
|
||||
/// Y Position (meters)
|
||||
double y;
|
||||
/// Perceived Pitch based on GPS + IMU
|
||||
double pitch;
|
||||
/// Perceived Roll based on GPS + IMU
|
||||
double roll;
|
||||
/// Perceived Yaw based on GPS + IMU
|
||||
double yaw;
|
||||
} gps_status_s_t;
|
||||
|
||||
/**
|
||||
* \struct gps_orientation_s_t
|
||||
*/
|
||||
typedef struct __attribute__((__packed__)) gps_orientation_s {
|
||||
/// Perceived Pitch based on GPS + IMU
|
||||
double pitch;
|
||||
/// Perceived Roll based on GPS + IMU
|
||||
double roll;
|
||||
/// Perceived Yaw based on GPS + IMU
|
||||
double yaw;
|
||||
} gps_orientation_s_t;
|
||||
|
||||
|
||||
/**
|
||||
* \struct gps_raw_s
|
||||
*/
|
||||
struct gps_raw_s {
|
||||
/// Perceived Pitch based on GPS + IMU
|
||||
double x;
|
||||
/// Perceived Roll based on GPS + IMU
|
||||
double y;
|
||||
/// Perceived Yaw based on GPS + IMU
|
||||
double z;
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct gps_accel_s_t
|
||||
*
|
||||
*/
|
||||
typedef struct gps_raw_s gps_accel_s_t;
|
||||
|
||||
/**
|
||||
* \struct gps_gyro_s_t
|
||||
*
|
||||
*/
|
||||
typedef struct gps_raw_s gps_gyro_s_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace c {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Set the GPS's offset relative to the center of turning in meters,
|
||||
* as well as its initial position.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
* \param xOffset
|
||||
* Cartesian 4-Quadrant X offset from center of turning (meters)
|
||||
* \param yOffset
|
||||
* Cartesian 4-Quadrant Y offset from center of turning (meters)
|
||||
* \param xInitial
|
||||
* Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters)
|
||||
* \param yInitial
|
||||
* Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters)
|
||||
* \param headingInitial
|
||||
* Heading with 0 being north on the field, in degrees [0,360) going clockwise
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
* #define X_OFFSET .225
|
||||
* #define Y_OFFSET .223
|
||||
* #define X_INITIAL 1.54
|
||||
* #define Y_INITIAL 1.14
|
||||
* #define HEADING_INITIAL 90
|
||||
*
|
||||
* void initialize() {
|
||||
* gps_initialize_full(GPS_PORT, X_OFFSET, Y_OFFSET, X_INITIAL, Y_INITIAL, HEADING_INITIAL);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t gps_initialize_full(uint8_t port, double xInitial, double yInitial, double headingInitial, double xOffset,
|
||||
double yOffset);
|
||||
|
||||
/**
|
||||
* Set the GPS's offset relative to the center of turning in meters.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
* \param xOffset
|
||||
* Cartesian 4-Quadrant X offset from center of turning (meters)
|
||||
* \param yOffset
|
||||
* Cartesian 4-Quadrant Y offset from center of turning (meters)
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
* #define X_OFFSET -.225
|
||||
* #define Y_OFFSET .225
|
||||
*
|
||||
* void initialize() {
|
||||
* gps_set_offset(GPS_PORT, X_OFFSET, Y_OFFSET);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t gps_set_offset(uint8_t port, double xOffset, double yOffset);
|
||||
|
||||
/**
|
||||
* Get the GPS's cartesian location relative to the center of turning/origin in meters.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
* \return A struct (gps_position_s_t) containing the X and Y values if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* gps_position_s_t pos;
|
||||
*
|
||||
* while (true) {
|
||||
* pos = gps_get_offset(GPS_PORT);
|
||||
* screen_print(TEXT_MEDIUM, 1, "X Offset: %4d, Y Offset: %4d", pos.x, pos.y);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
gps_position_s_t gps_get_offset(uint8_t port);
|
||||
|
||||
/**
|
||||
* Sets the robot's location relative to the center of the field in meters.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
* \param xInitial
|
||||
* Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters)
|
||||
* \param yInitial
|
||||
* Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters)
|
||||
* \param headingInitial
|
||||
* Heading with 0 being north on the field, in degrees [0,360) going clockwise
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
* #define X_INITIAL -1.15
|
||||
* #define Y_INITIAL 1.45
|
||||
* #define HEADING_INITIAL 90
|
||||
*
|
||||
* void initialize() {
|
||||
* gps_set_position(GPS_PORT, X_INITIAL, Y_INITIAL, HEADING_INITIAL);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t gps_set_position(uint8_t port, double xInitial, double yInitial, double headingInitial);
|
||||
|
||||
/**
|
||||
* Set the GPS sensor's data rate in milliseconds, only applies to IMU on GPS.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
* \param rate
|
||||
* Data rate in milliseconds (Minimum: 5 ms)
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
* #define GPS_DATA_RATE 5
|
||||
*
|
||||
* void initialize() {
|
||||
* gps_set_data_rate(GPS_PORT, GPS_DATA_RATE);
|
||||
* while (true) {
|
||||
* // Do something
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t gps_set_data_rate(uint8_t port, uint32_t rate);
|
||||
|
||||
/**
|
||||
* Get the possible RMS (Root Mean Squared) error in meters for GPS position.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
*
|
||||
* \return Possible RMS (Root Mean Squared) error in meters for GPS position.
|
||||
* If the operation failed, returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* double error;
|
||||
* error = gps_get_error(GPS_PORT);
|
||||
* screen_print(TEXT_MEDIUM, 1, "Error: %4d", error);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double gps_get_error(uint8_t port);
|
||||
|
||||
/**
|
||||
* Gets the position and roll, yaw, and pitch of the GPS.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
*
|
||||
* \return A struct (gps_status_s_t) containing values mentioned above.
|
||||
* If the operation failed, all the structure's members are filled with
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* gps_status_s_t status;
|
||||
*
|
||||
* while (true) {
|
||||
* status = gps_get_position_and_orientation(GPS_PORT);
|
||||
* printf("X: %f, Y: %f, Pitch: %f, Roll: %f, Yaw: %f\n", status.x, status.y, status.pitch, status.roll, status.yaw);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
gps_status_s_t gps_get_position_and_orientation(uint8_t port);
|
||||
|
||||
/**
|
||||
* Gets the x and y position on the field of the GPS in meters.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
*
|
||||
* \return A struct (gps_position_s_t) containing values mentioned above.
|
||||
* If the operation failed, all the structure's members are filled with
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* gps_position_s_t position;
|
||||
*
|
||||
* while (true) {
|
||||
* position = gps_get_position(GPS_PORT);
|
||||
* printf("X: %f, Y: %f\n", position.x, position.y);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
gps_position_s_t gps_get_position(uint8_t port);
|
||||
|
||||
/**
|
||||
* Gets the X position in meters of the robot relative to the starting position.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
*
|
||||
* \return The X position in meters. If the operation failed,
|
||||
* returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* double pos_x;
|
||||
*
|
||||
* while (true) {
|
||||
* pos_x = gps_get_position_x(GPS_PORT);
|
||||
* printf("X: %f\n", pos_x);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double gps_get_position_x(uint8_t port);
|
||||
|
||||
/**
|
||||
* Gets the Y position in meters of the robot relative to the starting position.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
*
|
||||
* \return The Y position in meters. If the operation failed,
|
||||
* returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* double pos_y;
|
||||
*
|
||||
* while (true) {
|
||||
* pos_y = gps_get_position_y(GPS_PORT);
|
||||
* printf("Y: %f\n", pos_y);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double gps_get_position_y(uint8_t port);
|
||||
|
||||
/**
|
||||
* Gets the pitch, roll, and yaw of the GPS relative to the starting orientation.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
*
|
||||
* \return A struct (gps_orientation_s_t) containing values mentioned above.
|
||||
* If the operation failed, all the structure's members are filled with
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* gps_orientation_s_t orientation;
|
||||
*
|
||||
* while (true) {
|
||||
* orientation = gps_get_orientation(GPS_PORT);
|
||||
* printf("pitch: %f, roll: %f, yaw: %f\n", orientation.pitch, orientation.roll, orientation.yaw);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
gps_orientation_s_t gps_get_orientation(uint8_t port);
|
||||
|
||||
/**
|
||||
* Gets the pitch of the robot in degrees relative to the starting oreintation.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
*
|
||||
* \return The pitch in [0,360) degree values. If the operation failed,
|
||||
* returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* double pitch;
|
||||
*
|
||||
* while (true) {
|
||||
* pitch = gps_get_pitch(GPS_PORT);
|
||||
* printf("pitch: %f\n", pitch);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double gps_get_pitch(uint8_t port);
|
||||
|
||||
/**
|
||||
* Gets the roll of the robot in degrees relative to the starting oreintation.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
*
|
||||
* \return The roll in [0,360) degree values. If the operation failed,
|
||||
* returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* double roll;
|
||||
*
|
||||
* while (true) {
|
||||
* roll = gps_get_roll(GPS_PORT);
|
||||
* printf("roll: %f\n", roll);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double gps_get_roll(uint8_t port);
|
||||
|
||||
/**
|
||||
* Gets the yaw of the robot in degrees relative to the starting oreintation.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
*
|
||||
* \return The yaw in [0,360) degree values. If the operation failed,
|
||||
* returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* double yaw;
|
||||
*
|
||||
* while (true) {
|
||||
* yaw = gps_get_yaw(GPS_PORT);
|
||||
* printf("yaw: %f\n", yaw);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double gps_get_yaw(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the heading in [0,360) degree values.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
*
|
||||
* \return The heading in [0,360) degree values. If the operation failed,
|
||||
* returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* double heading;
|
||||
*
|
||||
* while (true) {
|
||||
* heading = gps_get_heading(GPS_PORT);
|
||||
* printf("heading: %f\n", heading);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double gps_get_heading(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the heading in the max double value and min double value scale.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
*
|
||||
* \return The heading in [DOUBLE_MIN, DOUBLE_MAX] values. If the operation
|
||||
* fails, returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* double heading_raw;
|
||||
*
|
||||
* while (true) {
|
||||
* heading_raw = gps_get_heading_raw(GPS_PORT);
|
||||
* printf("heading_raw: %f\n", heading_raw);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double gps_get_heading_raw(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the GPS's raw gyroscope values
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
* \return A struct (gps_gyro_s_t) containing values mentioned above.
|
||||
* If the operation failed, all the
|
||||
* structure's members are filled with PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* gps_gyro_s_t gyro;
|
||||
*
|
||||
* while (true) {
|
||||
* gyro = gps_get_gyro(GPS_PORT);
|
||||
* printf("Gyro: %f %f %f\n", gyro.x, gyro.y, gyro.z);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
gps_gyro_s_t gps_get_gyro_rate(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the GPS's raw gyroscope value in x-axis
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
* \return The raw gyroscope value in x-axis. If the operation fails, returns
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* double gyro_x;
|
||||
*
|
||||
* while (true) {
|
||||
* gyro_x = gps_get_gyro_x(GPS_PORT);
|
||||
* printf("gyro_x: %f\n", gyro_x);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double gps_get_gyro_rate_x(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the GPS's raw gyroscope value in y-axis
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
* \return The raw gyroscope value in y-axis. If the operation fails, returns
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* double gyro_y;
|
||||
*
|
||||
* while (true) {
|
||||
* gyro_y = gps_get_gyro_y(GPS_PORT);
|
||||
* printf("gyro_y: %f\n", gyro_y);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double gps_get_gyro_rate_y(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the GPS's raw gyroscope value in z-axis
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
* \return The raw gyroscope value in z-axis. If the operation fails, returns
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* double gyro_z;
|
||||
*
|
||||
* while (true) {
|
||||
* gyro_z = gps_get_gyro_z(GPS_PORT);
|
||||
* printf("gyro_z: %f\n", gyro_z);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double gps_get_gyro_rate_z(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the GPS's raw accelerometer values
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS's port number from 1-21
|
||||
* \return A struct (gps_accel_s_t) containing values mentioned above.
|
||||
* If the operation failed, all the
|
||||
* structure's members are filled with PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* gps_accel_s_t accel;
|
||||
*
|
||||
* while (true) {
|
||||
* accel = gps_get_accel(GPS_PORT);
|
||||
* printf("X: %f, Y: %f, Z: %f\n", accel.x, accel.y, accel.z);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
gps_accel_s_t gps_get_accel(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the GPS's raw accelerometer value in x-axis
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS's port number from 1-21
|
||||
* \return The raw accelerometer value in x-axis. If the operation fails, returns
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* double accel_x;
|
||||
*
|
||||
* while (true) {
|
||||
* accel_x = gps_get_accel_x(GPS_PORT);
|
||||
* printf("accel_x: %f\n", accel_x);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double gps_get_accel_x(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the GPS's raw accelerometer value in y-axis
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS's port number from 1-21
|
||||
* \return The raw accelerometer value in y-axis. If the operation fails, returns
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* double accel_y;
|
||||
*
|
||||
* while (true) {
|
||||
* accel_y = gps_get_accel_y(GPS_PORT);
|
||||
* printf("accel_y: %f\n", accel_y);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double gps_get_accel_y(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the GPS's raw accelerometer value in z-axis
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS's port number from 1-21
|
||||
* \return The raw accelerometer value in z-axis. If the operation fails, returns
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* double accel_z;
|
||||
*
|
||||
* while (true) {
|
||||
* accel_z = gps_get_accel_z(GPS_PORT);
|
||||
* printf("accel_z: %f\n", accel_z);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double gps_get_accel_z(uint8_t port);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,937 @@
|
||||
/**
|
||||
* \file pros/gps.hpp
|
||||
* \ingroup cpp-gps
|
||||
*
|
||||
* Contains prototypes for functions related to the VEX GPS.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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/.
|
||||
*
|
||||
* \defgroup cpp-gps VEX GPS Sensor C API
|
||||
* \note For a pros-specific usage guide on the GPS, please check out our article [here.](@ref gps)
|
||||
*/
|
||||
|
||||
#ifndef _PROS_GPS_HPP_
|
||||
#define _PROS_GPS_HPP_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
#include "pros/device.hpp"
|
||||
#include "pros/gps.h"
|
||||
|
||||
namespace pros {
|
||||
inline namespace v5 {
|
||||
/**
|
||||
* \ingroup cpp-gps
|
||||
* @{
|
||||
*/
|
||||
class Gps : public Device {
|
||||
/**
|
||||
* \addtogroup cpp-gps
|
||||
* @{
|
||||
*/
|
||||
|
||||
public:
|
||||
/**
|
||||
* Creates a GPS 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \b Example:
|
||||
* \code
|
||||
* pros::Gps gps(1);
|
||||
* \endcode
|
||||
*
|
||||
*/
|
||||
Gps(const std::uint8_t port) : Device(port, DeviceType::gps){};
|
||||
|
||||
Gps(const Device& device) : Gps(device.get_port()){};
|
||||
|
||||
/**
|
||||
* Creates a GPS 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param xInitial
|
||||
* Cartesian 4-Quadrant X initial position (meters)
|
||||
* \param yInitial
|
||||
* Cartesian 4-Quadrant Y initial position (meters)
|
||||
* \param headingInitial
|
||||
* Initial heading (degrees)
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* pros::Gps gps(1, 1.30, 1.20, 90);
|
||||
* \endcode
|
||||
*
|
||||
*/
|
||||
explicit Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial)
|
||||
: Device(port, DeviceType::gps) {
|
||||
pros::c::gps_set_position(port, xInitial, yInitial, headingInitial);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a GPS 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param xOffset
|
||||
* Cartesian 4-Quadrant X offset from center of turning (meters)
|
||||
* \param yOffset
|
||||
* Cartesian 4-Quadrant Y offset from center of turning (meters)
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* pros::Gps gps(1, 1.30, 1.20);
|
||||
* \endcode
|
||||
*
|
||||
*/
|
||||
explicit Gps(const std::uint8_t port, double xOffset, double yOffset) : Device(port, DeviceType::gps) {
|
||||
pros::c::gps_set_offset(port, xOffset, yOffset);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a GPS 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param xInitial
|
||||
* Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters)
|
||||
* \param yInitial
|
||||
* Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters)
|
||||
* \param headingInitial
|
||||
* Initial Heading, with 0 being North, 90 being East, 180 being South, and 270 being West (degrees)
|
||||
* \param xOffset
|
||||
* Cartesian 4-Quadrant X offset from center of turning (meters)
|
||||
* \param yOffset
|
||||
* Cartesian 4-Quadrant Y offset from center of turning (meters)
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* pros::Gps gps(1, 1.30, 1.20, 180, 1.30, 1.20);
|
||||
* \endcode
|
||||
*
|
||||
*/
|
||||
explicit Gps(const std::uint8_t port, double xInitial, double yInitial, double headingInitial, double xOffset,
|
||||
double yOffset)
|
||||
: Device(port, DeviceType::gps) {
|
||||
pros::c::gps_initialize_full(port, xInitial, yInitial, headingInitial, xOffset, yOffset);
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the GPS's offset relative to the center of turning in meters,
|
||||
* as well as its initial position.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param xOffset
|
||||
* Cartesian 4-Quadrant X offset from center of turning (meters)
|
||||
* \param yOffset
|
||||
* Cartesian 4-Quadrant Y offset from center of turning (meters)
|
||||
* \param xInitial
|
||||
* Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters)
|
||||
* \param yInitial
|
||||
* Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters)
|
||||
* \param headingInitial
|
||||
* Heading with 0 being north on the field, in degrees [0,360) going clockwise
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT, 1.1, 1.2, 180, .4, .4);
|
||||
* // this is equivalent to the above line
|
||||
* gps.initialize_full(1.1, 1.2, 180, .4, .4);
|
||||
* while (true) {
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t initialize_full(double xInitial, double yInitial, double headingInitial, double xOffset,
|
||||
double yOffset) const;
|
||||
|
||||
/**
|
||||
* Set the GPS's offset relative to the center of turning in meters.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param xOffset
|
||||
* Cartesian 4-Quadrant X offset from center of turning (meters)
|
||||
* \param yOffset
|
||||
* Cartesian 4-Quadrant Y offset from center of turning (meters)
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT, 1.1, 1.2, 180, .4, .4);
|
||||
* // this is equivalent to the above line
|
||||
* gps.set_offset(.4, .4);
|
||||
* while (true) {
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t set_offset(double xOffset, double yOffset) const;
|
||||
|
||||
/**
|
||||
|
||||
* Gets all GPS sensors.
|
||||
*
|
||||
* \return A vector of Gps sensor objects.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* std::vector<Gps> gps_all = pros::Gps::get_all_devices(); // All GPS sensors that are connected
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
static std::vector<Gps> get_all_devices();
|
||||
|
||||
/**
|
||||
* Get the GPS's cartesian location relative to the center of turning/origin in meters.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 GPS port number from 1-21
|
||||
* \return A struct (gps_position_s_t) containing the X and Y values if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* gps_position_s_t pos;
|
||||
* Gps gps(GPS_PORT);
|
||||
* while (true) {
|
||||
* pos = gps.get_offset();
|
||||
* screen_print(TEXT_MEDIUM, 1, "X Offset: %4d, Y Offset: %4d", pos.x, pos.y);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual pros::gps_position_s_t get_offset() const;
|
||||
|
||||
/**
|
||||
* Sets the robot's location relative to the center of the field in meters.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param xInitial
|
||||
* Initial 4-Quadrant X Position, with (0,0) being at the center of the field (meters)
|
||||
* \param yInitial
|
||||
* Initial 4-Quadrant Y Position, with (0,0) being at the center of the field (meters)
|
||||
* \param headingInitial
|
||||
* Heading with 0 being north on the field, in degrees [0,360) going clockwise
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* gps.set_position(1.3, 1.4, 180);
|
||||
* while (true) {
|
||||
* printf("X: %f, Y: %f, Heading: %f\n", gps.get_position().x,
|
||||
* gps.get_position().y, gps.get_position().heading);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t set_position(double xInitial, double yInitial, double headingInitial) const;
|
||||
|
||||
/**
|
||||
* Set the GPS sensor's data rate in milliseconds, only applies to IMU on GPS.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param rate
|
||||
* Data rate in milliseconds (Minimum: 5 ms)
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* gps.set_data_rate(10);
|
||||
* while (true) {
|
||||
* printf("X: %f, Y: %f, Heading: %f\n", gps.get_position().x,
|
||||
* gps.get_position().y, gps.get_position().heading);
|
||||
* delay(10);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t set_data_rate(std::uint32_t rate) const;
|
||||
|
||||
/**
|
||||
* Get the possible RMS (Root Mean Squared) error in meters for GPS position.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return Possible RMS (Root Mean Squared) error in meters for GPS position.
|
||||
* If the operation failed, returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* double error = gps.get_error();
|
||||
* printf("Error: %f\n", error);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_error() const;
|
||||
|
||||
/**
|
||||
* Gets the position and roll, yaw, and pitch of the GPS.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
*
|
||||
* \return A struct (gps_status_s_t) containing values mentioned above.
|
||||
* If the operation failed, all the structure's members are filled with
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* gps_status_s_t status;
|
||||
* while (true) {
|
||||
* status = gps.get_position_and_orientation();
|
||||
* printf("X: %f, Y: %f, Roll: %f, Pitch: %f, Yaw: %f\n",
|
||||
* status.x, status.y, status.roll, status.pitch, status.yaw);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual pros::gps_status_s_t get_position_and_orientation() const;
|
||||
|
||||
/**
|
||||
* Gets the x and y position on the field of the GPS in meters.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return A struct (gps_position_s_t) containing values mentioned above.
|
||||
* If the operation failed, all the structure's members are filled with
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* gps_position_s_t position;
|
||||
* while (true) {
|
||||
* position = gps.get_position();
|
||||
* printf("X: %f, Y: %f\n", position.x, position.y);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual pros::gps_position_s_t get_position() const;
|
||||
|
||||
/**
|
||||
* Gets the X position in meters of the robot relative to the starting position.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return The X position in meters. If the operation failed,
|
||||
* returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* double pos_x = gps.get_position_x();
|
||||
* printf("X: %f\n", pos_x);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_position_x() const;
|
||||
|
||||
/**
|
||||
* Gets the Y position in meters of the robot relative to the starting position.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return The Y position in meters. If the operation failed,
|
||||
* returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* double pos_y = gps.get_position_y();
|
||||
* printf("Y: %f\n", pos_y);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_position_y() const;
|
||||
|
||||
/**
|
||||
* Gets the pitch, roll, and yaw of the GPS relative to the starting orientation.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return A struct (gps_orientation_s_t) containing values mentioned above.
|
||||
* If the operation failed, all the structure's members are filled with
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* gps_orientation_s_t orientation;
|
||||
* while (true) {
|
||||
* orientation = gps.get_orientation();
|
||||
* printf("pitch: %f, roll: %f, yaw: %f\n", orientation.pitch,
|
||||
* orientation.roll, orientation.yaw);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual pros::gps_orientation_s_t get_orientation() const;
|
||||
|
||||
/**
|
||||
* Gets the pitch of the robot in degrees relative to the starting oreintation.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return The pitch in [0,360) degree values. If the operation failed,
|
||||
* returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* double pitch = gps.get_pitch();
|
||||
* printf("pitch: %f\n", pitch);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_pitch() const;
|
||||
|
||||
/**
|
||||
* Gets the roll of the robot in degrees relative to the starting oreintation.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return The roll in [0,360) degree values. If the operation failed,
|
||||
* returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* double roll = gps.get_roll();
|
||||
* printf("roll: %f\n", roll);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_roll() const;
|
||||
|
||||
/**
|
||||
* Gets the yaw of the robot in degrees relative to the starting oreintation.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return The yaw in [0,360) degree values. If the operation failed,
|
||||
* returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* double yaw = gps.get_yaw();
|
||||
* printf("yaw: %f\n", yaw);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_yaw() const;
|
||||
|
||||
/**
|
||||
* Get the heading in [0,360) degree values.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
*
|
||||
* \return The heading in [0,360) degree values. If the operation failed,
|
||||
* returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* double heading = gps.get_heading();
|
||||
* printf("Heading: %f\n", heading);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_heading() const;
|
||||
|
||||
/**
|
||||
* Get the heading in the max double value and min double value scale.
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return The heading in [DOUBLE_MIN, DOUBLE_MAX] values. If the operation
|
||||
* fails, returns PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* double heading = gps.get_heading_raw();
|
||||
* printf("Heading: %f\n", heading);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_heading_raw() const;
|
||||
|
||||
/**
|
||||
* Get the GPS's raw gyroscope value in z-axis
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return The raw gyroscope value in z-axis. If the operation fails, returns
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
\b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* double gyro_z = gps.get_gyro_z();
|
||||
* printf("gyro_z: %f\n", gyro_z);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual pros::gps_gyro_s_t get_gyro_rate() const;
|
||||
|
||||
/**
|
||||
* Get the GPS's raw gyroscope value in x-axis
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return The raw gyroscope value in x-axis. If the operation fails, returns
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* double gyro_x = gps.get_gyro_x();
|
||||
* printf("gyro_x: %f\n", gyro_x);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_gyro_rate_x() const;
|
||||
|
||||
/**
|
||||
* Get the GPS's raw gyroscope value in y-axis
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return The raw gyroscope value in y-axis. If the operation fails, returns
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* double gyro_y = gps.get_gyro_y();
|
||||
* printf("gyro_y: %f\n", gyro_y);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_gyro_rate_y() const;
|
||||
|
||||
/**
|
||||
* Get the GPS's raw gyroscope value in z-axis
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return The raw gyroscope value in z-axis. If the operation fails, returns
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
\b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* double gyro_z = gps.get_gyro_z();
|
||||
* printf("gyro_z: %f\n", gyro_z);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_gyro_rate_z() const;
|
||||
|
||||
/**
|
||||
* Get the GPS's raw accelerometer values
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return The raw accelerometer values. If the operation failed, all the
|
||||
* structure's members are filled with PROS_ERR_F and errno is set.
|
||||
*/
|
||||
virtual pros::gps_accel_s_t get_accel() const;
|
||||
|
||||
/**
|
||||
* Get the GPS's raw accelerometer value in x-axis
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return The raw accelerometer value in x-axis. If the operation fails, returns
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* double accel_x = gps.get_accel_x();
|
||||
* printf("accel_x: %f\n", accel_x);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_accel_x() const;
|
||||
|
||||
/**
|
||||
* Get the GPS's raw accelerometer value in y-axis
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return The raw accelerometer value in y-axis. If the operation fails, returns
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* double accel_y = gps.get_accel_y();
|
||||
* printf("accel_y: %f\n", accel_y);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_accel_y() const;
|
||||
|
||||
/**
|
||||
* Get the GPS's raw accelerometer value in z-axis
|
||||
*
|
||||
* 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 GPS
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \return The raw accelerometer value in z-axis. If the operation fails, returns
|
||||
* PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* double accel_z = gps.get_accel_z();
|
||||
* printf("accel_z: %f\n", accel_z);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual double get_accel_z() const;
|
||||
|
||||
/**
|
||||
* This is the overload for the << operator for printing to streams
|
||||
*
|
||||
* Prints in format:
|
||||
* Gps [port: gps._port, x: (x position), y: (y position), heading: (gps heading), rotation: (gps rotation)]
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define GPS_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Gps gps(GPS_PORT);
|
||||
* while(true) {
|
||||
* std::cout << gps << std::endl;
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& os, const pros::Gps& gps);
|
||||
|
||||
/**
|
||||
* Gets a gps sensor that is plugged in to the brain
|
||||
*
|
||||
* \note The first time this function is called it returns the gps sensor at the lowest port
|
||||
* If this function is called multiple times, it will cycle through all the ports.
|
||||
* For example, if you have 1 gps sensor on the robot
|
||||
* this function will always return a gps sensor object for that port.
|
||||
* If you have 2 gps sensors, all the odd numered calls to this function will return objects
|
||||
* for the lower port number,
|
||||
* all the even number calls will return gps objects for the higher port number
|
||||
*
|
||||
*
|
||||
* This functions uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - No gps sensor is plugged into the brain
|
||||
*
|
||||
* \return A gps object corresponding to a port that a gps sensor is connected to the brain
|
||||
* If no gps sensor is plugged in, it returns a gps sensor on port PROS_ERR_BYTE
|
||||
*
|
||||
*/
|
||||
static Gps get_gps();
|
||||
///@}
|
||||
}; // Gps Class
|
||||
|
||||
namespace literals {
|
||||
/**
|
||||
* Constructs a Gps object with the given port number
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* using namespace literals;
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::Gps gps = 1_gps;
|
||||
* while (true) {
|
||||
* pos = gps.get_position();
|
||||
* screen_print(TEXT_MEDIUM, 1, "X Position: %4d, Y Position: %4d", pos.x, pos.y);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
const pros::Gps operator""_gps(const unsigned long long int g);
|
||||
} // namespace literals
|
||||
|
||||
/// @brief
|
||||
/// Alias for Gps is GPS for user convenience.
|
||||
using GPS = Gps;
|
||||
|
||||
} // namespace v5
|
||||
} // namespace pros
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,974 @@
|
||||
/**
|
||||
* \file pros/imu.h
|
||||
* \ingroup c-imu
|
||||
*
|
||||
* Contains prototypes for functions related to the VEX Inertial sensor.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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/.
|
||||
*
|
||||
* \defgroup c-imu VEX Inertial Sensor C API
|
||||
*/
|
||||
|
||||
#ifndef _PROS_IMU_H_
|
||||
#define _PROS_IMU_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
namespace pros {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \ingroup c-imu
|
||||
* */
|
||||
|
||||
/**
|
||||
* \addtogroup c-imu
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \enum imu_status_e_t
|
||||
* @brief Indicates IMU status.
|
||||
*/
|
||||
typedef enum imu_status_e {
|
||||
E_IMU_STATUS_READY = 0, // IMU is connected but not currently calibrating
|
||||
/** The IMU is calibrating */
|
||||
E_IMU_STATUS_CALIBRATING = 1,
|
||||
/** Used to indicate that an error state was reached in the imu_get_status function,\
|
||||
not that the IMU is necessarily in an error state */
|
||||
E_IMU_STATUS_ERROR = 0xFF,
|
||||
} imu_status_e_t;
|
||||
|
||||
typedef enum imu_orientation_e {
|
||||
E_IMU_Z_UP = 0, // IMU has the Z axis UP (VEX Logo facing DOWN)
|
||||
E_IMU_Z_DOWN = 1, // IMU has the Z axis DOWN (VEX Logo facing UP)
|
||||
E_IMU_X_UP = 2, // IMU has the X axis UP
|
||||
E_IMU_X_DOWN = 3, // IMU has the X axis DOWN
|
||||
E_IMU_Y_UP = 4, // IMU has the Y axis UP
|
||||
E_IMU_Y_DOWN = 5, // IMU has the Y axis DOWN
|
||||
E_IMU_ORIENTATION_ERROR = 0xFF // NOTE: used for returning an error from the get_physical_orientation function, not
|
||||
// that the IMU is necessarily in an error state
|
||||
} imu_orientation_e_t;
|
||||
|
||||
/**
|
||||
* \struct quaternion_s_t
|
||||
*/
|
||||
typedef struct __attribute__((__packed__)) quaternion_s {
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
double w;
|
||||
} quaternion_s_t;
|
||||
|
||||
/**
|
||||
* \struct imu_raw_s
|
||||
*
|
||||
*/
|
||||
struct imu_raw_s {
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
};
|
||||
|
||||
/**
|
||||
* \struct imu_gyro_s_t
|
||||
*
|
||||
*/
|
||||
typedef struct imu_raw_s imu_gyro_s_t;
|
||||
|
||||
/**
|
||||
* \struct imu_accel_s_t
|
||||
*
|
||||
*/
|
||||
typedef struct imu_raw_s imu_accel_s_t;
|
||||
|
||||
/**
|
||||
* \struct euler_s_t
|
||||
*
|
||||
*/
|
||||
typedef struct __attribute__((__packed__)) euler_s {
|
||||
double pitch;
|
||||
double roll;
|
||||
double yaw;
|
||||
} euler_s_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace c {
|
||||
#endif
|
||||
/**
|
||||
* \def IMU_MINIMUM_DATA_RATE
|
||||
*/
|
||||
#ifdef PROS_USE_SIMPLE_NAMES
|
||||
#ifdef __cplusplus
|
||||
#define IMU_STATUS_CALIBRATING pros::E_IMU_STATUS_CALIBRATING
|
||||
#define IMU_STATUS_ERROR pros::E_IMU_STATUS_ERROR
|
||||
#else
|
||||
#define IMU_STATUS_CALIBRATING E_IMU_STATUS_CALIBRATING
|
||||
#define IMU_STATUS_ERROR E_IMU_STATUS_ERROR
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define IMU_MINIMUM_DATA_RATE 5
|
||||
|
||||
/**
|
||||
* Calibrate IMU
|
||||
*
|
||||
* Calibration takes approximately 2 seconds, but this function only blocks
|
||||
* until the IMU status flag is set properly to E_IMU_STATUS_CALIBRATING,
|
||||
* with a minimum blocking time of 5ms.
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is already calibrating, or time out setting the status flag.
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* imu_reset(IMU_PORT);
|
||||
* int time = millis();
|
||||
* int iter = 0;
|
||||
* while (imu_get_status(IMU_PORT) & E_IMU_STATUS_CALIBRATING) {
|
||||
* printf("IMU calibrating... %d\n", iter);
|
||||
* iter += 10;
|
||||
* delay(10);
|
||||
* }
|
||||
* // should print about 2000 ms
|
||||
* printf("IMU is done calibrating (took %d ms)\n", iter - time);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_reset(uint8_t port);
|
||||
|
||||
/**
|
||||
* Calibrate IMU and Blocks while Calibrating
|
||||
*
|
||||
* Calibration takes approximately 2 seconds and blocks during this period,
|
||||
* with a timeout for this operation being set a 3 seconds as a safety margin.
|
||||
* Like the other reset function, this function also blocks until the IMU
|
||||
* status flag is set properly to E_IMU_STATUS_CALIBRATING, with a minimum
|
||||
* blocking time of 5ms and a timeout of 1 second if it's never set.
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is already calibrating, or time out setting the status flag.
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed (timing out or port claim failure), setting errno.
|
||||
*/
|
||||
int32_t imu_reset_blocking(uint8_t port);
|
||||
/**
|
||||
* Set the Inertial Sensor's refresh interval in milliseconds.
|
||||
*
|
||||
* The rate may be specified in increments of 5ms, and will be rounded down to
|
||||
* the nearest increment. The minimum allowable refresh rate is 5ms. The default
|
||||
* rate is 10ms.
|
||||
*
|
||||
* As values are copied into the shared memory buffer only at 10ms intervals,
|
||||
* setting this value to less than 10ms does not mean that you can poll the
|
||||
* sensor's values any faster. However, it will guarantee that the data is as
|
||||
* recent as possible.
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \param rate The data refresh interval in milliseconds
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
*
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_set_data_rate(uint8_t port, uint32_t rate);
|
||||
|
||||
/**
|
||||
* Get the total number of degrees the Inertial Sensor has spun about the z-axis
|
||||
*
|
||||
* This value is theoretically unbounded. Clockwise rotations are represented
|
||||
* with positive degree values, while counterclockwise rotations are represented
|
||||
* with negative ones.
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return The degree value or PROS_ERR_F if the operation failed, setting
|
||||
* errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("IMU get rotation: %f degrees\n", imu_get_rotation(IMU_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double imu_get_rotation(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the Inertial Sensor's heading relative to the initial direction of its
|
||||
* x-axis
|
||||
*
|
||||
* This value is bounded by [0,360). Clockwise rotations are represented with
|
||||
* positive degree values, while counterclockwise rotations are represented with
|
||||
* negative ones.
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return The degree value or PROS_ERR_F if the operation failed, setting
|
||||
* errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("IMU get heading: %f degrees\n", imu_get_heading(IMU_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double imu_get_heading(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get a quaternion representing the Inertial Sensor's orientation
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return The quaternion representing the sensor's orientation. If the
|
||||
* operation failed, all the quaternion's members are filled with PROS_ERR_F and
|
||||
* errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* quaternion_s_t qt = imu_get_quaternion(IMU_PORT);
|
||||
* printf("IMU quaternion: {x: %f, y: %f, z: %f, w: %f}\n", qt.x, qt.y, qt.z, qt.w);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
quaternion_s_t imu_get_quaternion(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the Euler angles representing the Inertial Sensor's orientation
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return The Euler angles representing the sensor's orientation. If the
|
||||
* operation failed, all the structure's members are filled with PROS_ERR_F and
|
||||
* errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* euler_s_t eu = imu_get_euler(IMU_PORT);
|
||||
* printf("IMU euler angles: {pitch: %f, roll: %f, yaw: %f}\n", eu.pitch, eu.roll, eu.yaw);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
euler_s_t imu_get_euler(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the Inertial Sensor's raw gyroscope values
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return The pitch angle, or PROS_ERR_F if the operation failed, setting
|
||||
* errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("IMU pitch: %f\n", imu_get_pitch(IMU_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
imu_gyro_s_t imu_get_gyro_rate(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the Inertial Sensor's raw acceleroneter values
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return The roll angle, or PROS_ERR_F if the operation failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("IMU roll: %f\n", imu_get_roll(IMU_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
imu_accel_s_t imu_get_accel(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the Inertial Sensor's status
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return The yaw angle, or PROS_ERR_F if the operation failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("IMU yaw: %f\n", imu_get_yaw(IMU_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
imu_status_e_t imu_get_status(uint8_t port);
|
||||
|
||||
// Value set functions:
|
||||
/**
|
||||
* Sets the current reading of the Inertial Sensor's euler values to
|
||||
* target euler values. Will default to +/- 180 if target exceeds +/- 180.
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return The raw gyroscope values. If the operation failed, all the
|
||||
* structure's members are filled with PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* int32_t val = imu_set_euler(IMU_PORT, {45, 60, 90});
|
||||
* printf("IMU : {gyro vals: %d}\n", val);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_set_euler(uint8_t port, euler_s_t target);
|
||||
|
||||
/**
|
||||
* Get the Inertial Sensor's pitch angle bounded by (-180,180)
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return The raw accelerometer values. If the operation failed, all the
|
||||
* structure's members are filled with PROS_ERR_F and errno is set.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* imu_accel_s_t accel = imu_get_accel(IMU_PORT);
|
||||
* printf("IMU accel values: {x: %f, y: %f, z: %f}\n", accel.x, accel.y, accel.z);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double imu_get_pitch(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the Inertial Sensor's roll angle bounded by (-180,180)
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return The Inertial Sensor's status code, or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* imu_reset(IMU_PORT);
|
||||
* int time = millis();
|
||||
* int iter = 0;
|
||||
* while (imu_get_status(IMU_PORT) & E_IMU_STATUS_CALIBRATING) {
|
||||
* printf("IMU calibrating... %d\n", iter);
|
||||
* iter += 10;
|
||||
* delay(10);
|
||||
* }
|
||||
* // should print about 2000 ms
|
||||
* printf("IMU is done calibrating (took %d ms)\n", iter - time);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double imu_get_roll(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the Inertial Sensor's yaw angle bounded by (-180,180)
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return The yaw angle, or PROS_ERR_F if the operation failed, setting errno.
|
||||
*/
|
||||
double imu_get_yaw(uint8_t port);
|
||||
|
||||
// NOTE: not used
|
||||
// void imu_set_mode(uint8_t port, uint32_t mode);
|
||||
// uint32_t imu_get_mode(uint8_t port);
|
||||
|
||||
/**
|
||||
* \name Value Reset Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resets the current reading of the Inertial Sensor's heading to zero
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* imu_tare_heading(IMU_PORT);
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_tare_heading(uint8_t port);
|
||||
|
||||
/**
|
||||
* Resets the current reading of the Inertial Sensor's rotation to zero
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* imu_tare_rotation(IMU_PORT);
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_tare_rotation(uint8_t port);
|
||||
|
||||
/**
|
||||
* Resets the current reading of the Inertial Sensor's pitch to zero
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1void opcontrol() {
|
||||
* while (true) {
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* imu_tare_pitch(IMU_PORT);
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_tare_pitch(uint8_t port);
|
||||
|
||||
/**
|
||||
* Resets the current reading of the Inertial Sensor's roll to zero
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* imu_tare_roll(IMU_PORT);
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_tare_roll(uint8_t port);
|
||||
|
||||
/**
|
||||
* Resets the current reading of the Inertial Sensor's yaw to zero
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* imu_tare_yaw(IMU_PORT);
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_tare_yaw(uint8_t port);
|
||||
|
||||
/**
|
||||
* Reset all 3 euler values of the Inertial Sensor 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* imu_tare_euler(IMU_PORT);
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_tare_euler(uint8_t port);
|
||||
|
||||
/**
|
||||
* Resets all 5 values of the Inertial Sensor 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* imu_tare(IMU_PORT);
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_tare(uint8_t port);
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* \name Value Set Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sets the current reading of the Inertial Sensor's euler values to
|
||||
* target euler values. Will default to +/- 180 if target exceeds +/- 180.
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \param target
|
||||
* Target euler values for the euler values to be set to
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* imu_set_euler(IMU_PORT, {45,45,45});
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_set_euler(uint8_t port, euler_s_t target);
|
||||
|
||||
/**
|
||||
* Sets the current reading of the Inertial Sensor's rotation to target 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \param target
|
||||
* Target value for the rotation value to be set to
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* imu_set_rotation(IMU_PORT, 45);
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_set_rotation(uint8_t port, double target);
|
||||
|
||||
/**
|
||||
* Sets the current reading of the Inertial Sensor's heading to target value
|
||||
* Target will default to 360 if above 360 and default to 0 if below 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \param target
|
||||
* Target value for the heading value to be set to
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* imu_set_heading(IMU_PORT, 45);
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_set_heading(uint8_t port, double target);
|
||||
|
||||
/**
|
||||
* Sets the current reading of the Inertial Sensor's pitch to target value
|
||||
* Will default to +/- 180 if target exceeds +/- 180.
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \param target
|
||||
* Target value for the pitch value to be set to
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* imu_set_pitch(IMU_PORT, 45);
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_set_pitch(uint8_t port, double target);
|
||||
|
||||
/**
|
||||
* Sets the current reading of the Inertial Sensor's roll to target value
|
||||
* Will default to +/- 180 if target exceeds +/- 180.
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \param target
|
||||
* Target value for the roll value to be set to
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* imu_set_roll(IMU_PORT, 45);
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_set_roll(uint8_t port, double target);
|
||||
|
||||
/**
|
||||
* Sets the current reading of the Inertial Sensor's yaw to target value
|
||||
* Will default to +/- 180 if target exceeds +/- 180.
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
* EAGAIN - The sensor is still calibrating
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \param target
|
||||
* Target value for the yaw value to be set to
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define IMU_PORT 1void opcontrol() {
|
||||
*
|
||||
* while (true) {
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* imu_set_yaw(IMU_PORT, 45);
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t imu_set_yaw(uint8_t port, double target);
|
||||
|
||||
/**
|
||||
* Returns the physical orientation of the IMU
|
||||
*
|
||||
* 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 Inertial Sensor
|
||||
*
|
||||
* \param port
|
||||
* The V5 Inertial Sensor port number from 1-21
|
||||
* \returns The orientation of the Inertial Sensor or PROS_ERR if an error occured.
|
||||
*
|
||||
*/
|
||||
imu_orientation_e_t imu_get_physical_orientation(uint8_t port);
|
||||
|
||||
/** @} */
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,421 @@
|
||||
/**
|
||||
* \file pros/link.h
|
||||
* \ingroup c-link
|
||||
*
|
||||
* Contains prototypes for functions related to the robot to robot communications.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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/.
|
||||
*
|
||||
* \defgroup c-link VEX Link C API
|
||||
*/
|
||||
|
||||
#ifndef _PROS_LINK_H_
|
||||
#define _PROS_LINK_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
namespace pros {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \ingroup c-link
|
||||
* */
|
||||
|
||||
/**
|
||||
* \addtogroup c-link
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \enum link_type_e_t
|
||||
* \brief Enum for the type of link (TX or RX)
|
||||
*/
|
||||
typedef enum link_type_e {
|
||||
E_LINK_RECIEVER = 0, ///< Indicates that the radio is a reciever.
|
||||
E_LINK_TRANSMITTER, ///< Indicates that the link is a transmitter.
|
||||
E_LINK_RX = E_LINK_RECIEVER, ///< Alias for E_LINK_RECIEVER
|
||||
E_LINK_TX = E_LINK_TRANSMITTER ///< Alias for E_LINK_TRANSMITTER
|
||||
} link_type_e_t;
|
||||
|
||||
#ifdef PROS_USE_SIMPLE_NAMES
|
||||
#ifdef __cplusplus
|
||||
#define LINK_RECEIVER pros::E_LINK_RECEIVER
|
||||
#define LINK_TRANSMITTER pros::E_LINK_TRANSMITTER
|
||||
#define LINK_RX pros::E_LINK_RX
|
||||
#define LINK_TX pros::E_LINK_TX
|
||||
#else
|
||||
#define LINK_RECEIVER E_LINK_RECEIVER
|
||||
#define LINK_TRANSMITTER E_LINK_TRANSMITTER
|
||||
#define LINK_RX E_LINK_RX
|
||||
#define LINK_TX E_LINK_TX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/// @brief
|
||||
/// The maximum size of a link buffer
|
||||
#define LINK_BUFFER_SIZE 512
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace c {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initializes a link on a radio port, with an indicated type. There might be a
|
||||
* 1 to 2 second delay from when this function is called to when the link is initializes.
|
||||
* PROS currently only supports the use of one radio per brain.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
*
|
||||
* \param port
|
||||
* The port of the radio for the intended link.
|
||||
* \param link_id
|
||||
* Unique link ID in the form of a string, needs to be different from other links in
|
||||
* the area.
|
||||
* \param type
|
||||
* Indicates whether the radio link on the brain is a transmitter or receiver,
|
||||
* with the transmitter having double the transmitting bandwidth as the receiving
|
||||
* end (1040 bytes/s vs 520 bytes/s).
|
||||
*
|
||||
* \return PROS_ERR if initialization fails, 1 if the initialization succeeds.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define LINK_TRANSMITTER_PORT 1
|
||||
* #define LINK_ID "ROBOT1"
|
||||
*
|
||||
* void initialize() {
|
||||
* link_init(LINK_TRANSMITTER_PORT, LINK_ID, E_LINK_TRANSMITTER);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t link_init(uint8_t port, const char* link_id, link_type_e_t type);
|
||||
|
||||
/**
|
||||
* Initializes a link on a radio port, with an indicated type and the ability for
|
||||
* vexlink to override the controller radio. There might be a 1 to 2 second delay
|
||||
* from when this function is called to when the link is initializes.
|
||||
* PROS currently only supports the use of one radio per brain.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
*
|
||||
* \param port
|
||||
* The port of the radio for the intended link.
|
||||
* \param link_id
|
||||
* Unique link ID in the form of a string, needs to be different from other links in
|
||||
* the area.
|
||||
* \param type
|
||||
* Indicates whether the radio link on the brain is a transmitter or receiver,
|
||||
* with the transmitter having double the transmitting bandwidth as the receiving
|
||||
* end (1040 bytes/s vs 520 bytes/s).
|
||||
*
|
||||
* \return PROS_ERR if initialization fails, 1 if the initialization succeeds.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define LINK_PORT 1
|
||||
* #define LINK_ID "ROBOT1"
|
||||
*
|
||||
* void initialize() {
|
||||
* link_init(LINK_PORT, LINK_ID, E_LINK_TRANSMITTER);
|
||||
* link_init_override(LINK_PORT, LINK_ID, E_LINK_TRANSMITTER);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t link_init_override(uint8_t port, const char* link_id, link_type_e_t type);
|
||||
|
||||
/**
|
||||
* Checks if a radio link on a port is active or not.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
*
|
||||
* \param port
|
||||
* The port of the radio for the intended link.
|
||||
*
|
||||
* \return If a radio is connected to a port and it's connected to a link.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define LINK_TRANSMITTER_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* if (link_connected(LINK_TRANSMITTER_PORT)) {
|
||||
* screen_print(TEXT_MEDIUM, 1, "Link connected!");
|
||||
* }
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
bool link_connected(uint8_t port);
|
||||
|
||||
/**
|
||||
* Returns the bytes of data available to be read
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
*
|
||||
* \param port
|
||||
* The port of the radio for the intended link.
|
||||
*
|
||||
* \return PROS_ERR if port is not a link/radio, else the bytes available to be
|
||||
* read by the user.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define LINK_RECIVER_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* uint32_t receiveable_size = link_raw_receivable_size(LINK_RECIVER_PORT);
|
||||
* screen_print(TEXT_MEDIUM, 1, "link_raw_receiveable_size: %d", receiveable_size);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t link_raw_receivable_size(uint8_t port);
|
||||
|
||||
/**
|
||||
* Returns the bytes of data available in transmission buffer.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
*
|
||||
* \param port
|
||||
* The port of the radio for the intended link.
|
||||
*
|
||||
* \return PROS_ERR if port is not a link/radio,
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define LINK_TRANSMITTER_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* uint32_t transmittable_size = link_raw_transmittable_size(LINK_TRANSMITTER_PORT);
|
||||
* screen_print(TEXT_MEDIUM, 1, "link_raw_transmittable_size: %d", transmittable_size);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t link_raw_transmittable_size(uint8_t port);
|
||||
|
||||
/**
|
||||
* Send raw serial data through vexlink.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
* EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no
|
||||
* room in the FIFO buffer (queue) to transmit the data.
|
||||
* EINVAL - The data given is NULL
|
||||
*
|
||||
* \param port
|
||||
* The port of the radio for the intended link.
|
||||
* \param data
|
||||
* Buffer with data to send
|
||||
* \param data_size
|
||||
* Bytes of data to be read to the destination buffer
|
||||
*
|
||||
* \return PROS_ERR if port is not a link, and the successfully transmitted
|
||||
* data size if it succeeded.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define LINK_TRANSMITTER_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* char* data = "Hello!";
|
||||
* link_transmit_raw(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t link_transmit_raw(uint8_t port, void* data, uint16_t data_size);
|
||||
|
||||
/**
|
||||
* Receive raw serial data through vexlink.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
* EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer
|
||||
* or destination buffer.
|
||||
*
|
||||
* \param port
|
||||
* The port of the radio for the intended link.
|
||||
* \param dest
|
||||
* Destination buffer to read data to
|
||||
* \param data_size
|
||||
* Bytes of data to be read to the destination buffer
|
||||
*
|
||||
* \return PROS_ERR if port is not a link, and the successfully received
|
||||
* data size if it succeeded.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define LINK_RECIVER_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* char* result;
|
||||
* char* expected = "Hello!";
|
||||
* link_receive_raw(LINK_RECIVER_PORT, (void*)result, sizeof(*expected) * sizeof(expected));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t link_receive_raw(uint8_t port, void* dest, uint16_t data_size);
|
||||
|
||||
/**
|
||||
* Send packeted message through vexlink, with a checksum and start byte.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
* EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no
|
||||
* room in the FIFO buffer (queue) to transmit the data.
|
||||
* EINVAL - The data given is NULL
|
||||
*
|
||||
* \param port
|
||||
* The port of the radio for the intended link.
|
||||
* \param data
|
||||
* Buffer with data to send
|
||||
* \param data_size
|
||||
* Bytes of data to be read to the destination buffer
|
||||
*
|
||||
* \return PROS_ERR if port is not a link, and the successfully transmitted
|
||||
* data size if it succeeded.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define LINK_TRANSMITTER_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* char* data = "Hello!";
|
||||
* link_transmit(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t link_transmit(uint8_t port, void* data, uint16_t data_size);
|
||||
|
||||
/**
|
||||
* Receive packeted message through vexlink, with a checksum and start byte.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
* EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer
|
||||
* or destination buffer.
|
||||
* EBADMSG - Protocol error related to start byte, data size, or checksum.
|
||||
*
|
||||
* \param port
|
||||
* The port of the radio for the intended link.
|
||||
* \param dest
|
||||
* Destination buffer to read data to
|
||||
* \param data_size
|
||||
* Bytes of data to be read to the destination buffer
|
||||
*
|
||||
* \return PROS_ERR if port is not a link or protocol error, and the successfully
|
||||
* transmitted data size if it succeeded.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define LINK_RECIVER_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* char* result;
|
||||
* char* expected = "Hello!";
|
||||
* link_receive(LINK_RECIVER_PORT, (void*)result, sizeof(*expected) * sizeof(expected));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t link_receive(uint8_t port, void* dest, uint16_t data_size);
|
||||
|
||||
/**
|
||||
* Clear the receive buffer of the link, and discarding the data.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
*
|
||||
* \param port
|
||||
* The port of the radio for the intended link.
|
||||
*
|
||||
* \return PROS_ERR if port is not a link, and the successfully received
|
||||
* data size if it succeeded.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define LINK_TRANSMITTER_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* char* data = "Hello!";
|
||||
* link_transmit(LINK_TRANSMITTER_PORT, (void*)data, sizeof(*data) * sizeof(data));
|
||||
* link_clear_receive_buf(LINK_TRANSMITTER_PORT);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t link_clear_receive_buf(uint8_t port);
|
||||
|
||||
///@}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,283 @@
|
||||
/**
|
||||
* \file pros/link.hpp
|
||||
* \ingroup cpp-link
|
||||
*
|
||||
* Contains prototypes for functions related to robot to robot communications.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* Copyright (c) 2017-2021, 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/.
|
||||
*
|
||||
* \defgroup cpp-link VEX Link C++ API
|
||||
*/
|
||||
#ifndef _PROS_LINK_HPP_
|
||||
#define _PROS_LINK_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "pros/link.h"
|
||||
#include "pros/device.hpp"
|
||||
|
||||
namespace pros {
|
||||
/**
|
||||
* \ingroup cpp-link
|
||||
*/
|
||||
class Link : public Device {
|
||||
/**
|
||||
* \addtogroup cpp-link
|
||||
* ///@{
|
||||
*/
|
||||
private:
|
||||
|
||||
public:
|
||||
/**
|
||||
* Initializes a link on a radio port, with an indicated type. There might be a
|
||||
* 1 to 2 second delay from when this function is called to when the link is initializes.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
*
|
||||
* \param port
|
||||
* The port of the radio for the intended link.
|
||||
* \param link_id
|
||||
* Unique link ID in the form of a string, needs to be different from other links in
|
||||
* the area.
|
||||
* \param type
|
||||
* Indicates whether the radio link on the brain is a transmitter or receiver,
|
||||
* with the transmitter having double the transmitting bandwidth as the receiving
|
||||
* end (1040 bytes/s vs 520 bytes/s).
|
||||
* \param ov
|
||||
* Indicates if the radio on the given port needs vexlink to override the controller radio. Defualts to True.
|
||||
*
|
||||
* \return PROS_ERR if initialization fails, 1 if the initialization succeeds.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* pros::Link link(1, "my_link", pros::E_LINK_TX);
|
||||
* \endcode
|
||||
*/
|
||||
explicit Link(const std::uint8_t port, const std::string link_id, link_type_e_t type, bool ov = true);
|
||||
|
||||
/**
|
||||
* Checks if a radio link on a port is active or not.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
*
|
||||
* \return If a radio is connected to a port and it's connected to a link.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* pros::Link link(1, "my_link", pros::E_LINK_TX);
|
||||
* if (link.connected()) {
|
||||
* // do something
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
bool connected();
|
||||
|
||||
/**
|
||||
* Returns the bytes of data number of without protocol available to be read
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
*
|
||||
* \return PROS_ERR if port is not a link/radio, else the bytes available to be
|
||||
* read by the user.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Link link(1, "my_link", pros::E_LINK_TX);
|
||||
* printf("Bytes available to read: %d", link.receivable_size());
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t raw_receivable_size();
|
||||
|
||||
/**
|
||||
* Returns the bytes of data available in transmission buffer.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
*
|
||||
* \return PROS_ERR if port is not a link/radio,
|
||||
* else the bytes available to be transmitted by the user.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Link link(1, "my_link", pros::E_LINK_TX);
|
||||
* printf("Bytes available to transmit: %d", link.transmittable_size());
|
||||
* }
|
||||
*/
|
||||
std::uint32_t raw_transmittable_size();
|
||||
|
||||
/**
|
||||
* Send raw serial data through vexlink.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
* EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no
|
||||
* room in the FIFO buffer (queue) to transmit the data.
|
||||
* EINVAL - The data given is NULL
|
||||
*
|
||||
* \param data
|
||||
* Buffer with data to send
|
||||
* \param data_size
|
||||
* Buffer with data to send
|
||||
*
|
||||
* \return PROS_ERR if port is not a link, and the successfully transmitted
|
||||
* data size if it succeeded.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Link link(1, "my_link", pros::E_LINK_TX);
|
||||
* std::uint8_t data[4] = {0x01, 0x02, 0x03, 0x04};
|
||||
* link.transmit_raw(data, 4);
|
||||
* }
|
||||
*
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t transmit_raw(void* data, std::uint16_t data_size);
|
||||
|
||||
/**
|
||||
* Receive raw serial data through vexlink.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
* EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer
|
||||
* or destination buffer.
|
||||
*
|
||||
* \param dest
|
||||
* Destination buffer to read data to
|
||||
* \param data_size
|
||||
* Bytes of data to be read to the destination buffer
|
||||
*
|
||||
* \return PROS_ERR if port is not a link, and the successfully received
|
||||
* data size if it succeeded.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Link link(1, "my_link", pros::E_LINK_TX);
|
||||
* std::uint8_t data[4];
|
||||
* link.receive_raw(data, 4);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t receive_raw(void* dest, std::uint16_t data_size);
|
||||
|
||||
/**
|
||||
* Send packeted message through vexlink, with a checksum and start byte.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
* EBUSY - The transmitter buffer is still busy with a previous transmission, and there is no
|
||||
* room in the FIFO buffer (queue) to transmit the data.
|
||||
* EINVAL - The data given is NULL
|
||||
*
|
||||
* \param data
|
||||
* Buffer with data to send
|
||||
* \param data_size
|
||||
* Bytes of data to be read to the destination buffer
|
||||
*
|
||||
* \return PROS_ERR if port is not a link, and the successfully transmitted
|
||||
* data size if it succeeded.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Link link(1, "my_link", pros::E_LINK_TX);
|
||||
* std::uint8_t data[4] = {0x01, 0x02, 0x03, 0x04};
|
||||
* link.transmit(data, 4);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t transmit(void* data, std::uint16_t data_size);
|
||||
|
||||
/**
|
||||
* Receive packeted message through vexlink, with a checksum and start byte.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
* EINVAL - The destination given is NULL, or the size given is larger than the FIFO buffer
|
||||
* or destination buffer.
|
||||
* EBADMSG - Protocol error related to start byte, data size, or checksum.
|
||||
|
||||
* \param dest
|
||||
* Destination buffer to read data to
|
||||
* \param data_size
|
||||
* Bytes of data to be read to the destination buffer
|
||||
*
|
||||
* \return PROS_ERR if port is not a link, and the successfully received
|
||||
* data size if it succeeded.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Link link(1, "my_link", pros::E_LINK_TX);
|
||||
* std::uint8_t data[4];
|
||||
* link.receive(data, 4);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t receive(void* dest, std::uint16_t data_size);
|
||||
|
||||
/**
|
||||
* Clear the receive buffer of the link, and discarding the data.
|
||||
*
|
||||
* \note 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 radio.
|
||||
* ENXIO - The sensor is still calibrating, or no link is connected via the radio.
|
||||
*
|
||||
* \return PROS_ERR if port is not a link, 1 if the operation succeeded.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Link link(1, "my_link", pros::E_LINK_TX);
|
||||
* link.clear_receive_buf();
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t clear_receive_buf();
|
||||
|
||||
///@}
|
||||
};
|
||||
} // namespace pros
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef _PROS_LLEMU_H_
|
||||
#define _PROS_LLEMU_H_
|
||||
|
||||
// TODO:? Should there be weak symbols for the C api in here as well?
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/** LLEMU Conditional Include **/
|
||||
/** **/
|
||||
/** When the libvgl versions of llemu.h is present, common.mk will **/
|
||||
/** define a macro which lets this file know that liblvgl's llemu.h is **/
|
||||
/** present. If it is, we conditionally include it so that it gets **/
|
||||
/** included into api.h. **/
|
||||
/******************************************************************************/
|
||||
#ifdef _PROS_INCLUDE_LIBLVGL_LLEMU_H
|
||||
#include "liblvgl/llemu.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
namespace pros {
|
||||
namespace c {
|
||||
#endif//__cplusplus
|
||||
|
||||
/**
|
||||
* Displays a formatted string on the emulated three-button LCD screen.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENXIO - The LCD has not been initialized. Call lcd_initialize() first.
|
||||
* EINVAL - The line number specified is not in the range [0-7]
|
||||
*
|
||||
* \param line
|
||||
* The line on which to display the text [0-7]
|
||||
* \param fmt
|
||||
* Format string
|
||||
* \param ...
|
||||
* Optional list of arguments for the format string
|
||||
*
|
||||
* \return True if the operation was successful, or false otherwise, setting
|
||||
* errno values as specified above.
|
||||
*/
|
||||
bool __attribute__((weak)) lcd_print(int16_t line, const char* fmt, ...) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // namespace c
|
||||
} // namespace pros
|
||||
} // extern "C"
|
||||
#endif//__cplusplus
|
||||
|
||||
#endif // _PROS_LLEMU_H_
|
||||
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* \file pros/llemu.hpp
|
||||
* \ingroup cpp-llemu
|
||||
*
|
||||
* Legacy LCD Emulator
|
||||
*
|
||||
* \details This file defines a high-level API for emulating the three-button, UART-based
|
||||
* VEX LCD, containing a set of functions that facilitate the use of a software-
|
||||
* emulated version of the classic VEX LCD module.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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_LLEMU_HPP_
|
||||
#define _PROS_LLEMU_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
/******************************************************************************/
|
||||
/** LLEMU Conditional Include **/
|
||||
/** **/
|
||||
/** When the libvgl versions of llemu.hpp is present, common.mk will **/
|
||||
/** define a macro which lets this file know that liblvgl's llemu.hpp is **/
|
||||
/** present. If it is, we conditionally include it so that it gets **/
|
||||
/** included into api.h. **/
|
||||
/******************************************************************************/
|
||||
#ifdef _PROS_INCLUDE_LIBLVGL_LLEMU_HPP
|
||||
#include "liblvgl/llemu.hpp"
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/** LLEMU Weak Stubs **/
|
||||
/** **/
|
||||
/** These functions allow main.cpp to be compiled without LVGL present **/
|
||||
/******************************************************************************/
|
||||
|
||||
namespace pros {
|
||||
|
||||
/**
|
||||
* \ingroup cpp-llemu
|
||||
*/
|
||||
namespace lcd {
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
namespace {
|
||||
template <typename T>
|
||||
T convert_args(T arg) {
|
||||
return arg;
|
||||
}
|
||||
const char* convert_args(const std::string& arg) {
|
||||
return arg.c_str();
|
||||
}
|
||||
} // namespace
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
using lcd_btn_cb_fn_t = void (*)(void);
|
||||
|
||||
/*
|
||||
* These weak symbols allow the example main.cpp in to compile even when
|
||||
* the liblvgl template is missing from the project.
|
||||
*
|
||||
* For documentation on these functions, please see the doxygen comments for
|
||||
* these functions in the libvgl llemu headers.
|
||||
*/
|
||||
|
||||
extern __attribute__((weak)) bool set_text(std::int16_t line, std::string text);
|
||||
extern __attribute__((weak)) bool clear_line(std::int16_t line);
|
||||
extern __attribute__((weak)) bool initialize(void);
|
||||
extern __attribute__((weak)) std::uint8_t read_buttons(void);
|
||||
extern __attribute__((weak)) void register_btn1_cb(lcd_btn_cb_fn_t cb);
|
||||
extern __attribute__((weak)) bool is_initialized(void);
|
||||
|
||||
/**
|
||||
* \addtogroup cpp-llemu
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*
|
||||
* Note: This template resides in this file since the
|
||||
*/
|
||||
|
||||
/**
|
||||
* Displays a formatted string on the emulated three-button LCD screen.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENXIO - The LCD has not been initialized. Call lcd_initialize() first.
|
||||
* EINVAL - The line number specified is not in the range [0-7]
|
||||
*
|
||||
* \param line
|
||||
* The line on which to display the text [0-7]
|
||||
* \param fmt
|
||||
* Format string
|
||||
* \param ...args
|
||||
* Optional list of arguments for the format string
|
||||
*
|
||||
* \return True if the operation was successful, or false otherwise, setting
|
||||
* errno values as specified above.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #include "pros/llemu.hpp"
|
||||
*
|
||||
* void initialize() {
|
||||
* pros::lcd::initialize();
|
||||
* pros::lcd::print(0, "My formatted text: %d!", 2);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
template <typename... Params>
|
||||
bool print(std::int16_t line, const char* fmt, Params... args) {
|
||||
return pros::c::lcd_print(line, fmt, convert_args(args)...);
|
||||
}
|
||||
|
||||
#ifndef LCD_BTN_LEFT
|
||||
#define LCD_BTN_LEFT 4
|
||||
#endif
|
||||
|
||||
#ifndef LCD_BTN_CENTER
|
||||
#define LCD_BTN_CENTER 2
|
||||
#endif
|
||||
|
||||
#ifndef LCD_BTN_RIGHT
|
||||
#define LCD_BTN_RIGHT 1
|
||||
#endif
|
||||
/// @}
|
||||
} // namespace lcd
|
||||
} // namespace pros
|
||||
|
||||
#endif // _PROS_LLEMU_HPP_
|
||||
@@ -0,0 +1,834 @@
|
||||
/**
|
||||
* \file pros/misc.h
|
||||
* \ingroup c-misc
|
||||
*
|
||||
* Contains prototypes for miscellaneous functions pertaining to the controller,
|
||||
* battery, and competition control.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, Purdue University ACM SIGBots.
|
||||
* All rights reservered.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
* \defgroup c-misc Miscellaneous C API
|
||||
* \note Additional example code for this module can be found in its [Tutorial.](@ref controller)
|
||||
*/
|
||||
|
||||
#ifndef _PROS_MISC_H_
|
||||
#define _PROS_MISC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define NUM_V5_PORTS (22)
|
||||
|
||||
/**
|
||||
* \ingroup c-misc
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup c-misc
|
||||
* @{
|
||||
*/
|
||||
|
||||
/// \name V5 Competition
|
||||
//@{
|
||||
|
||||
/*#define COMPETITION_DISABLED (1 << 0)
|
||||
#define COMPETITION_AUTONOMOUS (1 << 1)
|
||||
#define COMPETITION_CONNECTED (1 << 2)
|
||||
#define COMPETITION_SYSTEM (1 << 3)*/
|
||||
typedef enum {
|
||||
COMPETITION_DISABLED = 1 << 0,
|
||||
COMPETITION_CONNECTED = 1 << 2,
|
||||
COMPETITION_AUTONOMOUS = 1 << 1,
|
||||
COMPETITION_SYSTEM = 1 << 3,
|
||||
} competition_status;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
namespace pros {
|
||||
namespace c {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \fn competition_get_status(void)
|
||||
* Get the current status of the competition control.
|
||||
*
|
||||
* \return The competition control status as a mask of bits with
|
||||
* COMPETITION_{ENABLED,AUTONOMOUS,CONNECTED}.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* if (competition_get_status() & COMPETITION_CONNECTED == true) {
|
||||
* // Field Control is Connected
|
||||
* // Run LCD Selector code or similar
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint8_t competition_get_status(void);
|
||||
|
||||
/**
|
||||
* \fn competition_is_disabled()
|
||||
*
|
||||
* \return True if the V5 Brain is disabled, false otherwise.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void my_task_fn(void* ignore) {
|
||||
* while (!competition_is_disabled()) {
|
||||
* // Run competition tasks (like Lift Control or similar)
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* void initialize() {
|
||||
* task_t my_task = task_create(my_task_fn, NULL, TASK_PRIO_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "My Task");
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint8_t competition_is_disabled(void);
|
||||
|
||||
/**
|
||||
* \return True if the V5 Brain is connected to competition control, false otherwise.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* if (competition_is_connected()) {
|
||||
* // Field Control is Connected
|
||||
* // Run LCD Selector code or similar
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint8_t competition_is_connected(void);
|
||||
|
||||
/**
|
||||
* \return True if the V5 Brain is in autonomous mode, false otherwise.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void my_task_fn(void* ignore) {
|
||||
* while (!competition_is_autonomous()) {
|
||||
* // Wait to do anything until autonomous starts
|
||||
* delay(2);
|
||||
* }
|
||||
* while (competition_is_autonomous()) {
|
||||
* // Run whatever code is desired to just execute in autonomous
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* void initialize() {
|
||||
* task_t my_task = task_create(my_task_fn, NULL, TASK_PRIO_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "My Task");
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint8_t competition_is_autonomous(void);
|
||||
|
||||
/**
|
||||
* \return True if the V5 Brain is connected to VEXnet Field Controller, false otherwise.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* if (competition_is_field()) {
|
||||
* // connected to VEXnet Field Controller
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint8_t competition_is_field(void);
|
||||
|
||||
/**
|
||||
* \return True if the V5 Brain is connected to VEXnet Competition Switch, false otherwise.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* if (competition_is_switch()) {
|
||||
* // connected to VEXnet Competition Switch
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
uint8_t competition_is_switch(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
///@}
|
||||
|
||||
/// \name V5 Controller
|
||||
///@{
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
namespace pros {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \enum
|
||||
*/
|
||||
typedef enum {
|
||||
/// The master controller.
|
||||
E_CONTROLLER_MASTER = 0,
|
||||
/// The partner controller.
|
||||
E_CONTROLLER_PARTNER
|
||||
} controller_id_e_t;
|
||||
|
||||
/**
|
||||
* \enum
|
||||
*/
|
||||
typedef enum {
|
||||
/// The horizontal axis of the controller’s left analog stick.
|
||||
E_CONTROLLER_ANALOG_LEFT_X = 0,
|
||||
/// The vertical axis of the controller’s left analog stick.
|
||||
E_CONTROLLER_ANALOG_LEFT_Y,
|
||||
/// The horizontal axis of the controller’s right analog stick.
|
||||
E_CONTROLLER_ANALOG_RIGHT_X,
|
||||
/// The vertical axis of the controller’s right analog stick.
|
||||
E_CONTROLLER_ANALOG_RIGHT_Y
|
||||
} controller_analog_e_t;
|
||||
|
||||
/**
|
||||
* \enum
|
||||
*/
|
||||
typedef enum {
|
||||
/// The first trigger on the left side of the controller.
|
||||
E_CONTROLLER_DIGITAL_L1 = 6,
|
||||
/// The second trigger on the left side of the controller.
|
||||
E_CONTROLLER_DIGITAL_L2,
|
||||
/// The first trigger on the right side of the controller.
|
||||
E_CONTROLLER_DIGITAL_R1,
|
||||
/// The second trigger on the right side of the controller.
|
||||
E_CONTROLLER_DIGITAL_R2,
|
||||
/// The up arrow on the left arrow pad of the controller.
|
||||
E_CONTROLLER_DIGITAL_UP,
|
||||
/// The down arrow on the left arrow pad of the controller.
|
||||
E_CONTROLLER_DIGITAL_DOWN,
|
||||
/// The left arrow on the left arrow pad of the controller.
|
||||
E_CONTROLLER_DIGITAL_LEFT,
|
||||
/// The right arrow on the left arrow pad of the controller.
|
||||
E_CONTROLLER_DIGITAL_RIGHT,
|
||||
/// The ‘X’ button on the right button pad of the controller.
|
||||
E_CONTROLLER_DIGITAL_X,
|
||||
/// The ‘B’ button on the right button pad of the controller.
|
||||
E_CONTROLLER_DIGITAL_B,
|
||||
/// The ‘Y’ button on the right button pad of the controller.
|
||||
E_CONTROLLER_DIGITAL_Y,
|
||||
/// The ‘A’ button on the right button pad of the controller.
|
||||
E_CONTROLLER_DIGITAL_A
|
||||
} controller_digital_e_t;
|
||||
|
||||
#ifdef PROS_USE_SIMPLE_NAMES
|
||||
#ifdef __cplusplus
|
||||
#define CONTROLLER_MASTER pros::E_CONTROLLER_MASTER
|
||||
#define CONTROLLER_PARTNER pros::E_CONTROLLER_PARTNER
|
||||
#define ANALOG_LEFT_X pros::E_CONTROLLER_ANALOG_LEFT_X
|
||||
#define ANALOG_LEFT_Y pros::E_CONTROLLER_ANALOG_LEFT_Y
|
||||
#define ANALOG_RIGHT_X pros::E_CONTROLLER_ANALOG_RIGHT_X
|
||||
#define ANALOG_RIGHT_Y pros::E_CONTROLLER_ANALOG_RIGHT_Y
|
||||
#define DIGITAL_L1 pros::E_CONTROLLER_DIGITAL_L1
|
||||
#define DIGITAL_L2 pros::E_CONTROLLER_DIGITAL_L2
|
||||
#define DIGITAL_R1 pros::E_CONTROLLER_DIGITAL_R1
|
||||
#define DIGITAL_R2 pros::E_CONTROLLER_DIGITAL_R2
|
||||
#define DIGITAL_UP pros::E_CONTROLLER_DIGITAL_UP
|
||||
#define DIGITAL_DOWN pros::E_CONTROLLER_DIGITAL_DOWN
|
||||
#define DIGITAL_LEFT pros::E_CONTROLLER_DIGITAL_LEFT
|
||||
#define DIGITAL_RIGHT pros::E_CONTROLLER_DIGITAL_RIGHT
|
||||
#define DIGITAL_X pros::E_CONTROLLER_DIGITAL_X
|
||||
#define DIGITAL_B pros::E_CONTROLLER_DIGITAL_B
|
||||
#define DIGITAL_Y pros::E_CONTROLLER_DIGITAL_Y
|
||||
#define DIGITAL_A pros::E_CONTROLLER_DIGITAL_A
|
||||
#else
|
||||
#define CONTROLLER_MASTER E_CONTROLLER_MASTER
|
||||
#define CONTROLLER_PARTNER E_CONTROLLER_PARTNER
|
||||
#define ANALOG_LEFT_X E_CONTROLLER_ANALOG_LEFT_X
|
||||
#define ANALOG_LEFT_Y E_CONTROLLER_ANALOG_LEFT_Y
|
||||
#define ANALOG_RIGHT_X E_CONTROLLER_ANALOG_RIGHT_X
|
||||
#define ANALOG_RIGHT_Y E_CONTROLLER_ANALOG_RIGHT_Y
|
||||
#define DIGITAL_L1 E_CONTROLLER_DIGITAL_L1
|
||||
#define DIGITAL_L2 E_CONTROLLER_DIGITAL_L2
|
||||
#define DIGITAL_R1 E_CONTROLLER_DIGITAL_R1
|
||||
#define DIGITAL_R2 E_CONTROLLER_DIGITAL_R2
|
||||
#define DIGITAL_UP E_CONTROLLER_DIGITAL_UP
|
||||
#define DIGITAL_DOWN E_CONTROLLER_DIGITAL_DOWN
|
||||
#define DIGITAL_LEFT E_CONTROLLER_DIGITAL_LEFT
|
||||
#define DIGITAL_RIGHT E_CONTROLLER_DIGITAL_RIGHT
|
||||
#define DIGITAL_X E_CONTROLLER_DIGITAL_X
|
||||
#define DIGITAL_B E_CONTROLLER_DIGITAL_B
|
||||
#define DIGITAL_Y E_CONTROLLER_DIGITAL_Y
|
||||
#define DIGITAL_A E_CONTROLLER_DIGITAL_A
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \def Given an id and a port, this macro sets the port variable based on the id and allows the mutex to take that
|
||||
* port.
|
||||
*
|
||||
* \returns error (in the function/scope it's in) if the controller failed to connect or an invalid id is given.
|
||||
*/
|
||||
#define CONTROLLER_PORT_MUTEX_TAKE(id, port) \
|
||||
switch (id) { \
|
||||
case E_CONTROLLER_MASTER: \
|
||||
port = V5_PORT_CONTROLLER_1; \
|
||||
break; \
|
||||
case E_CONTROLLER_PARTNER: \
|
||||
port = V5_PORT_CONTROLLER_2; \
|
||||
break; \
|
||||
default: \
|
||||
errno = EINVAL; \
|
||||
return PROS_ERR; \
|
||||
} \
|
||||
if (!internal_port_mutex_take(port)) { \
|
||||
errno = EACCES; \
|
||||
return PROS_ERR; \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace c {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Checks if the controller is connected.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
|
||||
* given.
|
||||
* EACCES - Another resource is currently trying to access the controller port.
|
||||
*
|
||||
* \param id
|
||||
* The ID of the controller (e.g. the master or partner controller).
|
||||
* Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
|
||||
*
|
||||
* \return 1 if the controller is connected, 0 otherwise
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* if (competition_is_connected()) {
|
||||
* // Field Control is Connected
|
||||
* // Run LCD Selector code or similar
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t controller_is_connected(controller_id_e_t id);
|
||||
|
||||
/**
|
||||
* Gets the value of an analog channel (joystick) on a controller.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
|
||||
* given.
|
||||
* EACCES - Another resource is currently trying to access the controller port.
|
||||
*
|
||||
* \param id
|
||||
* The ID of the controller (e.g. the master or partner controller).
|
||||
* Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
|
||||
* \param channel
|
||||
* The analog channel to get.
|
||||
* Must be one of ANALOG_LEFT_X, ANALOG_LEFT_Y, ANALOG_RIGHT_X,
|
||||
* ANALOG_RIGHT_Y
|
||||
*
|
||||
* \return The current reading of the analog channel: [-127, 127].
|
||||
* If the controller was not connected, then 0 is returned
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y));
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t controller_get_analog(controller_id_e_t id, controller_analog_e_t channel);
|
||||
|
||||
/**
|
||||
* Gets the battery capacity of the given controller.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
|
||||
* given.
|
||||
* EACCES - Another resource is currently trying to access the controller port.
|
||||
*
|
||||
* \param id
|
||||
* The ID of the controller (e.g. the master or partner controller).
|
||||
* Must be one of E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER
|
||||
*
|
||||
* \return The controller's battery capacity
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* printf("Battery Capacity: %d\n", controller_get_battery_capacity(E_CONTROLLER_MASTER));
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t controller_get_battery_capacity(controller_id_e_t id);
|
||||
|
||||
/**
|
||||
* Gets the battery level of the given controller.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
|
||||
* given.
|
||||
* EACCES - Another resource is currently trying to access the controller port.
|
||||
*
|
||||
* \param id
|
||||
* The ID of the controller (e.g. the master or partner controller).
|
||||
* Must be one of E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER
|
||||
*
|
||||
* \return The controller's battery level
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* printf("Battery Level: %d\n", controller_get_battery_level(E_CONTROLLER_MASTER));
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t controller_get_battery_level(controller_id_e_t id);
|
||||
|
||||
/**
|
||||
* Checks if a digital channel (button) on the controller is currently pressed.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
|
||||
* given.
|
||||
* EACCES - Another resource is currently trying to access the controller port.
|
||||
*
|
||||
* \param id
|
||||
* The ID of the controller (e.g. the master or partner controller).
|
||||
* Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
|
||||
* \param button
|
||||
* The button to read.
|
||||
* Must be one of DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}
|
||||
*
|
||||
* \return 1 if the button on the controller is pressed.
|
||||
* If the controller was not connected, then 0 is returned
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* if (controller_get_digital(E_CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_A)) {
|
||||
* motor_set(1, 100);
|
||||
* }
|
||||
* else {
|
||||
* motor_set(1, 0);
|
||||
* }
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
|
||||
* \endcode
|
||||
*/
|
||||
int32_t controller_get_digital(controller_id_e_t id, controller_digital_e_t button);
|
||||
|
||||
/**
|
||||
* Returns a rising-edge case for a controller button press.
|
||||
*
|
||||
* This function is not thread-safe.
|
||||
* Multiple tasks polling a single button may return different results under the
|
||||
* same circumstances, so only one task should call this function for any given
|
||||
* button. E.g., Task A calls this function for buttons 1 and 2. Task B may call
|
||||
* this function for button 3, but should not for buttons 1 or 2. A typical
|
||||
* use-case for this function is to call inside opcontrol to detect new button
|
||||
* presses, and not in any other tasks.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
|
||||
* given.
|
||||
* EACCES - Another resource is currently trying to access the controller port.
|
||||
*
|
||||
* \param id
|
||||
* The ID of the controller (e.g. the master or partner controller).
|
||||
* Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
|
||||
* \param button
|
||||
* The button to read. Must be one of
|
||||
* DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}
|
||||
*
|
||||
* \return 1 if the button on the controller is pressed and had not been pressed
|
||||
* the last time this function was called, 0 otherwise.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* if (controller_get_digital_new_press(E_CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_A)) {
|
||||
* // Toggle pneumatics or other similar actions
|
||||
* }
|
||||
*
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t controller_get_digital_new_press(controller_id_e_t id, controller_digital_e_t button);
|
||||
|
||||
/**
|
||||
* Sets text to the controller LCD screen.
|
||||
*
|
||||
* \note Controller text setting is a slow process, so updates faster than 10ms
|
||||
* when on a wired connection or 50ms over Vexnet will not be applied to the controller.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
|
||||
* given.
|
||||
* EACCES - Another resource is currently trying to access the controller port.
|
||||
* EAGAIN - Could not send the text to the controller.
|
||||
*
|
||||
* \param id
|
||||
* The ID of the controller (e.g. the master or partner controller).
|
||||
* Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
|
||||
* \param line
|
||||
* The line number at which the text will be displayed [0-2]
|
||||
* \param col
|
||||
* The column number at which the text will be displayed [0-14]
|
||||
* \param fmt
|
||||
* The format string to print to the controller
|
||||
* \param ...
|
||||
* The argument list for the format string
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* int count = 0;
|
||||
* while (true) {
|
||||
* if (!(count % 25)) {
|
||||
* // Only print every 50ms, the controller text update rate is slow
|
||||
* controller_print(E_CONTROLLER_MASTER, 0, 0, "Counter: %d", count);
|
||||
* }
|
||||
* count++;
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t controller_print(controller_id_e_t id, uint8_t line, uint8_t col, const char* fmt, ...);
|
||||
|
||||
/**
|
||||
* Sets text to the controller LCD screen.
|
||||
*
|
||||
* \note Controller text setting is a slow process, so updates faster than 10ms
|
||||
* when on a wired connection or 50ms over Vexnet will not be applied to the controller.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
|
||||
* given.
|
||||
* EACCES - Another resource is currently trying to access the controller port.
|
||||
* EAGAIN - Could not send the text to the controller.
|
||||
*
|
||||
* \param id
|
||||
* The ID of the controller (e.g. the master or partner controller).
|
||||
* Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
|
||||
* \param line
|
||||
* The line number at which the text will be displayed [0-2]
|
||||
* \param col
|
||||
* The column number at which the text will be displayed [0-14]
|
||||
* \param str
|
||||
* The pre-formatted string to print to the controller
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* int count = 0;
|
||||
* while (true) {
|
||||
* if (!(count % 25)) {
|
||||
* // Only print every 50ms, the controller text update rate is slow
|
||||
* controller_set_text(E_CONTROLLER_MASTER, 0, 0, "Example text");
|
||||
* }
|
||||
* count++;
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t controller_set_text(controller_id_e_t id, uint8_t line, uint8_t col, const char* str);
|
||||
|
||||
/**
|
||||
* Clears an individual line of the controller screen.
|
||||
*
|
||||
* \note Controller text setting is currently in beta, so continuous, fast
|
||||
* updates will not work well.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
|
||||
* given.
|
||||
* EACCES - Another resource is currently trying to access the controller port.
|
||||
*
|
||||
* \param id
|
||||
* The ID of the controller (e.g. the master or partner controller).
|
||||
* Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
|
||||
* \param line
|
||||
* The line number to clear [0-2]
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* controller_set_text(E_CONTROLLER_MASTER, 0, 0, "Example");
|
||||
* delay(100);
|
||||
* controller_clear_line(E_CONTROLLER_MASTER, 0);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t controller_clear_line(controller_id_e_t id, uint8_t line);
|
||||
|
||||
/**
|
||||
* Clears all of the lines on the controller screen.
|
||||
*
|
||||
* \note Controller text setting is a slow process, so updates faster than 10ms
|
||||
* when on a wired connection or 50ms over Vexnet will not be applied to the controller.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
|
||||
* given.
|
||||
* EACCES - Another resource is currently trying to access the controller port.
|
||||
* EAGAIN - Could not send the text to the controller.
|
||||
*
|
||||
* \param id
|
||||
* The ID of the controller (e.g. the master or partner controller).
|
||||
* Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* controller_set_text(E_CONTROLLER_MASTER, 0, 0, "Example");
|
||||
* delay(100);
|
||||
* controller_clear(E_CONTROLLER_MASTER);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t controller_clear(controller_id_e_t id);
|
||||
|
||||
/**
|
||||
* Rumble the controller.
|
||||
*
|
||||
* \note Controller rumble activation is a slow process, so updates faster than 10ms
|
||||
* when on a wired connection or 50ms over Vexnet will not be applied to the controller.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is
|
||||
* given.
|
||||
* EACCES - Another resource is currently trying to access the controller port.
|
||||
*
|
||||
* \param id
|
||||
* The ID of the controller (e.g. the master or partner controller).
|
||||
* Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
|
||||
* \param rumble_pattern
|
||||
* A string consisting of the characters '.', '-', and ' ', where dots
|
||||
* are short rumbles, dashes are long rumbles, and spaces are pauses.
|
||||
* Maximum supported length is 8 characters.
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* int count = 0;
|
||||
* while (true) {
|
||||
* if (!(count % 25)) {
|
||||
* // Only send every 50ms, the controller update rate is slow
|
||||
* controller_rumble(E_CONTROLLER_MASTER, ". - . -");
|
||||
* }
|
||||
* count++;
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t controller_rumble(controller_id_e_t id, const char* rumble_pattern);
|
||||
|
||||
/**
|
||||
* Gets the current voltage of the battery, as reported by VEXos.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the battery port.
|
||||
*
|
||||
* \return The current voltage of the battery
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* printf("Battery's Voltage: %d\n", battery_get_voltage());
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t battery_get_voltage(void);
|
||||
|
||||
/**
|
||||
* Gets the current current of the battery, as reported by VEXos.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the battery port.
|
||||
*
|
||||
* \return The current current of the battery
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* printf("Battery Current: %d\n", battery_get_current());
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t battery_get_current(void);
|
||||
|
||||
/**
|
||||
* Gets the current temperature of the battery, as reported by VEXos.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the battery port.
|
||||
*
|
||||
* \return The current temperature of the battery
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* printf("Battery's Temperature: %d\n", battery_get_temperature());
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double battery_get_temperature(void);
|
||||
|
||||
/**
|
||||
* Gets the current capacity of the battery, as reported by VEXos.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the battery port.
|
||||
*
|
||||
* \return The current capacity of the battery
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* printf("Battery Level: %d\n", battery_get_capacity());
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double battery_get_capacity(void);
|
||||
|
||||
/**
|
||||
* Checks if the SD card is installed.
|
||||
*
|
||||
* \return 1 if the SD card is installed, 0 otherwise
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* printf("%i", usd_is_installed());
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t usd_is_installed(void);
|
||||
|
||||
/**
|
||||
* Lists the files in a directory specified by the path
|
||||
* Puts the list of file names (NOT DIRECTORIES) into the buffer seperated by newlines
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
*
|
||||
* EIO - Hard error occured in the low level disk I/O layer
|
||||
* EINVAL - file or directory is invalid, or length is invalid
|
||||
* EBUSY - THe physical drinve cannot work
|
||||
* ENOENT - cannot find the path or file
|
||||
* EINVAL - the path name format is invalid
|
||||
* EACCES - Access denied or directory full
|
||||
* EEXIST - Access denied
|
||||
* EROFS - SD card is write protected
|
||||
* ENXIO - drive number is invalid or not a FAT32 drive
|
||||
* ENOBUFS - drive has no work area
|
||||
* ENFILE - too many open files
|
||||
*
|
||||
*
|
||||
*
|
||||
* \note use a path of "\" to list the files in the main directory NOT "/usd/"
|
||||
* DO NOT PREPEND YOUR PATHS WITH "/usd/"
|
||||
*
|
||||
* \return 1 on success or PROS_ERR on failure setting errno
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* char* test = (char*) malloc(128);
|
||||
* pros::c::usd_list_files("/", test, 128);
|
||||
* pros::delay(200);
|
||||
* printf("%s\n", test); //Prints the file names in the root directory seperated by newlines
|
||||
* pros::delay(100);
|
||||
* pros::c::usd_list_files("/test", test, 128);
|
||||
* pros::delay(200);
|
||||
* printf("%s\n", test); //Prints the names of files in the folder named test seperated by newlines
|
||||
* pros::delay(100);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t usd_list_files(const char* path, char* buffer, int32_t len);
|
||||
|
||||
/******************************************************************************/
|
||||
/** Date and Time **/
|
||||
/******************************************************************************/
|
||||
|
||||
extern const char* baked_date;
|
||||
extern const char* baked_time;
|
||||
|
||||
typedef struct {
|
||||
uint16_t year; // Year - 1980
|
||||
uint8_t day;
|
||||
uint8_t month; // 1 = January
|
||||
} date_s_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t hour;
|
||||
uint8_t min;
|
||||
uint8_t sec;
|
||||
uint8_t sec_hund; // hundredths of a second
|
||||
} time_s_t;
|
||||
|
||||
///@}
|
||||
|
||||
///@}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
} // namespace pros
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _PROS_MISC_H_
|
||||
@@ -0,0 +1,577 @@
|
||||
/**
|
||||
* \file pros/misc.hpp
|
||||
* \ingroup cpp-pros
|
||||
*
|
||||
* Contains prototypes for miscellaneous functions pertaining to the controller,
|
||||
* battery, and competition control.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, Purdue University ACM SIGBots.
|
||||
* All rights reservered.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
* \defgroup cpp-misc Miscellaneous C++ API
|
||||
* \note Additional example code for this module can be found in its [Tutorial.](@ref controller)
|
||||
*/
|
||||
|
||||
#ifndef _PROS_MISC_HPP_
|
||||
#define _PROS_MISC_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "pros/misc.h"
|
||||
|
||||
namespace pros {
|
||||
inline namespace v5 {
|
||||
/**
|
||||
* \ingroup cpp-misc
|
||||
*/
|
||||
class Controller {
|
||||
/**
|
||||
* \addtogroup cpp-misc
|
||||
* ///@{
|
||||
*/
|
||||
public:
|
||||
/**
|
||||
* Creates a controller object for the given controller id.
|
||||
*
|
||||
* \param id
|
||||
* The ID of the controller (e.g. the master or partner controller).
|
||||
* Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER
|
||||
*/
|
||||
explicit Controller(controller_id_e_t id);
|
||||
|
||||
/**
|
||||
* Checks if the controller is connected.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the controller
|
||||
* port.
|
||||
*
|
||||
* \return 1 if the controller is connected, 0 otherwise
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void status_display_controller(){
|
||||
* pros::Controller master(pros::E_CONTROLLER_MASTER);
|
||||
* if(!master.is_connected()) {
|
||||
* pros::lcd::print(0, "Main controller is not connected!");
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t is_connected(void);
|
||||
|
||||
/**
|
||||
* Gets the value of an analog channel (joystick) on a controller.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the controller
|
||||
* port.
|
||||
*
|
||||
* \param channel
|
||||
* The analog channel to get.
|
||||
* Must be one of ANALOG_LEFT_X, ANALOG_LEFT_Y, ANALOG_RIGHT_X,
|
||||
* ANALOG_RIGHT_Y
|
||||
*
|
||||
* \return The current reading of the analog channel: [-127, 127].
|
||||
* If the controller was not connected, then 0 is returned
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Controller master(pros::E_CONTROLLER_MASTER);
|
||||
* while (true) {
|
||||
* motor_move(1, master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y));
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t get_analog(controller_analog_e_t channel);
|
||||
|
||||
/**
|
||||
* Gets the battery capacity of the controller.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the controller
|
||||
* port.
|
||||
*
|
||||
* \return The controller's battery capacity
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* pros::Controller master(pros::E_CONTROLLER_MASTER);
|
||||
* printf("Battery Capacity: %d\n", master.get_battery_capacity());
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t get_battery_capacity(void);
|
||||
|
||||
/**
|
||||
* Gets the battery level of the controller.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the controller
|
||||
* port.
|
||||
*
|
||||
* \return The controller's battery level
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* pros::Controller master(pros::E_CONTROLLER_MASTER);
|
||||
* printf("Battery Level: %d\n", master.get_battery_level());
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t get_battery_level(void);
|
||||
|
||||
/**
|
||||
* Checks if a digital channel (button) on the controller is currently
|
||||
* pressed.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the controller
|
||||
* port.
|
||||
*
|
||||
* \param button
|
||||
* The button to read. Must be one of
|
||||
* DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}
|
||||
*
|
||||
* \return 1 if the button on the controller is pressed.
|
||||
* If the controller was not connected, then 0 is returned
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Controller master(pros::E_CONTROLLER_MASTER);
|
||||
* while (true) {
|
||||
* if (master.get_digital(pros::E_CONTROLLER_DIGITAL_A)) {
|
||||
* motor_set(1, 100);
|
||||
* }
|
||||
* else {
|
||||
* motor_set(1, 0);
|
||||
* }
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t get_digital(controller_digital_e_t button);
|
||||
|
||||
/**
|
||||
* Returns a rising-edge case for a controller button press.
|
||||
*
|
||||
* This function is not thread-safe.
|
||||
* Multiple tasks polling a single button may return different results under
|
||||
* the same circumstances, so only one task should call this function for any
|
||||
* given button. E.g., Task A calls this function for buttons 1 and 2.
|
||||
* Task B may call this function for button 3, but should not for buttons
|
||||
* 1 or 2. A typical use-case for this function is to call inside opcontrol
|
||||
* to detect new button presses, and not in any other tasks.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the controller
|
||||
* port.
|
||||
*
|
||||
* \param button
|
||||
* The button to read. Must be one of
|
||||
* DIGITAL_{RIGHT,DOWN,LEFT,UP,A,B,Y,X,R1,R2,L1,L2}
|
||||
*
|
||||
* \return 1 if the button on the controller is pressed and had not been
|
||||
* pressed the last time this function was called, 0 otherwise.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Controller master(pros::E_CONTROLLER_MASTER);
|
||||
* while (true) {
|
||||
* if (master.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_A)) {
|
||||
* // Toggle pneumatics or other similar actions
|
||||
* }
|
||||
*
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t get_digital_new_press(controller_digital_e_t button);
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
template <typename T>
|
||||
T convert_args(T arg) {
|
||||
return arg;
|
||||
}
|
||||
const char* convert_args(const std::string& arg) {
|
||||
return arg.c_str();
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/**
|
||||
* Sets text to the controller LCD screen.
|
||||
*
|
||||
* \note Controller text setting is currently in beta, so continuous, fast
|
||||
* updates will not work well.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the controller
|
||||
* port.
|
||||
*
|
||||
* \param line
|
||||
* The line number at which the text will be displayed [0-2]
|
||||
* \param col
|
||||
* The column number at which the text will be displayed [0-14]
|
||||
* \param fmt
|
||||
* The format string to print to the controller
|
||||
* \param ...
|
||||
* The argument list for the format string
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* int count = 0;
|
||||
* pros::Controller master(pros::E_CONTROLLER_MASTER);
|
||||
* while (true) {
|
||||
* if (!(count % 25)) {
|
||||
* // Only print every 50ms, the controller text update rate is slow
|
||||
* master.print(0, 0, "Counter: %d", count);
|
||||
* }
|
||||
* count++;
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
template <typename... Params>
|
||||
std::int32_t print(std::uint8_t line, std::uint8_t col, const char* fmt, Params... args) {
|
||||
return pros::c::controller_print(_id, line, col, fmt, convert_args(args)...);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets text to the controller LCD screen.
|
||||
*
|
||||
* \note Controller text setting is currently in beta, so continuous, fast
|
||||
* updates will not work well.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the controller
|
||||
* port.
|
||||
*
|
||||
* \param line
|
||||
* The line number at which the text will be displayed [0-2]
|
||||
* \param col
|
||||
* The column number at which the text will be displayed [0-14]
|
||||
* \param str
|
||||
* The pre-formatted string to print to the controller
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* int count = 0;
|
||||
* pros::Controller master(pros::E_CONTROLLER_MASTER);
|
||||
* while (true) {
|
||||
* if (!(count % 25)) {
|
||||
* // Only print every 50ms, the controller text update rate is slow
|
||||
* master.set_text(0, 0, "Example text");
|
||||
* }
|
||||
* count++;
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t set_text(std::uint8_t line, std::uint8_t col, const char* str);
|
||||
std::int32_t set_text(std::uint8_t line, std::uint8_t col, const std::string& str);
|
||||
|
||||
/**
|
||||
* Clears an individual line of the controller screen.
|
||||
*
|
||||
* \note Controller text setting is currently in beta, so continuous, fast
|
||||
* updates will not work well.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the controller
|
||||
* port.
|
||||
*
|
||||
* \param line
|
||||
* The line number to clear [0-2]
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Controller master(pros::E_CONTROLLER_MASTER);
|
||||
* master.set_text(0, 0, "Example");
|
||||
* delay(100);
|
||||
* master.clear_line(0);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t clear_line(std::uint8_t line);
|
||||
|
||||
/**
|
||||
* Rumble the controller.
|
||||
*
|
||||
* \note Controller rumble activation is currently in beta, so continuous, fast
|
||||
* updates will not work well.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the controller
|
||||
* port.
|
||||
*
|
||||
* \param rumble_pattern
|
||||
* A string consisting of the characters '.', '-', and ' ', where dots
|
||||
* are short rumbles, dashes are long rumbles, and spaces are pauses.
|
||||
* Maximum supported length is 8 characters.
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* int count = 0;
|
||||
* pros::Controller master(pros::E_CONTROLLER_MASTER);
|
||||
* while (true) {
|
||||
* if (!(count % 25)) {
|
||||
* // Only send every 50ms, the controller update rate is slow
|
||||
* master.rumble(". - . -");
|
||||
* }
|
||||
* count++;
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t rumble(const char* rumble_pattern);
|
||||
|
||||
/**
|
||||
* Clears all of the lines on the controller screen.
|
||||
*
|
||||
* \note Controller text setting is currently in beta, so continuous, fast
|
||||
* updates will not work well. On vexOS version 1.0.0 this function will
|
||||
* block for 110ms.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the controller
|
||||
* port.
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Controller master(pros::E_CONTROLLER_MASTER);
|
||||
* master.set_text(0, 0, "Example");
|
||||
* delay(100);
|
||||
* master.clear();
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t clear(void);
|
||||
|
||||
private:
|
||||
controller_id_e_t _id;
|
||||
///@}
|
||||
};
|
||||
} // namespace v5
|
||||
|
||||
namespace battery {
|
||||
/**
|
||||
* \addtogroup cpp-misc
|
||||
* ///@{
|
||||
*/
|
||||
/**
|
||||
* Gets the current voltage of the battery, as reported by VEXos.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the battery port.
|
||||
*
|
||||
* \return The current voltage of the battery
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* printf("Battery Level: %.2f\n", get_capacity());
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double get_capacity(void);
|
||||
|
||||
/**
|
||||
* Gets the current current of the battery in milliamps, as reported by VEXos.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the battery port.
|
||||
*
|
||||
* \return The current current of the battery
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* printf("Battery Current: %d\n", get_current());
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t get_current(void);
|
||||
|
||||
/**
|
||||
* Gets the current temperature of the battery, as reported by VEXos.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the battery port.
|
||||
*
|
||||
* \return The current temperature of the battery
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* printf("Battery's Temperature: %.2f\n", get_temperature());
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
double get_temperature(void);
|
||||
|
||||
/**
|
||||
* Gets the current capacity of the battery in millivolts, as reported by VEXos.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCES - Another resource is currently trying to access the battery port.
|
||||
*
|
||||
* \return The current capacity of the battery
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* printf("Battery's Voltage: %d\n", get_voltage());
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t get_voltage(void);
|
||||
///@}
|
||||
} // namespace battery
|
||||
|
||||
namespace competition {
|
||||
/**
|
||||
* Get the current status of the competition control.
|
||||
*
|
||||
* \return The competition control status as a mask of bits with
|
||||
* COMPETITION_{ENABLED,AUTONOMOUS,CONNECTED}.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void status_display_task(){
|
||||
* if(!is_connected()) {
|
||||
* pros::lcd::print(0, "V5 Brain is not connected!");
|
||||
* }
|
||||
* if(is_autonomous()) {
|
||||
* pros::lcd::print(0, "V5 Brain is in autonomous mode!");
|
||||
* }
|
||||
* if(!is_disabled()) {
|
||||
* pros::lcd::print(0, "V5 Brain is disabled!");
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint8_t get_status(void);
|
||||
std::uint8_t is_autonomous(void);
|
||||
std::uint8_t is_connected(void);
|
||||
std::uint8_t is_disabled(void);
|
||||
std::uint8_t is_field_control(void);
|
||||
std::uint8_t is_competition_switch(void);
|
||||
} // namespace competition
|
||||
|
||||
namespace usd {
|
||||
/**
|
||||
* Checks if the SD card is installed.
|
||||
*
|
||||
* \return 1 if the SD card is installed, 0 otherwise
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* printf("%i", is_installed());
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t is_installed(void);
|
||||
/**
|
||||
* Lists the files in a directory specified by the path
|
||||
* Puts the list of file names (NOT DIRECTORIES) into the buffer seperated by newlines
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
*
|
||||
* EIO - Hard error occured in the low level disk I/O layer
|
||||
* EINVAL - file or directory is invalid, or length is invalid
|
||||
* EBUSY - THe physical drinve cannot work
|
||||
* ENOENT - cannot find the path or file
|
||||
* EINVAL - the path name format is invalid
|
||||
* EACCES - Access denied or directory full
|
||||
* EEXIST - Access denied
|
||||
* EROFS - SD card is write protected
|
||||
* ENXIO - drive number is invalid or not a FAT32 drive
|
||||
* ENOBUFS - drive has no work area
|
||||
* ENFILE - too many open files
|
||||
*
|
||||
*
|
||||
*
|
||||
* \note use a path of "\" to list the files in the main directory NOT "/usd/"
|
||||
* DO NOT PREPEND YOUR PATHS WITH "/usd/"
|
||||
*
|
||||
* \return 1 on success or PROS_ERR on failure setting errno
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* char* test = (char*) malloc(128);
|
||||
* pros::usd::list_files("/", test, 128);
|
||||
* pros::delay(200);
|
||||
* printf("%s\n", test); //Prints the file names in the root directory seperated by newlines
|
||||
* pros::delay(100);
|
||||
* pros::list_files("/test", test, 128);
|
||||
* pros::delay(200);
|
||||
* printf("%s\n", test); //Prints the names of files in the folder named test seperated by newlines
|
||||
* pros::delay(100);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
|
||||
std::int32_t list_files(const char* path, char* buffer, std::int32_t len);
|
||||
} // namespace usd
|
||||
|
||||
} // namespace pros
|
||||
|
||||
#endif // _PROS_MISC_HPP_
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,506 @@
|
||||
/**
|
||||
* \file pros/optical.h
|
||||
* \ingroup c-optical
|
||||
*
|
||||
* Contains prototypes for functions related to the VEX Optical sensor.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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/.
|
||||
*
|
||||
* \defgroup c-optical VEX Optical Sensor C API
|
||||
*/
|
||||
|
||||
#ifndef _PROS_OPTICAL_H_
|
||||
#define _PROS_OPTICAL_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "error.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
|
||||
|
||||
/**
|
||||
* \ingroup c-optical
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup c-optical
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \enum optical_direction_e_t
|
||||
*/
|
||||
typedef enum optical_direction_e { NO_GESTURE = 0,
|
||||
/// The direction indicating an upward gesture.
|
||||
UP = 1,
|
||||
/// The direction indicating a downward gesture.
|
||||
DOWN = 2,
|
||||
/// The direction indicating a rightward gesture.
|
||||
RIGHT = 3,
|
||||
/// The direction indicating a leftward gesture.
|
||||
LEFT = 4,
|
||||
ERROR = PROS_ERR
|
||||
} optical_direction_e_t;
|
||||
|
||||
/**
|
||||
* \struct optical_rgb_s_t
|
||||
* The RGB and Brightness values for the optical sensor.
|
||||
*/
|
||||
typedef struct optical_rgb_s {
|
||||
double red;
|
||||
double green;
|
||||
double blue;
|
||||
double brightness;
|
||||
} optical_rgb_s_t;
|
||||
|
||||
/**
|
||||
* \struct optical_raw_s_t
|
||||
* The RGB and clear values for the optical sensor.
|
||||
*/
|
||||
typedef struct optical_raw_s {
|
||||
uint32_t clear;
|
||||
uint32_t red;
|
||||
uint32_t green;
|
||||
uint32_t blue;
|
||||
} optical_raw_s_t;
|
||||
|
||||
/**
|
||||
* \struct optical_gesture_s_t
|
||||
* This structure contains the raw gesture data.
|
||||
*/
|
||||
typedef struct optical_gesture_s {
|
||||
uint8_t udata; ///Up data
|
||||
uint8_t ddata; ///Down data
|
||||
uint8_t ldata; ///Left data
|
||||
uint8_t rdata; ///Right data
|
||||
uint8_t type; ///Type of gesture
|
||||
uint8_t pad; ///Padding
|
||||
uint16_t count; ///Number of gestures
|
||||
uint32_t time; ///Time since gesture recognized
|
||||
} optical_gesture_s_t;
|
||||
|
||||
/**
|
||||
* \name Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define OPTICAL_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("Hue value: %lf \n", optical_get_hue(OPTICAL_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define OPTICAL_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("Saturation value: %lf \n", optical_get_saturation(OPTICAL_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define OPTICAL_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("Brightness value: %lf \n", optical_get_brightness(OPTICAL_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define OPTICAL_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("Proximity value: %d \n", optical_get_proximity(OPTICAL_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define OPTICAL_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* optical_set_led_pwm(OPTICAL_PORT, 50);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define OPTICAL_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("PWM Value: %d \n", optical_get_led_pwm(OPTICAL_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define OPTICAL_PORT 1
|
||||
*
|
||||
* optical_rgb_s_t RGB_values;
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* RGB_values = optical_get_rgb(OPTICAL_PORT);
|
||||
* printf("Red value: %lf \n", RGB_values.red);
|
||||
* printf("Green value: %lf \n", RGB_values.green);
|
||||
* printf("Blue value: %lf \n", RGB_values.blue);
|
||||
* printf("Brightness value: %lf \n", RGB_values.brightness);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define OPTICAL_PORT 1
|
||||
*
|
||||
* optical_raw_s_t raw_values;
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* raw_values = optical_get_raw(OPTICAL_PORT);
|
||||
* printf("Red value: %ld \n", raw_values.red);
|
||||
* printf("Green value: %ld \n", raw_values.green);
|
||||
* printf("Blue value: %ld \n", raw_values.blue);
|
||||
* printf("Clear value: %ld \n", raw_values.clear);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define OPTICAL_PORT 1
|
||||
*
|
||||
* optical_direction_e_t gesture;
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* gesture = optical_get_gesture(OPTICAL_PORT);
|
||||
* printf("Gesture value: %d \n", gesture);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define OPTICAL_PORT 1
|
||||
*
|
||||
* optical_gesture_s_t raw_gesture;
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* raw_gesture = optical_get_gesture_raw(OPTICAL_PORT);
|
||||
* printf("Up data: %u \n", raw_gesture.udata);
|
||||
* printf("Down data: %u \n", raw_gesture.ddata);
|
||||
* printf("Left data: %u \n", raw_gesture.ldata);
|
||||
* printf("Right data: %u \n", raw_gesture.rdata);
|
||||
* printf("Type: %u \n", raw_gesture.type);
|
||||
* printf("Count: %u \n", raw_gesture.count);
|
||||
* printf("Time: %lu \n", raw_gesture.time);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define OPTICAL_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* optical_enable_gesture(OPTICAL_PORT);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define OPTICAL_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* optical_disable_gesture(OPTICAL_PORT);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t optical_disable_gesture(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get integration time (update rate) of the optical sensor in milliseconds, with
|
||||
* minimum time being
|
||||
*
|
||||
* 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 Integration time in milliseconds if the operation is successful
|
||||
* or PROS_ERR if the operation failed, setting errno.
|
||||
*/
|
||||
double optical_get_integration_time(uint8_t port);
|
||||
|
||||
/**
|
||||
* Set integration time (update rate) of the optical sensor in milliseconds.
|
||||
*
|
||||
* 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
|
||||
* \param time
|
||||
* The desired integration time in milliseconds
|
||||
* \return 1 if the operation is successful or PROS_ERR if the operation failed,
|
||||
* setting errno.
|
||||
*/
|
||||
int32_t optical_set_integration_time(uint8_t port, double time);
|
||||
|
||||
///@}
|
||||
|
||||
///@}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,469 @@
|
||||
/**
|
||||
* \file pros/optical.hpp
|
||||
* \ingroup cpp-optical
|
||||
*
|
||||
* Contains prototypes for functions related to the VEX Optical sensor.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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/.
|
||||
*
|
||||
* \defgroup cpp-optical VEX Optical Sensor C++ API
|
||||
*/
|
||||
|
||||
#ifndef _PROS_OPTICAL_HPP_
|
||||
#define _PROS_OPTICAL_HPP_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
#include "pros/device.hpp"
|
||||
#include "pros/optical.h"
|
||||
|
||||
namespace pros {
|
||||
inline namespace v5 {
|
||||
/**
|
||||
* \ingroup cpp-optical
|
||||
*/
|
||||
class Optical : public Device {
|
||||
/**
|
||||
* \addtogroup cpp-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
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.cpp}
|
||||
* pros::Optical optical(1);
|
||||
* \endcode
|
||||
*/
|
||||
Optical(const std::uint8_t port);
|
||||
|
||||
Optical(const Device& device) : Optical(device.get_port()){};
|
||||
|
||||
|
||||
/**
|
||||
* Gets all optical sensors.
|
||||
*
|
||||
* \return A vector of Optical sensor objects.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* std::vector<Optical> optical_all = pros::Optical::get_all_devices(); // All optical sensors that are connected
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
static std::vector<Optical> get_all_devices();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.cpp}
|
||||
* void opcontrol() {
|
||||
* pros::Optical optical(1);
|
||||
* std::cout << "Hue: " << optical.get_hue() << std::endl;
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.cpp}
|
||||
* void opcontrol() {
|
||||
* pros::Optical optical(1);
|
||||
* std::cout << "Saturation: " << optical.get_saturation() << std::endl;
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.cpp}
|
||||
* void opcontrol() {
|
||||
* pros::Optical optical(1);
|
||||
* std::cout << "Brightness: " << optical.get_brightness() << std::endl;
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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 Proximity value if the operation was successful or PROS_ERR if
|
||||
* the operation failed, setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.cpp}
|
||||
* void opcontrol() {
|
||||
* pros::Optical optical(1);
|
||||
* std::cout << "Proximity: " << optical.get_proximity() << std::endl;
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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 or PROS_SUCCESS.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.cpp}
|
||||
* void initialize() {
|
||||
* pros::Optical optical(1);
|
||||
* optical.set_led_pwm(100);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.cpp}
|
||||
* void opcontrol() {
|
||||
* pros::Optical optical(1);
|
||||
* optical.set_led_pwm(100);
|
||||
* std::cout << "LED PWM: " << optical.get_led_pwm() << std::endl;
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.cpp}
|
||||
* void opcontrol() {
|
||||
* pros::Optical optical(1);
|
||||
* pros::c::optical_rgb_s_t rgb = optical.get_rgb();
|
||||
* while(1) {
|
||||
* std::cout << "Red: " << rgb.red << std::endl;
|
||||
* std::cout << "Green: " << rgb.green << std::endl;
|
||||
* std::cout << "Blue: " << rgb.blue << std::endl;
|
||||
* std::cout << "Brightness: " << rgb.brightness << std::endl;
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.cpp}
|
||||
* void opcontrol() {
|
||||
* pros::Optical optical(1);
|
||||
* pros::c::optical_raw_s_t raw = optical.get_raw();
|
||||
* while (1) {
|
||||
* std::cout << "Red: " << raw.red << std::endl;
|
||||
* std::cout << "Green: " << raw.green << std::endl;
|
||||
* std::cout << "Blue: " << raw.blue << std::endl;
|
||||
* std::cout << "Clear: " << raw.clear << std::endl;
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.cpp}
|
||||
* void opcontrol() {
|
||||
* pros::Optical optical(1);
|
||||
* while(1) {
|
||||
* std::cout << "Gesture: " << optical.get_gesture() << std::endl;
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.cpp}
|
||||
* void opcontrol() {
|
||||
* pros::Optical optical(1);
|
||||
* optical.enable_gesture();
|
||||
* while(1) {
|
||||
* pros::c::optical_gesture_s_t gesture = optical.get_gesture_raw();
|
||||
* std::cout << "Gesture raw data: " << std::endl;
|
||||
* std::cout << "Up data: " << gesture.udata << std::endl;
|
||||
* std::cout << "Down data: " << gesture.ddata << std::endl;
|
||||
* std::cout << "Left data: " << gesture.ldata << std::endl;
|
||||
* std::cout << "Right data: " << gesture.rdata << std::endl;
|
||||
* std::cout << "Type: " << gesture.type << std::endl;
|
||||
* std::cout << "Count: " << gesture.count << std::endl;
|
||||
* std::cout << "Time: " << gesture.time << std::endl;
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.cpp}
|
||||
* void opcontrol() {
|
||||
* pros::Optical optical(1);
|
||||
* optical.enable_gesture();
|
||||
* while(1) {
|
||||
* pros::c::optical_gesture_s_t gesture = optical.get_gesture_raw();
|
||||
* std::cout << "Gesture raw data: " << std::endl;
|
||||
* std::cout << "Up data: " << gesture.udata << std::endl;
|
||||
* std::cout << "Down data: " << gesture.ddata << std::endl;
|
||||
* std::cout << "Left data: " << gesture.ldata << std::endl;
|
||||
* std::cout << "Right data: " << gesture.rdata << std::endl;
|
||||
* std::cout << "Type: " << gesture.type << std::endl;
|
||||
* std::cout << "Count: " << gesture.count << std::endl;
|
||||
* std::cout << "Time: " << gesture.time << std::endl;
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.cpp}
|
||||
* void opcontrol() {
|
||||
* pros::Optical optical(1);
|
||||
* optical.enable_gesture();
|
||||
* while(1) {
|
||||
* if(optical.get_gesture() != 0) {
|
||||
* std::cout << "Gesture detected!"<< std::endl;
|
||||
* optical.disable_gesture();
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t disable_gesture();
|
||||
|
||||
/**
|
||||
* Set integration time (update rate) of the optical sensor in milliseconds, with
|
||||
* minimum time being 3 ms and maximum time being 712 ms. Default is 100 ms, with the
|
||||
* optical sensor communciating with the V5 brain every 20 ms.
|
||||
*
|
||||
* 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_F if the operation failed,
|
||||
* setting errno.
|
||||
*/
|
||||
double get_integration_time();
|
||||
|
||||
/**
|
||||
* Get integration time (update rate) of the optical sensor in milliseconds.
|
||||
*
|
||||
* 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 time
|
||||
* The desired integration time in milliseconds
|
||||
* \return Integration time in milliseconds if the operation is successful
|
||||
* or PROS_ERR if the operation failed, setting errno.
|
||||
*/
|
||||
std::int32_t set_integration_time(double time);
|
||||
|
||||
/**
|
||||
* This is the overload for the << operator for printing to streams
|
||||
*
|
||||
* Prints in format(this below is all in one line with no new line):
|
||||
* Optical [port: (port number), hue: (hue), saturation: (saturation),
|
||||
* brightness: (brightness), proximity: (proximity), rgb: {red, green, blue}]
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.cpp}
|
||||
* pros::Optical optical(1);
|
||||
* std::cout << optical << std::endl;
|
||||
* \endcode
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& os, pros::Optical& optical);
|
||||
|
||||
private:
|
||||
///@}
|
||||
};
|
||||
|
||||
namespace literals {
|
||||
/**
|
||||
* Constructs a Optical sensor from a literal ending in _opt
|
||||
*
|
||||
* \return a pros::Optical for the corresponding port
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* using namespace pros::literals;
|
||||
* void opcontrol() {
|
||||
* pros::Optical opt = 2_opt; //Makes an Optical object on port 2
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
const pros::Optical operator"" _opt(const unsigned long long int o);
|
||||
} // namespace literals
|
||||
} // namespace v5
|
||||
} // namespace pros
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,390 @@
|
||||
/**
|
||||
* \file pros/rotation.h
|
||||
* \ingroup c-rotation
|
||||
*
|
||||
* Contains prototypes for functions related to the VEX Rotation Sensor.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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/.
|
||||
*
|
||||
* \defgroup c-rotation VEX Rotation Sensor C API
|
||||
*/
|
||||
|
||||
#ifndef _PROS_ROTATION_H_
|
||||
#define _PROS_ROTATION_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
namespace pros {
|
||||
namespace c {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \ingroup c-rotation
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup c-rotation
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define ROTATION_MINIMUM_DATA_RATE 5
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define ROTATION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
*
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* rotation_reset(ROTATION_PORT);
|
||||
* }
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t rotation_reset(uint8_t port);
|
||||
|
||||
/**
|
||||
* Set the Rotation Sensor's refresh interval in milliseconds.
|
||||
*
|
||||
* The rate may be specified in increments of 5ms, and will be rounded down to
|
||||
* the nearest increment. The minimum allowable refresh rate is 5ms. The default
|
||||
* rate is 10ms.
|
||||
*
|
||||
* 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 rate The data refresh interval in milliseconds
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define ROTATION_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* pros::Rotation rotation_sensor(ROTATION_PORT);
|
||||
* rotation_set_data_rate(ROTATION_PORT, 5);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t rotation_set_data_rate(uint8_t port, uint32_t rate);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define ROTATION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
*
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* rotation_set_position(ROTATION_PORT, 600);
|
||||
* }
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define ROTATION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
*
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* rotation_reset_position(ROTATION_PORT);
|
||||
* }
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define ROTATION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("Position: %d centidegrees \n", rotation_get_position(ROTATION_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define ROTATION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("Velocity: %d centidegrees per second \n", rotation_get_velocity(ROTATION_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t rotation_get_velocity(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the Rotation Sensor's current angle in centidegrees (0-36000)
|
||||
*
|
||||
* 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 (0-36000) or PROS_ERR_F if the operation failed, setting
|
||||
* errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define ROTATION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("Angle: %d centidegrees \n", rotation_get_angle(ROTATION_PORT));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define ROTATION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Rotation rotation_sensor(ROTATION_PORT);
|
||||
* while (true) {
|
||||
*
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* rotation_set_reversed(ROTATION_PORT, true); // Reverses the Rotation Sensor on ROTATION_PORT
|
||||
* }
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define ROTATION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Rotation rotation_sensor(ROTATION_PORT);
|
||||
* while (true) {
|
||||
*
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* rotation_reverse(ROTATION_PORT);
|
||||
* }
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t rotation_reverse(uint8_t port);
|
||||
|
||||
/**
|
||||
* Initialize the Rotation Sensor with a reverse 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 reverse_flag
|
||||
* Determines if the Rotation Sensor is reversed or not.
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define ROTATION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Rotation rotation_sensor(ROTATION_PORT);
|
||||
* bool reverse_flag = true;
|
||||
* while (true) {
|
||||
*
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* rotation_init_reverse(ROTATION_PORT, reverse_flag);
|
||||
* }
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t rotation_init_reverse(uint8_t port, bool reverse_flag);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define ROTATION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* Rotation rotation_sensor(ROTATION_PORT);
|
||||
* while (true) {
|
||||
*
|
||||
* if(controller_get_digital(CONTROLLER_MASTER, E_CONTROLLER_DIGITAL_X)){
|
||||
* rotation_get_reversed(ROTATION_PORT);
|
||||
* }
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t rotation_get_reversed(uint8_t port);
|
||||
|
||||
///@}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} //namespace C
|
||||
} //namespace pros
|
||||
} //extern "C"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,394 @@
|
||||
/**
|
||||
* \file pros/rotation.hpp
|
||||
* \ingroup cpp-rotation
|
||||
*
|
||||
* Contains prototypes for functions related to the VEX Rotation Sensor.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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/.
|
||||
*
|
||||
* \defgroup cpp-rotation VEX Rotation Sensor C++ API
|
||||
*/
|
||||
#ifndef _PROS_ROTATION_HPP_
|
||||
#define _PROS_ROTATION_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
#include "pros/device.hpp"
|
||||
#include "pros/rotation.h"
|
||||
|
||||
namespace pros {
|
||||
inline namespace v5 {
|
||||
/**
|
||||
* \ingroup cpp-rotation
|
||||
*/
|
||||
class Rotation : public Device {
|
||||
/**
|
||||
* \addtogroup cpp-rotation
|
||||
* @{
|
||||
*/
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructs a new Rotation Sensor object
|
||||
*
|
||||
* ENXIO - The given value is not within the range of V5 ports |1-21|.
|
||||
* ENODEV - The port cannot be configured as a Rotation Sensor
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1 to 21, or from -21 to -1 for reversed Rotation Sensors.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Rotation rotation_sensor(1); //Creates a Rotation Sensor on port 1
|
||||
* pros::Rotation reversed_rotation_sensor(-2); //Creates a reversed Rotation Sensor on port 2
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
Rotation(const std::int8_t port);
|
||||
|
||||
Rotation(const Device& device) : Rotation(device.get_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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Rotation rotation_sensor(1);
|
||||
* pros::Controller master (E_CONTROLLER_MASTER);
|
||||
* while (true) {
|
||||
* if(master.get_analog(E_CONTROLLER_DIGITAL_X) {
|
||||
* rotation_sensor.reset();
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t reset();
|
||||
|
||||
/**
|
||||
* Set the Rotation Sensor's refresh interval in milliseconds.
|
||||
*
|
||||
* The rate may be specified in increments of 5ms, and will be rounded down to
|
||||
* the nearest increment. The minimum allowable refresh rate is 5ms. The default
|
||||
* rate is 10ms.
|
||||
*
|
||||
* As values are copied into the shared memory buffer only at 10ms intervals,
|
||||
* setting this value to less than 10ms does not mean that you can poll the
|
||||
* sensor's values any faster. However, it will guarantee that the data is as
|
||||
* recent as possible.
|
||||
*
|
||||
* 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 rate The data refresh interval in milliseconds
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* pros::Rotation rotation_sensor(1);
|
||||
* rotation_sensor.set_data_rate(5);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t set_data_rate(std::uint32_t rate) const;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Rotation rotation_sensor(1);
|
||||
* pros::Controller master (E_CONTROLLER_MASTER);
|
||||
* while (true) {
|
||||
* if(master.get_analog(E_CONTROLLER_DIGITAL_X) {
|
||||
* rotation_sensor.set_position(600);
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t set_position(std::uint32_t position) const;
|
||||
|
||||
/**
|
||||
* 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 position
|
||||
* The position in terms of ticks
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Rotation rotation_sensor(1);
|
||||
* pros::Controller master (E_CONTROLLER_MASTER);
|
||||
* while (true) {
|
||||
* if(master.get_analog(E_CONTROLLER_DIGITAL_X) {
|
||||
* rotation_sensor.reset_position();
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t reset_position(void) const;
|
||||
|
||||
/**
|
||||
* Gets all rotation sensors.
|
||||
*
|
||||
* \return A vector of Rotation sensor objects.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* std::vector<Rotation> rotation_all = pros::Rotation::get_all_devices(); // All rotation sensors that are connected
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
static std::vector<Rotation> get_all_devices();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Rotation rotation_sensor(1);
|
||||
* while (true) {
|
||||
* printf("Position: %d Ticks \n", rotation_sensor.get_position());
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t get_position() const;
|
||||
|
||||
/**
|
||||
* 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 if the operation failed, setting
|
||||
* errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Rotation rotation_sensor(1);
|
||||
* while (true) {
|
||||
* printf("Velocity: %d centidegrees per second \n", rotation_sensor.get_velocity));
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t get_velocity() const;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Rotation rotation_sensor(1);
|
||||
* while (true) {
|
||||
* printf("Angle: %d centidegrees \n", rotation_sensor.get_angle());
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t get_angle() const;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Rotation rotation_sensor(1);
|
||||
* pros::Controller master (E_CONTROLLER_MASTER);
|
||||
* while (true) {
|
||||
* if(master.get_analog(E_CONTROLLER_DIGITAL_X) {
|
||||
* rotation_sensor.set_reversed(true); // Reverses the Rotation Sensor
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t set_reversed(bool value) const;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Rotation rotation_sensor(1);
|
||||
* pros::Controller master (E_CONTROLLER_MASTER);
|
||||
* while (true) {
|
||||
* if(master.get_analog(E_CONTROLLER_DIGITAL_X) {
|
||||
* rotation_sensor.reverse();
|
||||
* }
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t reverse() const;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Rotation rotation_sensor(1);
|
||||
* while (true) {
|
||||
* printf("Reversed: %d \n", rotation_sensor.get_reversed());
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t get_reversed() const;
|
||||
|
||||
/**
|
||||
* This is the overload for the << operator for printing to streams
|
||||
*
|
||||
* Prints in format(this below is all in one line with no new line):
|
||||
* Rotation [port: rotation._port, position: (rotation position), velocity: (rotation velocity),
|
||||
* angle: (rotation angle), reversed: (reversed boolean)]
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define ROTATION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::Rotation rotation_sensor(1);
|
||||
* while(true) {
|
||||
* std::cout << rotation_sensor << std::endl;
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
friend std::ostream& operator<<(std::ostream& os, const pros::Rotation& rotation);
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
namespace literals {
|
||||
/**
|
||||
* Constructs a Rotation sensor from a literal ending in _rot
|
||||
*
|
||||
* \return a pros::Rotation for the corresponding port
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* using namespace pros::literals;
|
||||
* void opcontrol() {
|
||||
* pros::Rotation rotation = 2_rot; //Makes an Motor object on port 2
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
const pros::Rotation operator"" _rot(const unsigned long long int r);
|
||||
} // namespace literals
|
||||
} // namespace v5
|
||||
} // namespace pros
|
||||
|
||||
#endif
|
||||
+1108
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,791 @@
|
||||
/**
|
||||
* \file screen.h
|
||||
* \ingroup c-screen
|
||||
*
|
||||
* Brain screen display and touch functions.
|
||||
*
|
||||
* Contains user calls to the v5 screen for touching and displaying graphics.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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/.
|
||||
*
|
||||
* \defgroup c-screen Simplified Brain Screen C API
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _PROS_SCREEN_H_
|
||||
#define _PROS_SCREEN_H_
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#undef _GNU_SOURCE
|
||||
#include <stdint.h>
|
||||
|
||||
#include "pros/colors.h" // c color macros
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
namespace pros {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \ingroup c-screen
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup c-screen
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* \enum text_format_e_t
|
||||
* Different font sizes that can be used in printing text.
|
||||
*/
|
||||
typedef enum {
|
||||
/// Small text font size
|
||||
E_TEXT_SMALL = 0,
|
||||
/// Normal/Medium text font size
|
||||
E_TEXT_MEDIUM,
|
||||
/// Large text font size
|
||||
E_TEXT_LARGE,
|
||||
/// Medium centered text
|
||||
E_TEXT_MEDIUM_CENTER,
|
||||
/// Large centered text
|
||||
E_TEXT_LARGE_CENTER
|
||||
} text_format_e_t;
|
||||
|
||||
/**
|
||||
* \enum last_touch_e_t
|
||||
* Enum indicating what the current touch status is for the touchscreen.
|
||||
*/
|
||||
typedef enum {
|
||||
/// Last interaction with screen was a quick press
|
||||
E_TOUCH_RELEASED = 0,
|
||||
/// Last interaction with screen was a release
|
||||
E_TOUCH_PRESSED,
|
||||
/// User is holding screen down
|
||||
E_TOUCH_HELD,
|
||||
/// An error occured while taking/returning the mutex
|
||||
E_TOUCH_ERROR
|
||||
} last_touch_e_t;
|
||||
|
||||
/**
|
||||
* \struct screen_touch_status_s_t
|
||||
* Struct representing screen touch status, screen last x, screen last y, press count, release count.
|
||||
*/
|
||||
typedef struct screen_touch_status_s {
|
||||
last_touch_e_t touch_status; ///< Represents if the screen is being held, released, or pressed.
|
||||
int16_t x; ///< Represents the x value of the location of the touch.
|
||||
int16_t y; ///< Represents the y value of the location of the touch.
|
||||
int32_t press_count; ///< Represents how many times the screen has be pressed.
|
||||
int32_t release_count; ///< Represents how many times the user released after a touch on the screen.
|
||||
} screen_touch_status_s_t;
|
||||
|
||||
#ifdef PROS_USE_SIMPLE_NAMES
|
||||
#ifdef __cplusplus
|
||||
#define TEXT_SMALL pros::E_TEXT_SMALL
|
||||
#define TEXT_MEDIUM pros::E_TEXT_MEDIUM
|
||||
#define TEXT_LARGE pros::E_TEXT_LARGE
|
||||
#define TEXT_MEDIUM_CENTER pros::E_TEXT_MEDIUM_CENTER
|
||||
#define TEXT_LARGE_CENTER pros::E_TEXT_LARGE_CENTER
|
||||
#define TOUCH_RELEASED pros::E_TOUCH_RELEASED
|
||||
#define TOUCH_PRESSED pros::E_TOUCH_PRESSED
|
||||
#define TOUCH_HELD pros::E_TOUCH_HELD
|
||||
#else
|
||||
#define TEXT_SMALL E_TEXT_SMALL
|
||||
#define TEXT_MEDIUM E_TEXT_MEDIUM
|
||||
#define TEXT_LARGE E_TEXT_LARGE
|
||||
#define TEXT_MEDIUM_CENTER E_TEXT_MEDIUM_CENTER
|
||||
#define TEXT_LARGE_CENTER E_TEXT_LARGE_CENTER
|
||||
#define TOUCH_RELEASED E_TOUCH_RELEASED
|
||||
#define TOUCH_PRESSED E_TOUCH_PRESSED
|
||||
#define TOUCH_HELD E_TOUCH_HELD
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef void (*touch_event_cb_fn_t)();
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace c {
|
||||
#endif
|
||||
|
||||
/// \name Screen Graphical Display Functions
|
||||
/// These functions allow programmers to display shapes on the v5 screen
|
||||
///@{
|
||||
|
||||
/**
|
||||
* Set the pen color for subsequent graphics operations
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param color The pen color to set (it is recommended to use values
|
||||
* from the enum defined in colors.h)
|
||||
*
|
||||
* \return Returns 1 if the mutex was successfully returned, or PROS_ERR if
|
||||
* there was an error either taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* screen_set_pen(COLOR_RED);
|
||||
* }
|
||||
*
|
||||
* void opcontrol() {
|
||||
* int iter = 0;
|
||||
* while(1){
|
||||
* // This should print in red.
|
||||
* screen_print(TEXT_MEDIUM, 1, "%d", iter++);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_set_pen(uint32_t color);
|
||||
|
||||
/**
|
||||
* Set the eraser color for erasing and the current background.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param color The background color to set (it is recommended to use values
|
||||
* from the enum defined in colors.h)
|
||||
*
|
||||
* \return Returns 1 if the mutex was successfully returned, or
|
||||
* PROS_ERR if there was an error either taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* screen_set_eraser(COLOR_RED);
|
||||
* }
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while(1){
|
||||
* // This should turn the screen red.
|
||||
* screen_erase();
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_set_eraser(uint32_t color);
|
||||
|
||||
/**
|
||||
* Get the current pen color.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \return The current pen color in the form of a value from the enum defined
|
||||
* in colors.h, or PROS_ERR if there was an error taking or returning
|
||||
* the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* screen_set_pen(COLOR_RED);
|
||||
* }
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while(1){
|
||||
* // Should print number equivalent to COLOR_RED defined in colors.h.
|
||||
* screen_print(TEXT_MEDIUM, 1, "%d", screen_get_pen());
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_get_pen(void);
|
||||
|
||||
/**
|
||||
* Get the current eraser color.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \return The current eraser color in the form of a value from the enum
|
||||
* defined in colors.h, or PROS_ERR if there was an error taking or
|
||||
* returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* screen_set_eraser(COLOR_RED);
|
||||
* }
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while(1){
|
||||
* // Should print number equivalent to COLOR_RED defined in colors.h.
|
||||
* screen_print(TEXT_MEDIUM, 1, "%d", screen_get_eraser());
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_get_eraser(void);
|
||||
|
||||
/**
|
||||
* Clear display with eraser color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* screen_set_eraser(COLOR_RED);
|
||||
* }
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while(1){
|
||||
* // This should turn the screen red.
|
||||
* screen_erase();
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_erase(void);
|
||||
|
||||
/**
|
||||
* Scroll lines on the display upwards.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param start_line The line from which scrolling will start
|
||||
* \param lines The number of lines to scroll up
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* screen_print(TEXT_MEDIUM, 4, "Line Here");
|
||||
* // Scroll 3 lines
|
||||
* screen_scroll(4, 3);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_scroll(int16_t start_line, int16_t lines);
|
||||
|
||||
/**
|
||||
* Scroll lines within a region on the display
|
||||
*
|
||||
* This function behaves in the same way as `screen_scroll`, except that you
|
||||
* specify a rectangular region within which to scroll lines instead of a start
|
||||
* line.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x0, y0 The (x,y) coordinates of the first corner of the
|
||||
* rectangular region
|
||||
* \param x1, y1 The (x,y) coordinates of the second corner of the
|
||||
* rectangular region
|
||||
* \param lines The number of lines to scroll upwards
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* screen_print(TEXT_MEDIUM, 1, "Line Here");
|
||||
* // Scrolls area of screen upwards slightly. including line of text
|
||||
* screen_scroll_area(0,0, 400, 200, 3);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_scroll_area(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t lines);
|
||||
|
||||
/**
|
||||
* Copy a screen region (designated by a rectangle) from an off-screen buffer
|
||||
* to the screen
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x0, y0 The (x,y) coordinates of the first corner of the
|
||||
* rectangular region of the screen
|
||||
* \param x1, y1 The (x,y) coordinates of the second corner of the
|
||||
* rectangular region of the screen
|
||||
* \param buf Off-screen buffer containing screen data
|
||||
* \param stride Off-screen buffer width in pixels, such that image size
|
||||
* is stride-padding
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* uint32_t* buf = malloc(sizeof(uint32_t) * 400 * 200);
|
||||
* screen_print(TEXT_MEDIUM, 1, "Line Here");
|
||||
* // Copies area of the screen including text
|
||||
* screen_copy_area(0, 0, 400, 200, (uint32_t*)buf, 400 + 1);
|
||||
* // Equation for stride is x2 - x1 + 1
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_copy_area(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint32_t* buf, int32_t stride);
|
||||
|
||||
/**
|
||||
* Draw a single pixel on the screen using the current pen color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x, y The (x,y) coordinates of the pixel
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* int i = 0;
|
||||
* void opcontrol() {
|
||||
* while(i < 200){
|
||||
* screen_draw_pixel(100,i++);
|
||||
* // Draws a line at x = 100 gradually down the screen, pixel by pixel
|
||||
* delay(200);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_draw_pixel(int16_t x, int16_t y);
|
||||
|
||||
/**
|
||||
* Erase a pixel from the screen (Sets the location)
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x, y The (x,y) coordinates of the erased
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* // Color the Screen in Red
|
||||
* screen_set_pen(COLOR_RED);
|
||||
* screen_fill_rect(0,0,400,200);
|
||||
* int i = 0;
|
||||
* while(i < 200){
|
||||
* screen_erase_pixel(100,i++);
|
||||
* // Erases a line at x = 100 gradually down the screen, pixel by pixel
|
||||
* delay(200);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_erase_pixel(int16_t x, int16_t y);
|
||||
|
||||
/**
|
||||
* Draw a line on the screen using the current pen color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x0, y0 The (x, y) coordinates of the first point of the line
|
||||
* \param x1, y1 The (x, y) coordinates of the second point of the line
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* screen_set_pen(COLOR_RED);
|
||||
* // Draw line down the screen at x = 100
|
||||
* screen_draw_line(100,0,100,200);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1);
|
||||
|
||||
/**
|
||||
* Erase a line on the screen using the current eraser color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x0, y0 The (x, y) coordinates of the first point of the line
|
||||
* \param x1, y1 The (x, y) coordinates of the second point of the line
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* // Color the Screen in Red
|
||||
* screen_set_pen(COLOR_RED);
|
||||
* screen_fill_rect(0,0,400,200);
|
||||
* // Erase line down the screen at x = 100
|
||||
* screen_erase_line(100,0,100,200);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_erase_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1);
|
||||
|
||||
/**
|
||||
* Draw a rectangle on the screen using the current pen color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x0, y0 The (x,y) coordinates of the first point of the rectangle
|
||||
* \param x1, y1 The (x,y) coordinates of the second point of the rectangle
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* screen_set_pen(COLOR_RED);
|
||||
* screen_draw_rect(1,1,480,200);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_draw_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1);
|
||||
|
||||
/**
|
||||
* Erase a rectangle on the screen using the current eraser color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x0, y0 The (x,y) coordinates of the first point of the rectangle
|
||||
* \param x1, y1 The (x,y) coordinates of the second point of the rectangle
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* // Draw Box Around Half the Screen in Red
|
||||
* screen_set_eraser(COLOR_RED);
|
||||
* screen_erase_rect(5,5,240,200);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_erase_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1);
|
||||
|
||||
/**
|
||||
* Fill a rectangular region of the screen using the current pen
|
||||
* color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x0, y0 The (x,y) coordinates of the first point of the rectangle
|
||||
* \param x1, y1 The (x,y) coordinates of the second point of the rectangle
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* // Fill Around Half the Screen in Red
|
||||
* screen_set_pen(COLOR_RED);
|
||||
* screen_fill_rect(5,5,240,200);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_fill_rect(int16_t x0, int16_t y0, int16_t x1, int16_t y1);
|
||||
|
||||
/**
|
||||
* Draw a circle on the screen using the current pen color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x, y The (x,y) coordinates of the center of the circle
|
||||
* \param r The radius of the circle
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* // Draw a circle with radius of 100 in red
|
||||
* screen_set_pen(COLOR_RED);
|
||||
* screen_draw_circle(240, 200, 100);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_draw_circle(int16_t x, int16_t y, int16_t radius);
|
||||
|
||||
/**
|
||||
* Erase a circle on the screen using the current eraser color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x, y The (x,y) coordinates of the center of the circle
|
||||
* \param r The radius of the circle
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* screen_set_pen(COLOR_RED);
|
||||
* screen_fill_rect(5,5,240,200);
|
||||
* // Erase a circle with radius of 100 in COLOR_BLUE
|
||||
* screen_set_pen(COLOR_BLUE);
|
||||
* screen_erase_circle(240, 200, 100);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_erase_circle(int16_t x, int16_t y, int16_t radius);
|
||||
|
||||
/**
|
||||
* Fill a circular region of the screen using the current pen
|
||||
* color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x, y The (x,y) coordinates of the center of the circle
|
||||
* \param r The radius of the circle
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* screen_set_pen(COLOR_RED);
|
||||
* screen_fill_rect(5,5,240,200);
|
||||
* // Fill a circlular area with radius of 100 in COLOR_BLUE
|
||||
* screen_set_pen(COLOR_BLUE);
|
||||
* screen_fill_circle(240, 200, 100);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_fill_circle(int16_t x, int16_t y, int16_t radius);
|
||||
|
||||
///@}
|
||||
|
||||
/// \name Screen Text Display Functions
|
||||
/// These functions allow programmers to display text on the v5 screen
|
||||
///@{
|
||||
|
||||
/**
|
||||
* Print a formatted string to the screen on the specified line
|
||||
*
|
||||
* Will default to a medium sized font by default if invalid txt_fmt is given.
|
||||
*
|
||||
* \param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES
|
||||
* NOT SUPPORT SMALL) \param line The line number on which to print \param text Format string \param ... Optional list
|
||||
* of arguments for the format string
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* int i = 0;
|
||||
*
|
||||
* screen_set_pen(COLOR_BLUE);
|
||||
* while(1){
|
||||
* // Will print seconds started since program started on line 3
|
||||
* screen_print(TEXT_MEDIUM, 3, "Seconds Passed: %3d", i++);
|
||||
* delay(1000);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_print(text_format_e_t txt_fmt, const int16_t line, const char* text, ...);
|
||||
|
||||
/**
|
||||
* Print a formatted string to the screen at the specified point
|
||||
*
|
||||
* Will default to a medium sized font by default if invalid txt_fmt is given.
|
||||
*
|
||||
* Text formats medium_center and large_center will default to medium and large respectively.
|
||||
*
|
||||
* \param txt_fmt Text format enum that determines if the text is small, medium, or large.
|
||||
* \param x The y coordinate of the top left corner of the string
|
||||
* \param y The x coordinate of the top left corner of the string
|
||||
* \param text Format string
|
||||
* \param ... Optional list of arguments for the format string
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* int i = 0;
|
||||
*
|
||||
* screen_set_pen(COLOR_BLUE);
|
||||
* while(1){
|
||||
* // Will print seconds started since program started.
|
||||
* screen_print_at(TEXT_SMALL, 3, "Seconds Passed: %3d", i++);
|
||||
* delay(1000);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_print_at(text_format_e_t txt_fmt, const int16_t x, const int16_t y, const char* text, ...);
|
||||
|
||||
/**
|
||||
* Print a formatted string to the screen on the specified line
|
||||
*
|
||||
* Same as `display_printf` except that this uses a `va_list` instead of the
|
||||
* ellipsis operator so this can be used by other functions.
|
||||
*
|
||||
* Will default to a medium sized font by default if invalid txt_fmt is given.
|
||||
* Exposed mostly for writing libraries and custom functions.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES
|
||||
* NOT SUPPORT SMALL) \param line The line number on which to print \param text Format string \param args List of
|
||||
* arguments for the format string
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* while taking or returning the screen mutex.
|
||||
*
|
||||
*
|
||||
*/
|
||||
uint32_t screen_vprintf(text_format_e_t txt_fmt, const int16_t line, const char* text, va_list args);
|
||||
|
||||
/**
|
||||
* Print a formatted string to the screen at the specified coordinates
|
||||
*
|
||||
* Same as `display_printf_at` except that this uses a `va_list` instead of the
|
||||
* ellipsis operator so this can be used by other functions.
|
||||
*
|
||||
* Will default to a medium sized font by default if invalid txt_fmt is given.
|
||||
*
|
||||
* Text formats medium_center and large_center will default to medium and large respectively.
|
||||
* Exposed mostly for writing libraries and custom functions.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param txt_fmt Text format enum that determines if the text is small, medium, or large.
|
||||
* \param x, y The (x,y) coordinates of the top left corner of the string
|
||||
* \param text Format string
|
||||
* \param args List of arguments for the format string
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* while taking or returning the screen mutex.
|
||||
*
|
||||
*/
|
||||
uint32_t screen_vprintf_at(text_format_e_t txt_fmt, const int16_t x, const int16_t y, const char* text, va_list args);
|
||||
|
||||
///@}
|
||||
|
||||
/// \name Screen Touch Functions
|
||||
/// These functions allow programmers to access information about screen touches
|
||||
///@{
|
||||
|
||||
/**
|
||||
* Gets the touch status of the last touch of the screen.
|
||||
*
|
||||
* \return The last_touch_e_t enum specifier that indicates the last touch status of the screen (E_TOUCH_EVENT_RELEASE,
|
||||
* E_TOUCH_EVENT_PRESS, or E_TOUCH_EVENT_PRESS_AND_HOLD). This will be released by default if no action was taken. If an
|
||||
* error occured, the screen_touch_status_s_t will have its last_touch_e_t enum specifier set to E_TOUCH_ERR, and other
|
||||
* values set to -1.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* int i = 0;
|
||||
* screen_touch_status_s_t status;
|
||||
* while(1){
|
||||
* status = screen_touch_status();
|
||||
*
|
||||
* // Will print various information about the last touch
|
||||
* screen_print(TEXT_MEDIUM, 1, "Touch Status (Type): %d", status.touch_status);
|
||||
* screen_print(TEXT_MEDIUM, 2, "Last X: %d", status.x);
|
||||
* screen_print(TEXT_MEDIUM, 3, "Last Y: %d", status.y);
|
||||
* screen_print(TEXT_MEDIUM, 4, "Press Count: %d", status.press_count);
|
||||
* screen_print(TEXT_MEDIUM, 5, "Release Count: %d", status.release_count);
|
||||
* delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
screen_touch_status_s_t screen_touch_status(void);
|
||||
|
||||
/**
|
||||
* Assigns a callback function to be called when a certain touch event happens.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param cb Function pointer to callback when event type happens
|
||||
* \param event_type Touch event that will trigger the callback.
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* while taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* touch_event_cb_fn_t changePixel(){
|
||||
* screen_touch_status_s_t status = screen_touch_status();
|
||||
* screen_draw_pixel(status.x,status.y);
|
||||
* return NULL;
|
||||
* }
|
||||
*
|
||||
* void opcontrol() {
|
||||
* screen_touch_callback(changePixel(), TOUCH_PRESSED);
|
||||
* while(1) delay(20);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
uint32_t screen_touch_callback(touch_event_cb_fn_t cb, last_touch_e_t event_type);
|
||||
|
||||
///@}
|
||||
|
||||
///@}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // namespace c
|
||||
} // namespace pros
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,717 @@
|
||||
/**
|
||||
* \file screen.hpp
|
||||
* \ingroup cpp-screen
|
||||
*
|
||||
* Brain screen display and touch functions.
|
||||
*
|
||||
* Contains user calls to the v5 screen for touching and displaying graphics.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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/.
|
||||
*
|
||||
* \defgroup cpp-screen Simplified Brain Screen C++ API
|
||||
*/
|
||||
|
||||
#ifndef _PROS_SCREEN_HPP_
|
||||
#define _PROS_SCREEN_HPP_
|
||||
|
||||
#include "pros/screen.h"
|
||||
#include "pros/colors.hpp"
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace pros {
|
||||
namespace screen {
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
|
||||
namespace {
|
||||
template <typename T>
|
||||
T convert_args(T arg) {
|
||||
return arg;
|
||||
}
|
||||
const char* convert_args(const std::string& arg) {
|
||||
return arg.c_str();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/**
|
||||
* \ingroup cpp-screen
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup cpp-screen
|
||||
* @{
|
||||
*/
|
||||
|
||||
/******************************************************************************/
|
||||
/** Screen Graphical Display Functions **/
|
||||
/** **/
|
||||
/** These functions allow programmers to display shapes on the v5 screen **/
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* Set the pen color for subsequent graphics operations
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param color The pen color to set (it is recommended to use values
|
||||
* from the enum defined in colors.hpp)
|
||||
*
|
||||
* \return Returns 1 if the mutex was successfully returned, or PROS_ERR if
|
||||
* there was an error either taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* pros::screen::set_pen(red);
|
||||
* }
|
||||
*
|
||||
* void opcontrol() {
|
||||
* int iter = 0;
|
||||
* while(1){
|
||||
* // This should print in red.
|
||||
* pros::screen::print(TEXT_MEDIUM, 1, "%d", iter++);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t set_pen(pros::Color color);
|
||||
|
||||
/**
|
||||
* Set the pen color for subsequent graphics operations
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param color The pen color to set (in hex form)
|
||||
*
|
||||
* \return Returns 1 if the mutex was successfully returned, or PROS_ERR if
|
||||
* there was an error either taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* //set pen color to red
|
||||
* pros::screen::set_pen(0x00FF0000);
|
||||
* }
|
||||
*
|
||||
* void opcontrol() {
|
||||
* int iter = 0;
|
||||
* while(1){
|
||||
* // This should print in red.
|
||||
* pros::screen::print(TEXT_MEDIUM, 1, "%d", iter++);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t set_pen(std::uint32_t color);
|
||||
|
||||
/**
|
||||
* Set the eraser color for erasing and the current background.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param color The background color to set (it is recommended to use values
|
||||
* from the enum defined in colors.hpp)
|
||||
*
|
||||
* \return Returns 1 if the mutex was successfully returned, or PROS_ERR
|
||||
* if there was an error either taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* //set eraser color to red
|
||||
* set_eraser(red);
|
||||
* }
|
||||
*
|
||||
* void opcontrol() {
|
||||
* int iter = 0;
|
||||
* while(1){
|
||||
* // This should print in red.
|
||||
* pros::screen::print(TEXT_MEDIUM, 1, "%d", iter++);
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t set_eraser(pros::Color color);
|
||||
|
||||
/**
|
||||
* Set the eraser color for erasing and the current background.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param color The background color to set to set (in hex form)
|
||||
*
|
||||
* \return Returns 1 if the mutex was successfully returned, or PROS_ERR
|
||||
* if there was an error either taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* //set eraser color to red
|
||||
* pros::screen::set_eraser(0x00FF0000);
|
||||
* }
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while(1){
|
||||
* // This should turn the screen red.
|
||||
* pros::screen::erase();
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t set_eraser(std::uint32_t color);
|
||||
|
||||
/**
|
||||
* Get the current pen color.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \return The current pen color in the form of a value from the enum
|
||||
* defined in colors.h, or PROS_ERR if there was an error taking or
|
||||
* returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* pros::screen::set_pen(red);
|
||||
* }
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while(1){
|
||||
* // Should print number equivalent to red defined in colors.hpp.
|
||||
* pros::screen::print(TEXT_MEDIUM, 1, "%d", get_pen());
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t get_pen();
|
||||
|
||||
/**
|
||||
* Get the current eraser color.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \return The current eraser color in the form of a value from the enum
|
||||
* defined in colors.h, or PROS_ERR if there was an error taking or
|
||||
* returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* pros::screen::set_eraser(red);
|
||||
* }
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while(1){
|
||||
* // Should print number equivalent to red defined in colors.h.
|
||||
* pros::screen::print(TEXT_MEDIUM, 1, "%d", get_eraser());
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t get_eraser();
|
||||
|
||||
/**
|
||||
* Clear display with eraser color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* * \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* pros::screen::set_eraser(red);
|
||||
* }
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while(1){
|
||||
* // This should turn the screen red.
|
||||
* pros::screen::erase();
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t erase();
|
||||
|
||||
/**
|
||||
* Scroll lines on the display upwards.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param start_line The line from which scrolling will start
|
||||
* \param lines The number of lines to scroll up
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::screen::print(TEXT_MEDIUM, 4, "Line Here");
|
||||
* // Scroll 3 lines
|
||||
* pros::screen::scroll(4, 3);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t scroll(const std::int16_t start_line, const std::int16_t lines);
|
||||
|
||||
/**
|
||||
* Scroll lines within a region on the display
|
||||
*
|
||||
* This function behaves in the same way as `screen_scroll`, except that you
|
||||
* specify a rectangular region within which to scroll lines instead of a start
|
||||
* line.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x0, y0 The (x,y) coordinates of the first corner of the
|
||||
* rectangular region
|
||||
* \param x1, y1 The (x,y) coordinates of the second corner of the
|
||||
* rectangular region
|
||||
* \param lines The number of lines to scroll upwards
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::screen::print(TEXT_MEDIUM, 1, "Line Here");
|
||||
* // Scrolls area of screen upwards slightly. including line of text
|
||||
* pros::screen::scroll_area(0,0, 400, 200, 3);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t scroll_area(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1, std::int16_t lines);
|
||||
|
||||
/**
|
||||
* Copy a screen region (designated by a rectangle) from an off-screen buffer
|
||||
* to the screen
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x0, y0 The (x,y) coordinates of the first corner of the
|
||||
* rectangular region of the screen
|
||||
* \param x1, y1 The (x,y) coordinates of the second corner of the
|
||||
* rectangular region of the screen
|
||||
* \param buf Off-screen buffer containing screen data
|
||||
* \param stride Off-screen buffer width in pixels, such that image size
|
||||
* is stride-padding
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured taking
|
||||
* or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* uint32_t* buf = malloc(sizeof(uint32_t) * 400 * 200);
|
||||
* pros::screen::print(TEXT_MEDIUM, 1, "Line Here");
|
||||
* // Copies area of the screen including text
|
||||
* pros::screen::copy_area(0, 0, 400, 200, (uint32_t*)buf, 400 + 1);
|
||||
* // Equation for stride is x2 - x1 + 1
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t copy_area(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1, uint32_t* buf, const std::int32_t stride);
|
||||
|
||||
/**
|
||||
* Draw a single pixel on the screen using the current pen color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x, y The (x,y) coordinates of the pixel
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* int i = 0;
|
||||
* void opcontrol() {
|
||||
* while(i < 200){
|
||||
* pros::screen::draw_pixel(100,i++);
|
||||
* // Draws a line at x = 100 gradually down the screen, pixel by pixel
|
||||
* pros::delay(200);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t draw_pixel(const std::int16_t x, const std::int16_t y);
|
||||
|
||||
/**
|
||||
* Erase a pixel from the screen (Sets the location)
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x, y The (x,y) coordinates of the erased
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* // Color the Screen in Red
|
||||
* pros::screen::set_pen(red);
|
||||
* pros::screen::fill_rect(0,0,400,200);
|
||||
* int i = 0;
|
||||
* while(i < 200){
|
||||
* pros::screen::erase_pixel(100,i++);
|
||||
* // Erases a line at x = 100 gradually down the screen, pixel by pixel
|
||||
* pros::delay(200);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t erase_pixel(const std::int16_t x, const std::int16_t y);
|
||||
|
||||
/**
|
||||
* Draw a line on the screen using the current pen color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x0, y0 The (x, y) coordinates of the first point of the line
|
||||
* \param x1, y1 The (x, y) coordinates of the second point of the line
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::screen::set_pen(red);
|
||||
* // Draw line down the screen at x = 100
|
||||
* pros::screen::draw_line(100,0,100,200);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t draw_line(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1);
|
||||
|
||||
/**
|
||||
* Erase a line on the screen using the current eraser color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x0, y0 The (x, y) coordinates of the first point of the line
|
||||
* \param x1, y1 The (x, y) coordinates of the second point of the line
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* // Color the Screen in Red
|
||||
* pros::screen::set_pen(red);
|
||||
* pros::screen::fill_rect(0,0,400,200);
|
||||
* // Erase line down the screen at x = 100
|
||||
* pros::screen::erase_line(100,0,100,200);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t erase_line(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1);
|
||||
|
||||
/**
|
||||
* Draw a rectangle on the screen using the current pen color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x0, y0 The (x,y) coordinates of the first point of the rectangle
|
||||
* \param x1, y1 The (x,y) coordinates of the second point of the rectangle
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::screen::set_pen(red);
|
||||
* pros::screen::draw_rect(1,1,480,200);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t draw_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1);
|
||||
|
||||
/**
|
||||
* Erase a rectangle on the screen using the current eraser color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x0, y0 The (x,y) coordinates of the first point of the rectangle
|
||||
* \param x1, y1 The (x,y) coordinates of the second point of the rectangle
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* // Draw Box Around Half the Screen in Red
|
||||
* pros::screen::set_eraser(red);
|
||||
* pros::screen::erase_rect(5,5,240,200);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t erase_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1);
|
||||
|
||||
/**
|
||||
* Fill a rectangular region of the screen using the current pen
|
||||
* color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x0, y0 The (x,y) coordinates of the first point of the rectangle
|
||||
* \param x1, y1 The (x,y) coordinates of the second point of the rectangle
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* // Fill Around Half the Screen in Red
|
||||
* pros::screen::set_pen(red);
|
||||
* pros::screen::fill_rect(5,5,240,200);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t fill_rect(const std::int16_t x0, const std::int16_t y0, const std::int16_t x1, const std::int16_t y1);
|
||||
|
||||
/**
|
||||
* Draw a circle on the screen using the current pen color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x, y The (x,y) coordinates of the center of the circle
|
||||
* \param r The radius of the circle
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* // Draw a circle with radius of 100 in red
|
||||
* pros::screen::set_pen(red);
|
||||
* pros::screen::draw_circle(240, 200, 100);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t draw_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius);
|
||||
|
||||
/**
|
||||
* Erase a circle on the screen using the current eraser color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x, y The (x,y) coordinates of the center of the circle
|
||||
* \param r The radius of the circle
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::screen::set_pen(red);
|
||||
* pros::screen::fill_rect(5,5,240,200);
|
||||
* // Erase a circle with radius of 100 in blue
|
||||
* pros::screen::set_pen(blue);
|
||||
* pros::screen::erase_circle(240, 200, 100);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t erase_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius);
|
||||
|
||||
/**
|
||||
* Fill a circular region of the screen using the current pen
|
||||
* color
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param x, y The (x,y) coordinates of the center of the circle
|
||||
* \param r The radius of the circle
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::screen::set_pen(red);
|
||||
* pros::screen::fill_rect(5,5,240,200);
|
||||
* // Fill a circlular area with radius of 100 in blue
|
||||
* pros::screen::set_pen(blue);
|
||||
* pros::screen::fill_circle(240, 200, 100);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t fill_circle(const std::int16_t x, const std::int16_t y, const std::int16_t radius);
|
||||
|
||||
/******************************************************************************/
|
||||
/** Screen Text Display Functions **/
|
||||
/** **/
|
||||
/** These functions allow programmers to display text on the v5 screen **/
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* Print a formatted string to the screen, overwrite available for printing at location too.
|
||||
*
|
||||
* Will default to a medium sized font by default if invalid txt_fmt is given.
|
||||
*
|
||||
* \param txt_fmt Text format enum that determines if the text is medium, large, medium_center, or large_center. (DOES NOT SUPPORT SMALL)
|
||||
* \param line The line number on which to print
|
||||
* \param x The (x,y) coordinates of the top left corner of the string
|
||||
* \param y The (x,y) coordinates of the top left corner of the string
|
||||
* \param fmt Format string
|
||||
* \param ... Optional list of arguments for the format string
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* int i = 0;
|
||||
* pros::screen::set_pen(blue);
|
||||
* while(1){
|
||||
* // Will print seconds started since program started on line 3
|
||||
* pros::screen::print(pros::TEXT_MEDIUM, 3, "Seconds Passed: %3d", i++);
|
||||
* pros::delay(1000);
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
template <typename... Params>
|
||||
void print(pros::text_format_e_t txt_fmt, const std::int16_t line, const char* text, Params... args){
|
||||
pros::c::screen_print(txt_fmt, line, text, convert_args(args)...);
|
||||
}
|
||||
|
||||
template <typename... Params>
|
||||
void print(pros::text_format_e_t txt_fmt, const std::int16_t x, const std::int16_t y, const char* text, Params... args){
|
||||
pros::c::screen_print_at(txt_fmt, x, y, text, convert_args(args)...);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/** Screen Touch Functions **/
|
||||
/** **/
|
||||
/** These functions allow programmers to access **/
|
||||
/** information about screen touches **/
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* Gets the touch status of the last touch of the screen.
|
||||
*
|
||||
* \return The last_touch_e_t enum specifier that indicates the last touch status of the screen (E_TOUCH_EVENT_RELEASE, E_TOUCH_EVENT_PRESS, or E_TOUCH_EVENT_PRESS_AND_HOLD).
|
||||
* This will be released by default if no action was taken.
|
||||
* If an error occured, the screen_touch_status_s_t will have its
|
||||
* last_touch_e_t enum specifier set to E_TOUCH_ERR, and other values set to -1.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* int i = 0;
|
||||
* pros::screen_touch_status_s_t status;
|
||||
* while(1){
|
||||
* status = pros::touch_status();
|
||||
*
|
||||
* // Will print various information about the last touch
|
||||
* pros::screen::print(TEXT_MEDIUM, 1, "Touch Status (Type): %d", status.touch_status);
|
||||
* pros::screen::print(TEXT_MEDIUM, 2, "Last X: %d", status.x);
|
||||
* pros::screen::print(TEXT_MEDIUM, 3, "Last Y: %d", status.y);
|
||||
* pros::screen::print(TEXT_MEDIUM, 4, "Press Count: %d", status.press_count);
|
||||
* pros::screen::print(TEXT_MEDIUM, 5, "Release Count: %d", status.release_count);
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
screen_touch_status_s_t touch_status();
|
||||
|
||||
/**
|
||||
* Assigns a callback function to be called when a certain touch event happens.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EACCESS - Another resource is currently trying to access the screen mutex.
|
||||
*
|
||||
* \param cb Function pointer to callback when event type happens
|
||||
* \param event_type Touch event that will trigger the callback.
|
||||
*
|
||||
* \return 1 if there were no errors, or PROS_ERR if an error occured
|
||||
* while taking or returning the screen mutex.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* touch_event_cb_fn_t changePixel(){
|
||||
* pros::screen_touch_status_s_t status = pros::screen::touch_status();
|
||||
* pros::screen::draw_pixel(status.x,status.y);
|
||||
* return NULL;
|
||||
* }
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::screen::touch_callback(changePixel(), TOUCH_PRESSED);
|
||||
* while(1) {
|
||||
* pros::delay(20);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::uint32_t touch_callback(touch_event_cb_fn_t cb, last_touch_e_t event_type);
|
||||
|
||||
} // namespace screen
|
||||
|
||||
|
||||
} // namespace pros
|
||||
|
||||
extern __attribute__((weak)) void lvgl_init() {}
|
||||
///@}
|
||||
#endif //header guard
|
||||
@@ -0,0 +1,410 @@
|
||||
/**
|
||||
* \file pros/serial.h
|
||||
* \ingroup c-serial
|
||||
*
|
||||
* Contains prototypes for the V5 Generic Serial related functions.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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/.
|
||||
*
|
||||
* \defgroup c-serial Generic Serial C API
|
||||
*/
|
||||
|
||||
#ifndef _PROS_SERIAL_H_
|
||||
#define _PROS_SERIAL_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
namespace pros {
|
||||
namespace c {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \ingroup c-serial
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup c-serial
|
||||
* @{
|
||||
*/
|
||||
|
||||
/// \name Serial communication functions
|
||||
/// These functions allow programmers to communicate using UART over RS485
|
||||
///@{
|
||||
|
||||
/**
|
||||
* Enables generic serial on the given port.
|
||||
*
|
||||
* \note This function must be called before any of the generic serial
|
||||
* functions will work.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.c}
|
||||
* void opcontrol() {
|
||||
* serial_enable(1);
|
||||
* serial_set_baudrate(1, 9600);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t serial_enable(uint8_t port);
|
||||
|
||||
/**
|
||||
* Sets the baudrate for the serial port to operate at.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param baudrate
|
||||
* The baudrate to operate at
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.c}
|
||||
* void opcontrol() {
|
||||
* serial_enable(1);
|
||||
* serial_set_baudrate(1, 9600);
|
||||
* while (true) {
|
||||
* serial_write(1, "Hello World!", 12);
|
||||
* delay(100);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t serial_set_baudrate(uint8_t port, int32_t baudrate);
|
||||
|
||||
/**
|
||||
* Clears the internal input and output FIFO buffers.
|
||||
*
|
||||
* This can be useful to reset state and remove old, potentially unneeded data
|
||||
* from the input FIFO buffer or to cancel sending any data in the output FIFO
|
||||
* buffer.
|
||||
*
|
||||
* \note This function does not cause the data in the output buffer to be
|
||||
* written, it simply clears the internal buffers. Unlike stdout, generic
|
||||
* serial does not use buffered IO (the FIFO buffers are written as soon
|
||||
* as possible).
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.c}
|
||||
* void opcontrol() {
|
||||
* serial_enable(1);
|
||||
* serial_set_baudrate(1, 9600);
|
||||
* while (true) {
|
||||
* serial_flush(1);
|
||||
* serial_write(1, "Hello World!", 12);
|
||||
* delay(100);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t serial_flush(uint8_t port);
|
||||
|
||||
/**
|
||||
* Returns the number of bytes available to be read in the the port's FIFO
|
||||
* input buffer.
|
||||
*
|
||||
* \note This function does not actually read any bytes, is simply returns the
|
||||
* number of bytes available to be read.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
*
|
||||
* \return The number of bytes avaliable to be read or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.c}
|
||||
* void opcontrol() {
|
||||
* serial_enable(1);
|
||||
* serial_set_baudrate(1, 9600);
|
||||
* while (true) {
|
||||
* if (serial_get_read_avail(1) >= 12) {
|
||||
* char buffer[12];
|
||||
* serial_read(1, buffer, 12);
|
||||
* printf("%s", buffer);
|
||||
* }
|
||||
* delay(100);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
|
||||
*/
|
||||
int32_t serial_get_read_avail(uint8_t port);
|
||||
|
||||
/**
|
||||
* Returns the number of bytes free in the port's FIFO output buffer.
|
||||
*
|
||||
* \note This function does not actually write any bytes, is simply returns the
|
||||
* number of bytes free in the port's buffer.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
*
|
||||
* \return The number of bytes free or PROS_ERR if the operation failed,
|
||||
* setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.c}
|
||||
* void opcontrol() {
|
||||
* serial_enable(1);
|
||||
* serial_set_baudrate(1, 9600);
|
||||
* while (true) {
|
||||
* if (serial_get_write_free(1) >= 12) {
|
||||
* serial_write(1, "Hello World!", 12);
|
||||
* }
|
||||
* delay(100);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t serial_get_write_free(uint8_t port);
|
||||
|
||||
/**
|
||||
* Reads the next byte avaliable in the port's input buffer without removing it.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
*
|
||||
* \return The next byte avaliable to be read, -1 if none are available, or
|
||||
* PROS_ERR if the operation failed, setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.c}
|
||||
* void opcontrol() {
|
||||
* serial_enable(1);
|
||||
* serial_set_baudrate(1, 9600);
|
||||
* while (true) {
|
||||
* if (serial_peek_byte(1) == 'H') {
|
||||
* char buffer[12];
|
||||
* serial_read(1, buffer, 12);
|
||||
* printf("%s", buffer);
|
||||
* }
|
||||
* delay(100);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t serial_peek_byte(uint8_t port);
|
||||
|
||||
/**
|
||||
* Reads the next byte avaliable in the port's input buffer.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
*
|
||||
* \return The next byte avaliable to be read, -1 if none are available, or
|
||||
* PROS_ERR if the operation failed, setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.c}
|
||||
* void opcontrol() {
|
||||
* serial_enable(1);
|
||||
* serial_set_baudrate(1, 9600);
|
||||
* while (true) {
|
||||
* if (serial_read_byte(1) == 'H') {
|
||||
* char buffer[12];
|
||||
* serial_read(1, buffer, 12);
|
||||
* printf("%s", buffer);
|
||||
* }
|
||||
* delay(100);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t serial_read_byte(uint8_t port);
|
||||
|
||||
/**
|
||||
* Reads up to the next length bytes from the port's input buffer and places
|
||||
* them in the user supplied buffer.
|
||||
*
|
||||
* \note This function will only return bytes that are currently avaliable to be
|
||||
* read and will not block waiting for any to arrive.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param buffer
|
||||
* The location to place the data read
|
||||
* \param length
|
||||
* The maximum number of bytes to read
|
||||
*
|
||||
* \return The number of bytes read or PROS_ERR if the operation failed, setting
|
||||
* errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.c}
|
||||
* void opcontrol() {
|
||||
* serial_enable(1);
|
||||
* serial_set_baudrate(1, 9600);
|
||||
* while (true) {
|
||||
* if (serial_get_read_avail(1) >= 12) {
|
||||
* char buffer[12];
|
||||
* serial_read(1, buffer, 12);
|
||||
* printf("%s", buffer);
|
||||
* }
|
||||
* delay(100);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t serial_read(uint8_t port, uint8_t* buffer, int32_t length);
|
||||
|
||||
/**
|
||||
* Write the given byte to the port's output buffer.
|
||||
*
|
||||
* \note Data in the port's output buffer is written to the serial port as soon
|
||||
* as possible on a FIFO basis and can not be done manually by the user.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
* EIO - Serious internal write error.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param buffer
|
||||
* The byte to write
|
||||
*
|
||||
* \return The number of bytes written or PROS_ERR if the operation failed,
|
||||
* setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.c}
|
||||
* void opcontrol() {
|
||||
* serial_enable(1);
|
||||
* serial_set_baudrate(1, 9600);
|
||||
* while (true) {
|
||||
* if (serial_get_write_free(1) >= 12) {
|
||||
* serial_write_byte(1, 'H');
|
||||
* serial_write_byte(1, 'e');
|
||||
* serial_write_byte(1, 'l');
|
||||
* serial_write_byte(1, 'l');
|
||||
* serial_write_byte(1, 'o');
|
||||
* serial_write_byte(1, ' ');
|
||||
* serial_write_byte(1, 'W');
|
||||
* serial_write_byte(1, 'o');
|
||||
* serial_write_byte(1, 'r');
|
||||
* serial_write_byte(1, 'l');
|
||||
* serial_write_byte(1, 'd');
|
||||
* serial_write_byte(1, '!');
|
||||
* serial_write_byte(1, '\n');
|
||||
* }
|
||||
* delay(100);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t serial_write_byte(uint8_t port, uint8_t buffer);
|
||||
|
||||
/**
|
||||
* Writes up to length bytes from the user supplied buffer to the port's output
|
||||
* buffer.
|
||||
*
|
||||
* \note Data in the port's output buffer is written to the serial port as soon
|
||||
* as possible on a FIFO basis and can not be done manually by the user.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
* EIO - Serious internal write error.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param buffer
|
||||
* The data to write
|
||||
* \param length
|
||||
* The maximum number of bytes to write
|
||||
*
|
||||
* \return The number of bytes written or PROS_ERR if the operation failed,
|
||||
* setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code{.c}
|
||||
* void opcontrol() {
|
||||
* serial_enable(1);
|
||||
* serial_set_baudrate(1, 9600);
|
||||
* while (true) {
|
||||
* if (serial_get_write_free(1) >= 12) {
|
||||
* serial_write(1, "Hello World!\n", 12);
|
||||
* }
|
||||
* delay(100);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t serial_write(uint8_t port, uint8_t* buffer, int32_t length);
|
||||
|
||||
///@}
|
||||
|
||||
///@}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // namespace c
|
||||
} // namespace pros
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _PROS_SERIAL_H_
|
||||
@@ -0,0 +1,344 @@
|
||||
/**
|
||||
* \file pros/serial.hpp
|
||||
* \ingroup cpp-serial
|
||||
*
|
||||
* Contains prototypes for the V5 Generic Serial related functions.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, 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/.
|
||||
*
|
||||
* \defgroup cpp-serial Generic Serial C++ API
|
||||
*/
|
||||
|
||||
#ifndef _PROS_SERIAL_HPP_
|
||||
#define _PROS_SERIAL_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "pros/device.hpp"
|
||||
#include "pros/serial.h"
|
||||
|
||||
namespace pros {
|
||||
/**
|
||||
* \ingroup cpp-serial
|
||||
* @{
|
||||
*/
|
||||
class Serial : public Device {
|
||||
/**
|
||||
* \addtogroup cpp-serial
|
||||
* @{
|
||||
*/
|
||||
public:
|
||||
/**
|
||||
* Creates a Serial object for the given port and specifications.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param baudrate
|
||||
* The baudrate to run the port at
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* pros::Serial serial(1, 9600);
|
||||
* \endcode
|
||||
*/
|
||||
explicit Serial(std::uint8_t port, std::int32_t baudrate);
|
||||
|
||||
/**
|
||||
* Creates a Serial object for the given port without a set baudrate.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* pros::Serial serial(1);
|
||||
* \endcode
|
||||
*/
|
||||
explicit Serial(std::uint8_t port);
|
||||
|
||||
/******************************************************************************/
|
||||
/** Serial communication functions **/
|
||||
/** **/
|
||||
/** These functions allow programmers to communicate using UART over RS485 **/
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the baudrate for the serial port to operate at.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \param baudrate
|
||||
* The baudrate to operate at
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* pros::Serial serial(1);
|
||||
* serial.set_baudrate(9600);
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t set_baudrate(std::int32_t baudrate) const;
|
||||
|
||||
/**
|
||||
* Clears the internal input and output FIFO buffers.
|
||||
*
|
||||
* This can be useful to reset state and remove old, potentially unneeded data
|
||||
* from the input FIFO buffer or to cancel sending any data in the output FIFO
|
||||
* buffer.
|
||||
*
|
||||
* \note This function does not cause the data in the output buffer to be
|
||||
* written, it simply clears the internal buffers. Unlike stdout, generic
|
||||
* serial does not use buffered IO (the FIFO buffers are written as soon
|
||||
* as possible).
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* pros::Serial serial(1);
|
||||
* serial.flush();
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t flush() const;
|
||||
|
||||
/**
|
||||
* Returns the number of bytes available to be read in the the port's FIFO
|
||||
* input buffer.
|
||||
*
|
||||
* \note This function does not actually read any bytes, is simply returns the
|
||||
* number of bytes available to be read.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \return The number of bytes avaliable to be read or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Serial serial(1);
|
||||
* if(serial.get_read_avail() > 0) {
|
||||
* std::uint8_t byte = serial.read_byte();
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t get_read_avail() const;
|
||||
|
||||
/**
|
||||
* Returns the number of bytes free in the port's FIFO output buffer.
|
||||
*
|
||||
* \note This function does not actually write any bytes, is simply returns the
|
||||
* number of bytes free in the port's buffer.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \return The number of bytes free or PROS_ERR if the operation failed,
|
||||
* setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Serial serial(1);
|
||||
* if(serial.get_write_free() > 0) {
|
||||
* serial.write_byte(0x01);
|
||||
* pros::delay(10);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t get_write_free() const;
|
||||
|
||||
/**
|
||||
* Reads the next byte avaliable in the port's input buffer without removing it.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \return The next byte avaliable to be read, -1 if none are available, or
|
||||
* PROS_ERR if the operation failed, setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Serial serial(1);
|
||||
* if(serial.peek_byte() == 0x01) {
|
||||
* serial.read_byte();
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t peek_byte() const;
|
||||
|
||||
/**
|
||||
* Reads the next byte avaliable in the port's input buffer.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \return The next byte avaliable to be read, -1 if none are available, or
|
||||
* PROS_ERR if the operation failed, setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Serial serial(1);
|
||||
* if(serial.read_byte() == 0x01) {
|
||||
* // Do something
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t read_byte() const;
|
||||
|
||||
/**
|
||||
* Reads up to the next length bytes from the port's input buffer and places
|
||||
* them in the user supplied buffer.
|
||||
*
|
||||
* \note This function will only return bytes that are currently avaliable to be
|
||||
* read and will not block waiting for any to arrive.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
*
|
||||
* \param buffer
|
||||
* The location to place the data read
|
||||
* \param length
|
||||
* The maximum number of bytes to read
|
||||
*
|
||||
* \return The number of bytes read or PROS_ERR if the operation failed, setting
|
||||
* errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Serial serial(1);
|
||||
* std::uint8_t buffer[10];
|
||||
* serial.read(buffer, 10);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t read(std::uint8_t* buffer, std::int32_t length) const;
|
||||
|
||||
/**
|
||||
* Write the given byte to the port's output buffer.
|
||||
*
|
||||
* \note Data in the port's output buffer is written to the serial port as soon
|
||||
* as possible on a FIFO basis and can not be done manually by the user.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
* EIO - Serious internal write error.
|
||||
*
|
||||
* \param buffer
|
||||
* The byte to write
|
||||
*
|
||||
* \return The number of bytes written or PROS_ERR if the operation failed,
|
||||
* setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Serial serial(1);
|
||||
* serial.write_byte(0x01);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t write_byte(std::uint8_t buffer) const;
|
||||
|
||||
/**
|
||||
* Writes up to length bytes from the user supplied buffer to the port's output
|
||||
* buffer.
|
||||
*
|
||||
* \note Data in the port's output buffer is written to the serial port as soon
|
||||
* as possible on a FIFO basis and can not be done manually by the user.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - The given value is not within the range of V5 ports (1-21).
|
||||
* EACCES - Another resource is currently trying to access the port.
|
||||
* EIO - Serious internal write error.
|
||||
*
|
||||
* \param buffer
|
||||
* The data to write
|
||||
* \param length
|
||||
* The maximum number of bytes to write
|
||||
*
|
||||
* \return The number of bytes written or PROS_ERR if the operation failed,
|
||||
* setting errno.
|
||||
*
|
||||
* \b Example:
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Serial serial(1);
|
||||
* std::uint8_t buffer[10];
|
||||
* serial.write(buffer, 10);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
virtual std::int32_t write(std::uint8_t* buffer, std::int32_t length) const;
|
||||
|
||||
private:
|
||||
///@}
|
||||
};
|
||||
|
||||
namespace literals {
|
||||
/**
|
||||
* Constructs a Serial device from a litteral ending in _ser
|
||||
*
|
||||
* \return a pros::Serial for the corresponding port
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* using namespace pros::literals;
|
||||
* void opcontrol() {
|
||||
* pros::Serial serial = 2_ser; //Makes an Serial device object on port 2
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
const pros::Serial operator"" _ser(const unsigned long long int m);
|
||||
} // namespace literals
|
||||
} // namespace pros
|
||||
#endif // _PROS_SERIAL_HPP_
|
||||
@@ -0,0 +1,851 @@
|
||||
/**
|
||||
* \file pros/vision.h
|
||||
* \ingroup c-vision
|
||||
*
|
||||
* Contains prototypes for the VEX Vision Sensor-related functions.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, Purdue University ACM SIGBots.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
* \defgroup c-vision Vision Sensor C API
|
||||
* \note Additional example code for this module can be found in its [Tutorial.](@ref vision)
|
||||
*/
|
||||
|
||||
#ifndef _PROS_VISION_H_
|
||||
#define _PROS_VISION_H_
|
||||
|
||||
/**
|
||||
* \ingroup c-vision
|
||||
*/
|
||||
|
||||
/**
|
||||
* \addtogroup c-vision
|
||||
* @{
|
||||
*/
|
||||
|
||||
/// \name Macros
|
||||
///Parameters given by VEX
|
||||
///@{
|
||||
|
||||
#define VISION_OBJECT_ERR_SIG 255
|
||||
|
||||
/**
|
||||
* The width of the Vision Sensor’s field of view.
|
||||
*/
|
||||
#define VISION_FOV_WIDTH 316
|
||||
|
||||
/**
|
||||
* The height of the Vision Sensor’s field of view.
|
||||
*/
|
||||
#define VISION_FOV_HEIGHT 212
|
||||
|
||||
///@}
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
namespace pros {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \enum vision_object_type_e_t
|
||||
* This enumeration defines the different types of objects that can be detected by the Vision Sensor
|
||||
*/
|
||||
typedef enum vision_object_type {
|
||||
E_VISION_OBJECT_NORMAL = 0,
|
||||
E_VISION_OBJECT_COLOR_CODE = 1,
|
||||
E_VISION_OBJECT_LINE = 2
|
||||
} vision_object_type_e_t;
|
||||
|
||||
/**
|
||||
* \struct vision_signature_s_t
|
||||
* This structure contains the parameters used by the Vision Sensor to detect objects.
|
||||
*/
|
||||
typedef struct __attribute__((__packed__)) vision_signature {
|
||||
uint8_t id;
|
||||
uint8_t _pad[3];
|
||||
float range;
|
||||
int32_t u_min;
|
||||
int32_t u_max;
|
||||
int32_t u_mean;
|
||||
int32_t v_min;
|
||||
int32_t v_max;
|
||||
int32_t v_mean;
|
||||
uint32_t rgb;
|
||||
uint32_t type;
|
||||
} vision_signature_s_t;
|
||||
|
||||
/**
|
||||
* \typedef vision_color_code_t
|
||||
* Color codes are just signatures with multiple IDs and a different type.
|
||||
*/
|
||||
typedef uint16_t vision_color_code_t;
|
||||
|
||||
/**
|
||||
* \struct vision_object_s_t
|
||||
* This structure contains a descriptor of an object detected by the Vision Sensor
|
||||
*/
|
||||
typedef struct __attribute__((__packed__)) vision_object {
|
||||
/// Object signature
|
||||
uint16_t signature;
|
||||
/// Object type, e.g. normal, color code, or line detection
|
||||
vision_object_type_e_t type;
|
||||
/// Left boundary coordinate of the object
|
||||
int16_t left_coord;
|
||||
/// Top boundary coordinate of the object
|
||||
int16_t top_coord;
|
||||
/// Width of the object
|
||||
int16_t width;
|
||||
/// Height of the object
|
||||
int16_t height;
|
||||
/// Angle of a color code object in 0.1 degree units (e.g. 10 -> 1 degree, 155 -> 15.5 degrees)
|
||||
uint16_t angle;
|
||||
/// Coordinates of the middle of the object (computed from the values above)
|
||||
int16_t x_middle_coord;
|
||||
/// Coordinates of the middle of the object (computed from the values above)
|
||||
int16_t y_middle_coord;
|
||||
} vision_object_s_t;
|
||||
|
||||
/**
|
||||
* \enum vision_zero
|
||||
* This enumeration defines different zero points for returned vision objects.
|
||||
*/
|
||||
typedef enum vision_zero {
|
||||
/// (0,0) coordinate is the top left of the FOV
|
||||
E_VISION_ZERO_TOPLEFT = 0,
|
||||
/// (0,0) coordinate is the center of the FOV
|
||||
E_VISION_ZERO_CENTER = 1
|
||||
} vision_zero_e_t;
|
||||
|
||||
#ifdef PROS_USE_SIMPLE_NAMES
|
||||
#ifdef __cplusplus
|
||||
#define VISION_OBJECT_NORMAL pros::E_VISION_OBJECT_NORMAL
|
||||
#define VISION_OBJECT_COLOR_CODE pros::E_VISION_OBJECT_COLOR_CODE
|
||||
#define VISION_OBJECT_LINE pros::E_VISION_OBJECT_LINE
|
||||
#define VISION_ZERO_TOPLEFT pros::E_VISION_ZERO_TOPLEFT
|
||||
#define VISION_ZERO_CENTER pros::E_VISION_ZERO_CENTER
|
||||
#else
|
||||
#define VISION_OBJECT_NORMAL E_VISION_OBJECT_NORMAL
|
||||
#define VISION_OBJECT_COLOR_CODE E_VISION_OBJECT_COLOR_CODE
|
||||
#define VISION_OBJECT_LINE E_VISION_OBJECT_LINE
|
||||
#define VISION_ZERO_TOPLEFT E_VISION_ZERO_TOPLEFT
|
||||
#define VISION_ZERO_CENTER E_VISION_ZERO_CENTER
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace c {
|
||||
#endif
|
||||
|
||||
/// \name Functions
|
||||
///@{
|
||||
|
||||
/**
|
||||
* Clears the vision sensor LED color, reseting it back to its default behavior,
|
||||
* displaying the most prominent object signature color.
|
||||
*
|
||||
* 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 vision sensor
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* void initialize() {
|
||||
* vision_clear_led(VISION_PORT);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_clear_led(uint8_t port);
|
||||
|
||||
/**
|
||||
* Creates a signature from the vision sensor utility
|
||||
*
|
||||
* \param id
|
||||
* The signature ID
|
||||
* \param u_min
|
||||
* Minimum value on U axis
|
||||
* \param u_max
|
||||
* Maximum value on U axis
|
||||
* \param u_mean
|
||||
* Mean value on U axis
|
||||
* \param v_min
|
||||
* Minimum value on V axis
|
||||
* \param v_max
|
||||
* Maximum value on V axis
|
||||
* \param v_mean
|
||||
* Mean value on V axis
|
||||
* \param range
|
||||
* Scale factor
|
||||
* \param type
|
||||
* Signature type
|
||||
*
|
||||
* \return A vision_signature_s_t that can be set using vision_set_signature
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* // values acquired from the vision utility
|
||||
* vision_signature_s_t RED_SIG =
|
||||
* vision_signature_from_utility(EXAMPLE_SIG, 8973, 11143, 10058, -2119, -1053, -1586, 5.4, 0);
|
||||
* vision_set_signature(VISION_PORT, EXAMPLE_SIG, &RED_SIG);
|
||||
* while (true) {
|
||||
* vision_signature_s_t rtn = vision_get_by_sig(VISION_PORT, 0, EXAMPLE_SIG);
|
||||
* // Gets the largest object of the EXAMPLE_SIG signature
|
||||
* printf("sig: %d", rtn.signature);
|
||||
* // Prints "sig: 1"
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
vision_signature_s_t vision_signature_from_utility(const int32_t id, const int32_t u_min, const int32_t u_max,
|
||||
const int32_t u_mean, const int32_t v_min, const int32_t v_max,
|
||||
const int32_t v_mean, const float range, const int32_t type);
|
||||
|
||||
/**
|
||||
* Creates a color code that represents a combination of the given signature
|
||||
* IDs. If fewer than 5 signatures are to be a part of the color code, pass 0
|
||||
* for the additional function parameters.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - Fewer than two signatures have been provided or one of the
|
||||
* signatures is out of its [1-7] range (or 0 when omitted).
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param sig_id1
|
||||
* The first signature id [1-7] to add to the color code
|
||||
* \param sig_id2
|
||||
* The second signature id [1-7] to add to the color code
|
||||
* \param sig_id3
|
||||
* The third signature id [1-7] to add to the color code
|
||||
* \param sig_id4
|
||||
* The fourth signature id [1-7] to add to the color code
|
||||
* \param sig_id5
|
||||
* The fifth signature id [1-7] to add to the color code
|
||||
*
|
||||
* \return A vision_color_code_t object containing the color code information.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
* #define OTHER_SIG 2
|
||||
*
|
||||
* void opcontrol() {
|
||||
* vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
vision_color_code_t vision_create_color_code(uint8_t port, const uint32_t sig_id1, const uint32_t sig_id2,
|
||||
const uint32_t sig_id3, const uint32_t sig_id4, const uint32_t sig_id5);
|
||||
|
||||
/**
|
||||
* Gets the nth largest object according to size_id.
|
||||
*
|
||||
* 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 vision sensor
|
||||
* EDOM - size_id is greater than the number of available objects.
|
||||
* EHOSTDOWN - Reading the vision sensor failed for an unknown reason.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param size_id
|
||||
* The object to read from a list roughly ordered by object size
|
||||
* (0 is the largest item, 1 is the second largest, etc.)
|
||||
*
|
||||
* \return The vision_object_s_t object corresponding to the given size id, or
|
||||
* PROS_ERR if an error occurred.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* vision_object_s_t rtn = vision_get_by_size(VISION_PORT, 0);
|
||||
* // Gets the largest object
|
||||
* printf("sig: %d", rtn.signature);
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
vision_object_s_t vision_get_by_size(uint8_t port, const uint32_t size_id);
|
||||
|
||||
/**
|
||||
* Gets the nth largest object of the given signature according to size_id.
|
||||
*
|
||||
* 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 vision sensor
|
||||
* EINVAL - sig_id is outside the range [1-8]
|
||||
* EDOM - size_id is greater than the number of available objects.
|
||||
* EAGAIN - Reading the vision sensor failed for an unknown reason.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param size_id
|
||||
* The object to read from a list roughly ordered by object size
|
||||
* (0 is the largest item, 1 is the second largest, etc.)
|
||||
* \param signature
|
||||
* The signature ID [1-7] for which an object will be returned.
|
||||
*
|
||||
* \return The vision_object_s_t object corresponding to the given signature and
|
||||
* size_id, or PROS_ERR if an error occurred.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* vision_object_s_t rtn = vision_get_by_sig(VISION_PORT, 0, EXAMPLE_SIG);
|
||||
* // Gets the largest object of the EXAMPLE_SIG signature
|
||||
* printf("sig: %d", rtn.signature);
|
||||
* // Prints "sig: 1"
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
vision_object_s_t vision_get_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id);
|
||||
|
||||
/**
|
||||
* Gets the nth largest object of the given color code according to size_id.
|
||||
*
|
||||
* 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 vision sensor
|
||||
* EAGAIN - Reading the vision sensor failed for an unknown reason.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param size_id
|
||||
* The object to read from a list roughly ordered by object size
|
||||
* (0 is the largest item, 1 is the second largest, etc.)
|
||||
* \param color_code
|
||||
* The vision_color_code_t for which an object will be returned
|
||||
*
|
||||
* \return The vision_object_s_t object corresponding to the given color code
|
||||
* and size_id, or PROS_ERR if an error occurred.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
* #define OTHER_SIG 2
|
||||
*
|
||||
* void opcontrol() {
|
||||
* vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG);
|
||||
* while (true) {
|
||||
* vision_object_s_t rtn = vision_get_by_code(VISION_PORT, 0, code1);
|
||||
* // Gets the largest object
|
||||
* printf("sig: %d", rtn.signature);
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
vision_object_s_t vision_get_by_code(uint8_t port, const uint32_t size_id, const vision_color_code_t color_code);
|
||||
|
||||
/**
|
||||
* Gets the exposure parameter of the Vision 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 a vision sensor
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
*
|
||||
* \return The current exposure setting from [0,150], PROS_ERR if an error
|
||||
* occurred
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* if (vision_get_exposure(VISION_PORT) < 50)
|
||||
* vision_set_exposure(VISION_PORT, 50);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_get_exposure(uint8_t port);
|
||||
|
||||
/**
|
||||
* Gets the number of objects currently detected by the Vision 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 a vision sensor
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
*
|
||||
* \return The number of objects detected on the specified vision sensor.
|
||||
* Returns PROS_ERR if the port was invalid or an error occurred.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* while (true) {
|
||||
* printf("Number of Objects Detected: %d\n", vision_get_object_count(VISION_PORT));
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_get_object_count(uint8_t port);
|
||||
|
||||
/**
|
||||
* Get the white balance parameter of the Vision 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 a vision sensor
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
*
|
||||
* \return The current RGB white balance setting of the sensor
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define VISION_WHITE 0xff
|
||||
*
|
||||
* void initialize() {
|
||||
* if (vision_get_white_balance(VISION_PORT) != VISION_WHITE)
|
||||
* vision_set_white_balance(VISION_PORT, VISION_WHITE);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_get_white_balance(uint8_t port);
|
||||
|
||||
/**
|
||||
* Prints the contents of the signature as an initializer list to the terminal.
|
||||
*
|
||||
* \param sig
|
||||
* The signature for which the contents will be printed
|
||||
*
|
||||
* \return 1 if no errors occured, PROS_ERR otherwise
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG);
|
||||
* vision_print_signature(sig);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_print_signature(const vision_signature_s_t sig);
|
||||
|
||||
/**
|
||||
* Reads up to object_count object descriptors into object_arr.
|
||||
*
|
||||
* 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), or
|
||||
* fewer than object_count number of objects were found.
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
* EDOM - size_id is greater than the number of available objects.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param size_id
|
||||
* The object to read from a list roughly ordered by object size
|
||||
* (0 is the largest item, 1 is the second largest, etc.)
|
||||
* \param object_count
|
||||
* The number of objects to read
|
||||
* \param[out] object_arr
|
||||
* A pointer to copy the objects into
|
||||
*
|
||||
* \return The number of object signatures copied. This number will be less than
|
||||
* object_count if there are fewer objects detected by the vision sensor.
|
||||
* Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects
|
||||
* than size_id were found. All objects in object_arr that were not found are
|
||||
* given VISION_OBJECT_ERR_SIG as their signature.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define NUM_VISION_OBJECTS 4
|
||||
*
|
||||
* void opcontrol() {
|
||||
* vision_object_s_t object_arr[NUM_VISION_OBJECTS];
|
||||
* while (true) {
|
||||
* vision_read_by_size(VISION_PORT, 0, NUM_VISION_OBJECTS, object_arr);
|
||||
* printf("sig: %d", object_arr[0].signature);
|
||||
* // Prints the signature of the largest object found
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_read_by_size(uint8_t port, const uint32_t size_id, const uint32_t object_count,
|
||||
vision_object_s_t* const object_arr);
|
||||
|
||||
/**
|
||||
* Reads up to object_count object descriptors into object_arr.
|
||||
*
|
||||
* 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), or
|
||||
* fewer than object_count number of objects were found.
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
* EDOM - size_id is greater than the number of available objects.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param object_count
|
||||
* The number of objects to read
|
||||
* \param size_id
|
||||
* The object to read from a list roughly ordered by object size
|
||||
* (0 is the largest item, 1 is the second largest, etc.)
|
||||
* \param signature
|
||||
* The signature ID [1-7] for which objects will be returned.
|
||||
* \param[out] object_arr
|
||||
* A pointer to copy the objects into
|
||||
*
|
||||
* \return The number of object signatures copied. This number will be less than
|
||||
* object_count if there are fewer objects detected by the vision sensor.
|
||||
* Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects
|
||||
* than size_id were found. All objects in object_arr that were not found are
|
||||
* given VISION_OBJECT_ERR_SIG as their signature.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
* #define NUM_VISION_OBJECTS 4
|
||||
*
|
||||
* void opcontrol() {
|
||||
* vision_object_s_t object_arr[NUM_VISION_OBJECTS];
|
||||
* while (true) {
|
||||
* vision_read_by_sig(VISION_PORT, 0, EXAMPLE_SIG, NUM_VISION_OBJECTS, object_arr);
|
||||
* printf("sig: %d", object_arr[0].signature);
|
||||
* // Prints "sig: 1"
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_read_by_sig(uint8_t port, const uint32_t size_id, const uint32_t sig_id, const uint32_t object_count,
|
||||
vision_object_s_t* const object_arr);
|
||||
|
||||
/**
|
||||
* Reads up to object_count object descriptors into object_arr.
|
||||
*
|
||||
* 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), or
|
||||
* fewer than object_count number of objects were found.
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param object_count
|
||||
* The number of objects to read
|
||||
* \param size_id
|
||||
* The object to read from a list roughly ordered by object size
|
||||
* (0 is the largest item, 1 is the second largest, etc.)
|
||||
* \param color_code
|
||||
* The vision_color_code_t for which objects will be returned
|
||||
* \param[out] object_arr
|
||||
* A pointer to copy the objects into
|
||||
*
|
||||
* \return The number of object signatures copied. This number will be less than
|
||||
* object_count if there are fewer objects detected by the vision sensor.
|
||||
* Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects
|
||||
* than size_id were found. All objects in object_arr that were not found are
|
||||
* given VISION_OBJECT_ERR_SIG as their signature.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
* #define OTHER_SIG 2
|
||||
* #define NUM_VISION_OBJECTS 4
|
||||
*
|
||||
* void opcontrol() {
|
||||
* vision_object_s_t object_arr[NUM_VISION_OBJECTS];
|
||||
* vision_color_code_t code1 = vision_create_color_code(VISION_PORT, EXAMPLE_SIG, OTHER_SIG, 0, 0, 0);
|
||||
* while (true) {
|
||||
* vision_read_by_code(VISION_PORT, 0, code1, NUM_VISION_OBJECTS, object_arr);
|
||||
* printf("sig: %d", object_arr[0].signature);
|
||||
* // Prints the signature of the largest object found
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_read_by_code(uint8_t port, const uint32_t size_id, const vision_color_code_t color_code,
|
||||
const uint32_t object_count, vision_object_s_t* const object_arr);
|
||||
|
||||
/**
|
||||
* Gets the object detection signature with the given id number.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param signature_id
|
||||
* The signature id to read
|
||||
*
|
||||
* \return A vision_signature_s_t containing information about the signature.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG);
|
||||
* vision_print_signature(sig);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
vision_signature_s_t vision_get_signature(uint8_t port, const uint8_t signature_id);
|
||||
|
||||
/**
|
||||
* Stores the supplied object detection signature onto the vision sensor.
|
||||
*
|
||||
* \note This saves the signature in volatile memory, and the signature will be
|
||||
* lost as soon as the sensor is powered down.
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param signature_id
|
||||
* The signature id to store into
|
||||
* \param[in] signature_ptr
|
||||
* A pointer to the signature to save
|
||||
*
|
||||
* \return 1 if no errors occured, PROS_ERR otherwise
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* vision_signature_s_t sig = vision_get_signature(VISION_PORT, EXAMPLE_SIG);
|
||||
* sig.range = 10.0;
|
||||
* vision_set_signature(VISION_PORT, EXAMPLE_SIG, &sig);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_set_signature(uint8_t port, const uint8_t signature_id, vision_signature_s_t* const signature_ptr);
|
||||
|
||||
/**
|
||||
* Enables/disables auto white-balancing on the Vision 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 a vision sensor
|
||||
* EINVAL - enable was not 0 or 1
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param enabled
|
||||
* Pass 0 to disable, 1 to enable
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* vision_set_auto_white_balance(VISION_PORT, true);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_set_auto_white_balance(uint8_t port, const uint8_t enable);
|
||||
|
||||
/**
|
||||
* Sets the exposure parameter of the Vision 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 a vision sensor
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param percent
|
||||
* The new exposure setting from [0,150]
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* if (vision_get_exposure(VISION_PORT) < 50)
|
||||
* vision_set_exposure(VISION_PORT, 50);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_set_exposure(uint8_t port, const uint8_t exposure);
|
||||
|
||||
/**
|
||||
* Sets the vision sensor LED color, overriding the automatic behavior.
|
||||
*
|
||||
* 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 vision sensor
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param rgb
|
||||
* An RGB code to set the LED to
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* vision_set_led(VISION_PORT, COLOR_BLANCHED_ALMOND);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_set_led(uint8_t port, const int32_t rgb);
|
||||
|
||||
/**
|
||||
* Sets the white balance parameter of the Vision 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 a vision sensor
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param rgb
|
||||
* The new RGB white balance setting of the sensor
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define VISION_WHITE 0xff
|
||||
*
|
||||
* void initialize() {
|
||||
* vision_set_white_balance(VISION_PORT, VISION_WHITE);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_set_white_balance(uint8_t port, const int32_t rgb);
|
||||
|
||||
/**
|
||||
* Sets the (0,0) coordinate for the Field of View.
|
||||
*
|
||||
* This will affect the coordinates returned for each request for a
|
||||
* vision_object_s_t from the sensor, so it is recommended that this function
|
||||
* only be used to configure the sensor at the beginning of its use.
|
||||
*
|
||||
* 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 vision sensor
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param zero_point
|
||||
* One of vision_zero_e_t to set the (0,0) coordinate for the FOV
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* vision_set_zero_point(VISION_PORT, E_VISION_ZERO_CENTER);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_set_zero_point(uint8_t port, vision_zero_e_t zero_point);
|
||||
|
||||
/**
|
||||
* Sets the Wi-Fi mode of the Vision sensor
|
||||
*
|
||||
* This functions uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENXIO - The given port is not within the range of V5 ports (1-21)
|
||||
* EACCESS - Anothe resources is currently trying to access the port
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param enable
|
||||
* Disable Wi-Fi on the Vision sensor if 0, enable otherwise (e.g. 1)
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* vision_set_wifi_mode(VISION_PORT, 0);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t vision_set_wifi_mode(uint8_t port, const uint8_t enable);
|
||||
|
||||
///@}
|
||||
|
||||
///@}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // namespace c
|
||||
} // namespace pros
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _PROS_VISION_H_
|
||||
@@ -0,0 +1,787 @@
|
||||
/**
|
||||
* \file pros/vision.hpp
|
||||
* \ingroup cpp-vision
|
||||
*
|
||||
* Contains prototypes for the VEX Vision Sensor-related functions in C++.
|
||||
*
|
||||
* This file should not be modified by users, since it gets replaced whenever
|
||||
* a kernel upgrade occurs.
|
||||
*
|
||||
* \copyright (c) 2017-2023, Purdue University ACM SIGBots.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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/.
|
||||
*
|
||||
* \defgroup cpp-vision Vision Sensor C++ API
|
||||
* \note Additional example code for this module can be found in its [Tutorial.](@ref vision)
|
||||
*/
|
||||
|
||||
#ifndef _PROS_VISION_HPP_
|
||||
#define _PROS_VISION_HPP_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "pros/device.hpp"
|
||||
#include "pros/vision.h"
|
||||
|
||||
namespace pros {
|
||||
inline namespace v5 {
|
||||
/**
|
||||
* \ingroup cpp-vision
|
||||
*/
|
||||
class Vision : public Device {
|
||||
/**
|
||||
* \addtogroup cpp-vision
|
||||
* @{
|
||||
*/
|
||||
public:
|
||||
/**
|
||||
* Create a Vision Sensor object on 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 vision sensor
|
||||
*
|
||||
* \param port
|
||||
* The V5 port number from 1-21
|
||||
* \param zero_point
|
||||
* One of vision_zero_e_t to set the (0,0) coordinate for the FOV
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* pros::Vision vision_sensor(1); // Creates a vision sensor on port one, with the zero point set to top left
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
Vision(std::uint8_t port, vision_zero_e_t zero_point = E_VISION_ZERO_TOPLEFT);
|
||||
|
||||
Vision(const Device& device) : Vision(device.get_port()){};
|
||||
|
||||
/**
|
||||
* Clears the vision sensor LED color, reseting it back to its default
|
||||
* behavior, displaying the most prominent object signature color.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void initialize() {
|
||||
* pros::Vision vision_sensor(1);
|
||||
* vision_sensor.clear_led();
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t clear_led(void) const;
|
||||
|
||||
/**
|
||||
* Creates a signature from the vision sensor utility
|
||||
*
|
||||
* \param id
|
||||
* The signature ID
|
||||
* \param u_min
|
||||
* Minimum value on U axis
|
||||
* \param u_max
|
||||
* Maximum value on U axis
|
||||
* \param u_mean
|
||||
* Mean value on U axis
|
||||
* \param v_min
|
||||
* Minimum value on V axis
|
||||
* \param v_max
|
||||
* Maximum value on V axis
|
||||
* \param v_mean
|
||||
* Mean value on V axis
|
||||
* \param rgb
|
||||
* Scale factor
|
||||
* \param type
|
||||
* Signature type
|
||||
*
|
||||
* \return A vision_signature_s_t that can be set using Vision::set_signature
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* // values acquired from the vision utility
|
||||
* vision_signature_s_t RED_SIG =
|
||||
* vision_signature_from_utility(EXAMPLE_SIG, 8973, 11143, 10058, -2119, -1053, -1586, 5.4, 0);
|
||||
* vision_sensor.set_signature(EXAMPLE_SIG, &RED_SIG);
|
||||
* while (true) {
|
||||
* vision_signature_s_t rtn = vision_sensor.get_by_sig(VISION_PORT, 0, EXAMPLE_SIG);
|
||||
* // Gets the largest object of the EXAMPLE_SIG signature
|
||||
* printf("sig: %d", rtn.signature);
|
||||
* // Prints "sig: 1"
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
static vision_signature_s_t signature_from_utility(const std::int32_t id, const std::int32_t u_min,
|
||||
const std::int32_t u_max, const std::int32_t u_mean,
|
||||
const std::int32_t v_min, const std::int32_t v_max,
|
||||
const std::int32_t v_mean, const float range,
|
||||
const std::int32_t type);
|
||||
|
||||
/**
|
||||
* Creates a color code that represents a combination of the given signature
|
||||
* IDs.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EINVAL - Fewer than two signatures have been provided or one of the
|
||||
* signatures is out of its [1-7] range (or 0 when omitted).
|
||||
*
|
||||
* \param sig_id1
|
||||
* The first signature id [1-7] to add to the color code
|
||||
* \param sig_id2
|
||||
* The second signature id [1-7] to add to the color code
|
||||
* \param sig_id3
|
||||
* The third signature id [1-7] to add to the color code
|
||||
* \param sig_id4
|
||||
* The fourth signature id [1-7] to add to the color code
|
||||
* \param sig_id5
|
||||
* The fifth signature id [1-7] to add to the color code
|
||||
*
|
||||
* \return A vision_color_code_t object containing the color code information.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
* #define OTHER_SIG 2
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* vision_color_code_t code1 = vision_sensor.create_color_code(EXAMPLE_SIG, OTHER_SIG);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
vision_color_code_t create_color_code(const std::uint32_t sig_id1, const std::uint32_t sig_id2,
|
||||
const std::uint32_t sig_id3 = 0, const std::uint32_t sig_id4 = 0,
|
||||
const std::uint32_t sig_id5 = 0) const;
|
||||
|
||||
/**
|
||||
* Gets all vision sensors.
|
||||
*
|
||||
* \return A vector of Vision sensor objects.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* void opcontrol() {
|
||||
* std::vector<Vision> vision_all = pros::Vision::get_all_devices(); // All vision sensors that are connected
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
static std::vector<Vision> get_all_devices();
|
||||
|
||||
/**
|
||||
* Gets the nth largest object according to size_id.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
* EDOM - size_id is greater than the number of available objects.
|
||||
* EAGAIN - Reading the vision sensor failed for an unknown reason.
|
||||
*
|
||||
* \param size_id
|
||||
* The object to read from a list roughly ordered by object size
|
||||
* (0 is the largest item, 1 is the second largest, etc.)
|
||||
*
|
||||
* \return The vision_object_s_t object corresponding to the given size id, or
|
||||
* PROS_ERR if an error occurred.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* while (true) {
|
||||
* vision_object_s_t rtn = vision_sensor.get_by_size(0);
|
||||
* // Gets the largest object
|
||||
* printf("sig: %d", rtn.signature);
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
vision_object_s_t get_by_size(const std::uint32_t size_id) const;
|
||||
|
||||
/**
|
||||
* Gets the nth largest object of the given signature according to size_id.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
* EDOM - size_id is greater than the number of available objects.
|
||||
* EINVAL - sig_id is outside the range [1-8]
|
||||
* EAGAIN - Reading the vision sensor failed for an unknown reason.
|
||||
*
|
||||
* \param size_id
|
||||
* The object to read from a list roughly ordered by object size
|
||||
* (0 is the largest item, 1 is the second largest, etc.)
|
||||
* \param signature
|
||||
* The vision_signature_s_t signature for which an object will be
|
||||
* returned.
|
||||
*
|
||||
* \return The vision_object_s_t object corresponding to the given signature
|
||||
* and size_id, or PROS_ERR if an error occurred.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* while (true) {
|
||||
* vision_object_s_t rtn = vision_sensor.get_by_sig(0, EXAMPLE_SIG);
|
||||
* // Gets the largest object of the EXAMPLE_SIG signature
|
||||
* printf("sig: %d", rtn.signature);
|
||||
* // Prints "sig: 1"
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
vision_object_s_t get_by_sig(const std::uint32_t size_id, const std::uint32_t sig_id) const;
|
||||
|
||||
/**
|
||||
* Gets the nth largest object of the given color code according to size_id.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
* EAGAIN - Reading the Vision Sensor failed for an unknown reason.
|
||||
*
|
||||
* \param size_id
|
||||
* The object to read from a list roughly ordered by object size
|
||||
* (0 is the largest item, 1 is the second largest, etc.)
|
||||
* \param color_code
|
||||
* The vision_color_code_t for which an object will be returned
|
||||
*
|
||||
* \return The vision_object_s_t object corresponding to the given color code
|
||||
* and size_id, or PROS_ERR if an error occurred.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
* #define OTHER_SIG 2
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* vision_color_code_t code1 = vision_sensor.create_color_code(EXAMPLE_SIG, OTHER_SIG);
|
||||
* while (true) {
|
||||
* vision_object_s_t rtn = vision_sensor.get_by_code(0, code1);
|
||||
* // Gets the largest object
|
||||
* printf("sig: %d", rtn.signature);
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
vision_object_s_t get_by_code(const std::uint32_t size_id, const vision_color_code_t color_code) const;
|
||||
|
||||
/**
|
||||
* Gets the exposure parameter of the Vision Sensor.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
*
|
||||
* \return The current exposure parameter from [0,150],
|
||||
* PROS_ERR if an error occurred
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* if (vision_sensor.get_exposure() < 50)
|
||||
* vision_sensor.set_exposure(50);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t get_exposure(void) const;
|
||||
|
||||
/**
|
||||
* Gets the number of objects currently detected by the Vision Sensor.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
*
|
||||
* \return The number of objects detected on the specified vision sensor.
|
||||
* Returns PROS_ERR if the port was invalid or an error occurred.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* while (true) {
|
||||
* printf("Number of Objects Detected: %d\n", vision_sensor.get_object_count());
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t get_object_count(void) const;
|
||||
|
||||
/**
|
||||
* Gets the object detection signature with the given id number.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
*
|
||||
* \param signature_id
|
||||
* The signature id to read
|
||||
*
|
||||
* \return A vision_signature_s_t containing information about the signature.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* vision_signature_s_t sig = vision_sensor.get_signature(EXAMPLE_SIG);
|
||||
* vision_sensor.print_signature(sig);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
vision_signature_s_t get_signature(const std::uint8_t signature_id) const;
|
||||
|
||||
/**
|
||||
* Get the white balance parameter of the Vision Sensor.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
*
|
||||
* \return The current RGB white balance setting of the sensor
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define VISION_WHITE 0xff
|
||||
*
|
||||
* void initialize() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* if (vision_sensor.get_white_balance() != VISION_WHITE)
|
||||
* vision_sensor.set_white_balance(VISION_WHITE);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t get_white_balance(void) const;
|
||||
|
||||
/**
|
||||
* Reads up to object_count object descriptors into object_arr.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
* EDOM - size_id is greater than the number of available objects.
|
||||
* EAGAIN - Reading the vision sensor failed for an unknown reason.
|
||||
*
|
||||
* \param size_id
|
||||
* The object to read from a list roughly ordered by object size
|
||||
* (0 is the largest item, 1 is the second largest, etc.)
|
||||
* \param object_count
|
||||
* The number of objects to read
|
||||
* \param[out] object_arr
|
||||
* A pointer to copy the objects into
|
||||
*
|
||||
* \return The number of object signatures copied. This number will be less than
|
||||
* object_count if there are fewer objects detected by the vision sensor.
|
||||
* Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects
|
||||
* than size_id were found. All objects in object_arr that were not found are
|
||||
* given VISION_OBJECT_ERR_SIG as their signature.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define NUM_VISION_OBJECTS 4
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* vision_object_s_t object_arr[NUM_VISION_OBJECTS];
|
||||
* while (true) {
|
||||
* vision_sensor.read_by_size(0, NUM_VISION_OBJECTS, object_arr);
|
||||
* printf("sig: %d", object_arr[0].signature);
|
||||
* // Prints the signature of the largest object found
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t read_by_size(const std::uint32_t size_id, const std::uint32_t object_count,
|
||||
vision_object_s_t* const object_arr) const;
|
||||
|
||||
/**
|
||||
* Reads up to object_count object descriptors into object_arr.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
* EDOM - size_id is greater than the number of available objects.
|
||||
* EINVAL - sig_id is outside the range [1-8]
|
||||
* EAGAIN - Reading the vision sensor failed for an unknown reason.
|
||||
*
|
||||
* \param object_count
|
||||
* The number of objects to read
|
||||
* \param size_id
|
||||
* The object to read from a list roughly ordered by object size
|
||||
* (0 is the largest item, 1 is the second largest, etc.)
|
||||
* \param signature
|
||||
* The vision_signature_s_t signature for which an object will be
|
||||
* returned.
|
||||
* \param[out] object_arr
|
||||
* A pointer to copy the objects into
|
||||
*
|
||||
* \return The number of object signatures copied. This number will be less than
|
||||
* object_count if there are fewer objects detected by the vision sensor.
|
||||
* Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects
|
||||
* than size_id were found. All objects in object_arr that were not found are
|
||||
* given VISION_OBJECT_ERR_SIG as their signature.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
* #define NUM_VISION_OBJECTS 4
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* vision_object_s_t object_arr[NUM_VISION_OBJECTS];
|
||||
* while (true) {
|
||||
* vision_sensor.read_by_sig(0, EXAMPLE_SIG, NUM_VISION_OBJECTS, object_arr);
|
||||
* printf("sig: %d", object_arr[0].signature);
|
||||
* // Prints "sig: 1"
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t read_by_sig(const std::uint32_t size_id, const std::uint32_t sig_id, const std::uint32_t object_count,
|
||||
vision_object_s_t* const object_arr) const;
|
||||
|
||||
/**
|
||||
* Reads up to object_count object descriptors into object_arr.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* EDOM - size_id is greater than the number of available objects.
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
* EAGAIN - Reading the vision sensor failed for an unknown reason.
|
||||
*
|
||||
* \param object_count
|
||||
* The number of objects to read
|
||||
* \param size_id
|
||||
* The object to read from a list roughly ordered by object size
|
||||
* (0 is the largest item, 1 is the second largest, etc.)
|
||||
* \param color_code
|
||||
* The vision_color_code_t for which objects will be returned
|
||||
* \param[out] object_arr
|
||||
* A pointer to copy the objects into
|
||||
*
|
||||
* \return The number of object signatures copied. This number will be less than
|
||||
* object_count if there are fewer objects detected by the vision sensor.
|
||||
* Returns PROS_ERR if the port was invalid, an error occurred, or fewer objects
|
||||
* than size_id were found. All objects in object_arr that were not found are
|
||||
* given VISION_OBJECT_ERR_SIG as their signature.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
* #define OTHER_SIG 2
|
||||
* #define NUM_VISION_OBJECTS 4
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* vision_object_s_t object_arr[NUM_VISION_OBJECTS];
|
||||
* vision_color_code_t code1 = vision_sensor.create_color_code(EXAMPLE_SIG, OTHER_SIG, 0, 0, 0);
|
||||
* while (true) {
|
||||
* vision_sensor.read_by_code(0, code1, NUM_VISION_OBJECTS, object_arr);
|
||||
* printf("sig: %d", object_arr[0].signature);
|
||||
* // Prints the signature of the largest object found
|
||||
* delay(2);
|
||||
* }
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
int32_t read_by_code(const std::uint32_t size_id, const vision_color_code_t color_code,
|
||||
const std::uint32_t object_count, vision_object_s_t* const object_arr) const;
|
||||
|
||||
/**
|
||||
* Prints the contents of the signature as an initializer list to the terminal.
|
||||
*
|
||||
* \param sig
|
||||
* The signature for which the contents will be printed
|
||||
*
|
||||
* \return 1 if no errors occured, PROS_ERR otherwise
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* vision_signature_s_t sig = visionsensor.get_signature(EXAMPLE_SIG);
|
||||
* vision_print_signature(sig);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
static std::int32_t print_signature(const vision_signature_s_t sig);
|
||||
|
||||
/**
|
||||
* Enables/disables auto white-balancing on the Vision Sensor.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
*
|
||||
* \param enabled
|
||||
* Pass 0 to disable, 1 to enable
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* vision_sensor.set_auto_white_balance(true);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t set_auto_white_balance(const std::uint8_t enable) const;
|
||||
|
||||
/**
|
||||
* Sets the exposure parameter of the Vision Sensor.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
*
|
||||
* \param percent
|
||||
* The new exposure setting from [0,150].
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* if (vision_sensor.get_exposure() < 50)
|
||||
* vision_sensor.set_exposure(50);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t set_exposure(const std::uint8_t exposure) const;
|
||||
|
||||
/**
|
||||
* Sets the vision sensor LED color, overriding the automatic behavior.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
*
|
||||
* \param rgb
|
||||
* An RGB code to set the LED to
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* vision_sensor.set_led(COLOR_BLANCHED_ALMOND);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t set_led(const std::int32_t rgb) const;
|
||||
|
||||
/**
|
||||
* Stores the supplied object detection signature onto the vision sensor.
|
||||
*
|
||||
* NOTE: This saves the signature in volatile memory, and the signature will be
|
||||
* lost as soon as the sensor is powered down.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
* EINVAL - sig_id is outside the range [1-8]
|
||||
*
|
||||
* \param signature_id
|
||||
* The signature id to store into
|
||||
* \param[in] signature_ptr
|
||||
* A pointer to the signature to save
|
||||
*
|
||||
* \return 1 if no errors occured, PROS_ERR otherwise
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define EXAMPLE_SIG 1
|
||||
*
|
||||
* void opcontrol() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* vision_signature_s_t sig = vision_sensor.get_signature(EXAMPLE_SIG);
|
||||
* sig.range = 10.0;
|
||||
* vision_sensor.set_signature(EXAMPLE_SIG, &sig);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t set_signature(const std::uint8_t signature_id, vision_signature_s_t* const signature_ptr) const;
|
||||
|
||||
/**
|
||||
* Sets the white balance parameter of the Vision Sensor.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
*
|
||||
* \param rgb
|
||||
* The new RGB white balance setting of the sensor
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
* #define VISION_WHITE 0xff
|
||||
*
|
||||
* void initialize() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* vision_sensor.set_white_balance(VISION_WHITE);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t set_white_balance(const std::int32_t rgb) const;
|
||||
|
||||
/**
|
||||
* Sets the (0,0) coordinate for the Field of View.
|
||||
*
|
||||
* This will affect the coordinates returned for each request for a
|
||||
* vision_object_s_t from the sensor, so it is recommended that this function
|
||||
* only be used to configure the sensor at the beginning of its use.
|
||||
*
|
||||
* This function uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
*
|
||||
* \param zero_point
|
||||
* One of vision_zero_e_t to set the (0,0) coordinate for the FOV
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* vision_sensor.set_zero_point(E_VISION_ZERO_CENTER);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t set_zero_point(vision_zero_e_t zero_point) const;
|
||||
|
||||
/**
|
||||
* Sets the Wi-Fi mode of the Vision sensor
|
||||
*
|
||||
* This functions uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - The port cannot be configured as a vision sensor
|
||||
*
|
||||
* \param enable
|
||||
* Disable Wi-Fi on the Vision sensor if 0, enable otherwise (e.g. 1)
|
||||
*
|
||||
* \return 1 if the operation was successful or PROS_ERR if the operation
|
||||
* failed, setting errno.
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* #define VISION_PORT 1
|
||||
*
|
||||
* void initialize() {
|
||||
* pros::Vision vision_sensor(VISION_PORT);
|
||||
* vision_sensor.set_wifi_mode(0);
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
std::int32_t set_wifi_mode(const std::uint8_t enable) const;
|
||||
|
||||
/**
|
||||
* Gets a vision sensor that is plugged in to the brain
|
||||
*
|
||||
* \note The first time this function is called it returns the vision sensor at the lowest port
|
||||
* If this function is called multiple times, it will cycle through all the ports.
|
||||
* For example, if you have 1 vision sensor on the robot
|
||||
* this function will always return a vision sensor object for that port.
|
||||
* If you have 2 vision sensors, all the odd numered calls to this function will return objects
|
||||
* for the lower port number,
|
||||
* all the even number calls will return vision objects for the higher port number
|
||||
*
|
||||
*
|
||||
* This functions uses the following values of errno when an error state is
|
||||
* reached:
|
||||
* ENODEV - No vision sensor is plugged into the brain
|
||||
*
|
||||
* \return A vision object corresponding to a port that a vision sensor is connected to the brain
|
||||
* If no vision sensor is plugged in, it returns a vision sensor on port PROS_ERR_BYTE
|
||||
*
|
||||
*/
|
||||
static Vision get_vision();
|
||||
|
||||
private:
|
||||
///@}
|
||||
};
|
||||
} // namespace v5
|
||||
namespace literals {
|
||||
/**
|
||||
* Constructs a Vision sensor from a litteral ending in _vis
|
||||
*
|
||||
* \return a pros::Vision for the corresponding port
|
||||
*
|
||||
* \b Example
|
||||
* \code
|
||||
* using namespace pros::literals;
|
||||
* void opcontrol() {
|
||||
* pros::Vision vision = 2_vis; //Makes an Vision sensor object on port 2
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
const pros::Vision operator"" _vis(const unsigned long long int m);
|
||||
} // namespace literals
|
||||
} // namespace pros
|
||||
#endif // _PROS_VISION_HPP_
|
||||
Reference in new issue
Block a user