Teleoperated Robot Hand
Loading...
Searching...
No Matches
main.h File Reference

Glove transmitter interface for sensor acquisition and ESP-NOW communication. More...

#include <Arduino.h>
#include "WiFi.h"
#include "esp_now.h"

Go to the source code of this file.

Classes

struct  packet
 Packet containing averaged flex sensor readings for each finger and the palm. More...
class  Hand
 Class holding FreeRTOS queues for all glove fingers and palm. More...

Functions

void ReadSensorsTask (void *p_params)
 FreeRTOS task that continuously reads flex sensors and pushes values into per-finger queues.
void TransmitTask (void *p_params)
 FreeRTOS task that averages queue data for each finger and sends packets over ESP-NOW.
BaseType_t SendToQueue (const uint32_t pin, QueueHandle_t queue)
 Read a single ADC value and send it to a FreeRTOS queue.
uint16_t ReadQueue (QueueHandle_t queue)
 Empty a queue and return the average of all readings.
void PrintReadings (packet *hand)
 Print formatted finger readings to the Serial monitor.
void OnDataSent (const uint8_t *mac_addr, esp_now_send_status_t status)
 ESP-NOW send callback called after a packet is transmitted.
bool InitComms ()
 Initialize ESP-NOW communication subsystem.

Variables

const uint8_t ADC_RESOLUTION = 12
 ADC configuration: resolution in bits. Used with ::analogReadResolution.
const adc_attenuation_t ADC_ATTENUATION = ADC_11db
 ADC attenuation configuration. Used with ::analogSetAttenuation to set the input range.
const uint8_t BROADCAST_ADDRESS [] = {0x24, 0xDC, 0xC3, 0x82, 0x7F, 0xB4}
Flex sensor ADC input pins

GPIO pins connected to each flex sensor (ADC channels).

const uint32_t THUMB_PIN = GPIO_NUM_36
const uint32_t INDEX_PIN = GPIO_NUM_39
const uint32_t MIDDLE_PIN = GPIO_NUM_34
const uint32_t RING_PIN = GPIO_NUM_35
const uint32_t PINKIE_PIN = GPIO_NUM_32
const uint32_t PALM_PIN = GPIO_NUM_33

Detailed Description

Glove transmitter interface for sensor acquisition and ESP-NOW communication.

This header defines the public interface for the glove-side firmware, including:

  • Data structures for packaging sensor readings
  • A Hand class encapsulating FreeRTOS queues for each finger and the palm
  • Hardware configuration constants for ADC inputs
  • ESP-NOW communication parameters
  • FreeRTOS task prototypes for sensing and transmission

Function Documentation

◆ InitComms()

bool InitComms ( )

Initialize ESP-NOW communication subsystem.

Initialize ESP-NOW communications and register the receiver peer.

Sets WiFi to station mode, initializes ESP-NOW, and registers the receive callback.

Returns
true on success, false on failure.

This function:

  • Puts WiFi into station mode.
  • Initializes ESP-NOW.
  • Registers OnDataSent as the send callback.
  • Adds the receiver peer specified by ::BROADCAST_ADDRESS.
Returns
true on success, false if initialization or peer registration fails.

Initialize ESP-NOW communication subsystem.

This function:

  • Puts WiFi into station mode.
  • Initializes ESP-NOW.
  • Registers OnDataSent as the send callback.
  • Adds the receiver peer specified by ::BROADCAST_ADDRESS.
Returns
true on success, false if initialization or peer registration fails.

◆ OnDataSent()

void OnDataSent ( const uint8_t * mac_addr,
esp_now_send_status_t status )

ESP-NOW send callback called after a packet is transmitted.

This callback is registered via ::esp_now_register_send_cb and reports whether the last transmission was successful.

Parameters
mac_addrMAC address of the peer to which the data was sent.
statusTransmission status, e.g. ::ESP_NOW_SEND_SUCCESS on success.

◆ PrintReadings()

void PrintReadings ( packet * hand)

Print formatted finger readings to the Serial monitor.

Parameters
handPointer to a packet structure containing all finger readings.

◆ ReadQueue()

uint16_t ReadQueue ( QueueHandle_t queue)

Empty a queue and return the average of all readings.

This function repeatedly calls ::xQueueReceive with zero block time until the queue is empty. It computes the average of all values removed.

Parameters
queueHandle to the FreeRTOS queue containing sensor readings.
Returns
Average of all readings in the queue, or 0 if the queue was empty.

◆ ReadSensorsTask()

void ReadSensorsTask ( void * p_params)

FreeRTOS task that continuously reads flex sensors and pushes values into per-finger queues.

The task:

  • Configures ADC resolution and attenuation.
  • Periodically reads each sensor using SendToQueue.
  • Logs an error over Serial if queue send fails.
Parameters
p_paramsPointer to task parameters (unused).

◆ SendToQueue()

BaseType_t SendToQueue ( const uint32_t pin,
QueueHandle_t queue )

Read a single ADC value and send it to a FreeRTOS queue.

This function performs an ADC reading on the specified pin (in millivolts) and attempts to enqueue the reading into the provided queue.

Parameters
pinGPIO pin connected to the flex sensor (ADC input).
queueHandle to the FreeRTOS queue for this sensor.
Returns
pdPASS on success, or an error code from ::xQueueSend on failure.

◆ TransmitTask()

void TransmitTask ( void * p_params)

FreeRTOS task that averages queue data for each finger and sends packets over ESP-NOW.

The task:

  • Reads and averages queued sensor values with ReadQueue.
  • Packages readings into a packet.
  • Prints readings via PrintReadings.
  • Sends the packet with ::esp_now_send and reports success or failure.
Parameters
p_paramsPointer to task parameters (unused).