Teleoperated Robot Hand
Loading...
Searching...
No Matches
pid.cpp File Reference

PID control and motor control helpers for robotic hand fingers. More...

#include "pid.h"

Functions

void PID_Init (PID_t *pid, float kp, float ki, float kd, float out_min, float out_max)
 Initialize a PID controller structure.
void InitPIDs ()
 Initialize all PID controllers used by the robotic hand.
void PID_Reset (PID_t *pid)
 Reset a PID controller's internal state.
float PID_Step (PID_t *pid, float error, float dt)
 Perform one PID control step.
void SetPhase (float u, uint32_t motor_phase_pin)
 Set motor direction based on signed control effort.
void PositionControlFinger (uint32_t enc, uint32_t target, PID_t *pid, int pwm_channel, int phase_pin, float dt)
 Perform PID-based position control for a single finger motor.
bool HomeFinger (uint32_t enc, uint32_t home_target, int pwm_channel, int phase_pin)
 Home a single finger motor to a reference position.

Detailed Description

PID control and motor control helpers for robotic hand fingers.

This module provides:

  • Generic PID initialization, reset, and step functions
  • Homing control logic for DC motors with encoders
  • Position control using PID with PWM + phase output

Designed for use with FreeRTOS-based embedded systems.

Function Documentation

◆ HomeFinger()

bool HomeFinger ( uint32_t enc,
uint32_t home_target,
int pwm_channel,
int phase_pin )

Home a single finger motor to a reference position.

Drives the motor toward a known home encoder value using a proportional controller until the error falls below ::HOMING_THRESHOLD.

Parameters
encCurrent encoder reading.
home_targetDesired home encoder value.
pwm_channelLEDC PWM channel controlling the motor.
phase_pinGPIO pin controlling motor direction.
Returns
true if the finger is homed, false otherwise.

◆ InitPIDs()

void InitPIDs ( )

Initialize all PID controllers used by the robotic hand.

Sets gains and output limits for all fingers and palm.

◆ PID_Init()

void PID_Init ( PID_t * pid,
float kp,
float ki,
float kd,
float out_min,
float out_max )

Initialize a PID controller structure.

Sets controller gains, output limits, and clears internal state.

Parameters
pidPointer to PID controller structure.
kpProportional gain.
kiIntegral gain.
kdDerivative gain.
out_minMinimum allowable output.
out_maxMaximum allowable output.

◆ PID_Reset()

void PID_Reset ( PID_t * pid)

Reset a PID controller's internal state.

Clears the integral accumulator and previous error term.

Parameters
pidPointer to PID controller structure.

◆ PID_Step()

float PID_Step ( PID_t * pid,
float error,
float dt )

Perform one PID control step.

Computes the control output using proportional, integral, and derivative terms and applies output clamping.

Parameters
pidPointer to PID controller structure.
errorCurrent control error (setpoint - measurement).
dtTime step in seconds since last update.
Returns
Saturated control output value.

◆ PositionControlFinger()

void PositionControlFinger ( uint32_t enc,
uint32_t target,
PID_t * pid,
int pwm_channel,
int phase_pin,
float dt )

Perform PID-based position control for a single finger motor.

Computes the control effort using PID, sets motor direction, enforces a minimum PWM threshold, and applies the PWM output.

Parameters
encCurrent encoder reading.
targetDesired encoder target value.
pidPointer to PID controller for this finger.
pwm_channelLEDC PWM channel controlling the motor.
phase_pinGPIO pin controlling motor direction.
dtControl loop timestep in seconds.

◆ SetPhase()

void SetPhase ( float u,
uint32_t motor_phase_pin )

Set motor direction based on signed control effort.

Uses the sign of the control signal to determine the motor rotation direction via the phase pin.

Parameters
uSigned control output.
motor_phase_pinGPIO pin controlling motor direction.