Teleoperated Robot Hand
Loading...
Searching...
No Matches
main.h
Go to the documentation of this file.
1
12
13#ifndef MAIN_H
14#define MAIN_H
15
16#include <Arduino.h>
17#include "WiFi.h"
18#include "esp_now.h"
19
25struct packet {
26 uint16_t thumb_reading;
27 uint16_t index_reading;
28 uint16_t middle_reading;
29 uint16_t ring_reading;
30 uint16_t pinkie_reading;
31 uint16_t palm_reading;
32};
33
34
40class Hand {
41 public:
42 QueueHandle_t thumb_queue;
43 QueueHandle_t index_queue;
44 QueueHandle_t middle_queue;
45 QueueHandle_t ring_queue;
46 QueueHandle_t pinkie_queue;
47 QueueHandle_t palm_queue;
48
54 Hand() {
55 thumb_queue = xQueueCreate(10, sizeof(uint16_t));
56 index_queue = xQueueCreate(10, sizeof(uint16_t));
57 middle_queue = xQueueCreate(10, sizeof(uint16_t));
58 ring_queue = xQueueCreate(10, sizeof(uint16_t));
59 pinkie_queue = xQueueCreate(10, sizeof(uint16_t));
60 palm_queue = xQueueCreate(10, sizeof(uint16_t));
61 }
62};
63
68const uint32_t THUMB_PIN = GPIO_NUM_36;
69const uint32_t INDEX_PIN = GPIO_NUM_39;
70const uint32_t MIDDLE_PIN = GPIO_NUM_34;
71const uint32_t RING_PIN = GPIO_NUM_35;
72const uint32_t PINKIE_PIN = GPIO_NUM_32;
73const uint32_t PALM_PIN = GPIO_NUM_33;
75
80const uint8_t ADC_RESOLUTION = 12; // 12 bit resolution
81
86const adc_attenuation_t ADC_ATTENUATION = ADC_11db;
87
88// WROOM 32D DevKit MAC Address: 0xE8, 0x6B, 0xEA, 0xD3, 0x9B, 0x98
89// Firebeetle MAC Address: 0x24, 0xDC, 0xC3, 0x82, 0x7F, 0xB4
90const uint8_t BROADCAST_ADDRESS[] = {0x24, 0xDC, 0xC3, 0x82, 0x7F, 0xB4}; // Receiver MAC Address
91
92
93void ReadSensorsTask(void *p_params);
94void TransmitTask(void *p_params);
95BaseType_t SendToQueue(const uint32_t pin, QueueHandle_t queue);
96uint16_t ReadQueue(QueueHandle_t queue);
97void PrintReadings(packet *hand);
98void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status);
99bool InitComms();
100
101
102#endif
Hand()
Construct a new Hand object and create all sensor queues.
Definition main.h:54
bool InitComms()
Initialize ESP-NOW communication subsystem.
Definition main.cpp:133
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status)
ESP-NOW send callback called after a packet is transmitted.
Definition main.cpp:188
BaseType_t SendToQueue(const uint32_t pin, QueueHandle_t queue)
Read a single ADC value and send it to a FreeRTOS queue.
Definition main.cpp:117
uint16_t ReadQueue(QueueHandle_t queue)
Empty a queue and return the average of all readings.
Definition main.cpp:137
void ReadSensorsTask(void *p_params)
FreeRTOS task that continuously reads flex sensors and pushes values into per-finger queues.
Definition main.cpp:24
void TransmitTask(void *p_params)
FreeRTOS task that averages queue data for each finger and sends packets over ESP-NOW.
Definition main.cpp:78
const adc_attenuation_t ADC_ATTENUATION
ADC attenuation configuration. Used with analogSetAttenuation to set the input range.
Definition main.h:86
void PrintReadings(packet *hand)
Print formatted finger readings to the Serial monitor.
Definition main.cpp:159
const uint8_t ADC_RESOLUTION
ADC configuration: resolution in bits. Used with analogReadResolution.
Definition main.h:80
Packet containing averaged flex sensor readings for each finger and the palm.
Definition main.h:25