Pressure Sensor
PressureThe pressure sensors measureare fluid/gasanalog pressureforce sensing resistor (FSR) pads read via ADC, intended primarily for robotic gripper force feedbackfeedback: grip force sensing, object presence detection, and control,load depthdistribution sensing,across altitudetwo measurement,gripper or system pressure monitoring.pads. The system supports a dual pressure sensor configuration for dual-pad gripper control with load distribution feedback.configuration.
Hardware Specifications
Parameter | Value |
|---|---|
Sensor Count | 2 (independent) |
Interface | Analog ADC |
|
|
|
|
Hardware Status
The ADC path is compile gated by PRESSURE_USE_ADC because no ADC is enabled in CubeMX yet. Without the flag, poll_pressure_sensor() returns RESULT_ERR_UNIMPLEMENTED and both sensors report IDLE / DISCONNECTED (the firmware still links). To enable:
- In CubeMX enable an ADC and the channel(s) for the force pins. On the STM32H753, PD15 has NO ADC function and PF3 = ADC3_INP5, so FORCE_ANALOG_DATA_1 must be moved to an ADC-capable pin.
- Build with
-D PRESSURE_USE_ADC. - Bind each unit with pressure_sensor_init_hw().
Conversion Model
voltage = raw / adc_max × reference_voltage
pressure_kpa = voltage × scale_kpa_per_volt + offset_kpa
Defaults: scale_kpa_per_volt = 1.0, offset_kpa = 0.0 (passthrough until calibrated).
Data Structure
typedef struct {
float pressure_kpa;
// Pressure in kilopascals (kPa)
float temperature_c; // Temperature in Celsius (°C)
float voltage;
// Sensor output voltage
bool is_calibrated;
bool read_ok; /* true if the last poll read succeeded */
Calibration/* statusADC flagbinding (set by pressure_sensor_init_hw) */
void *adc_handle; /* ADC_HandleTypeDef* (void* keeps header HAL-free) */
uint32_t adc_channel; /* ADC_CHANNEL_x */
uint32_t adc_max; /* full-scale count (e.g. 65535 for 16-bit) */
float reference_voltage; /* ADC Vref+ in volts */
float scale_kpa_per_volt; /* linear gain (default 1.0) */
float offset_kpa; /* linear offset (default 0.0) */
} pressure_sensor_data_t;
Initialization
Initialize Pressure Sensors (as in main.c)
pressure_sensor_data_t pressure_data[2]; // Support 2 sensors
for (size_t i = 0; i < 2; i++) {
pressure_sensor_init(&pressure_data[i]);
}
/* Once an ADC exists, bind it per unit: */
pressure_sensor_init_hw(&pressure_data[1], &hadc3, ADC_CHANNEL_5,
65535U, 3.3f);
Poll Pressure Sensor
result_t ps_resultpr_result = poll_pressure_sensor(&pressure_data[0]i]);
if (ps_result == RESULT_OK) {
float pressure_kpa = pressure_data[0].pressure_kpa;
float temperature_c = pressure_data[0].temperature_c;
}
Data Access Functions
//float Getkpa, pressuretemp_c, involtage;
kilopascalsbool result_tvalid;
pressure_sensor_get_pressure_kpa(&sensor, const pressure_sensor_data_t *data,
float *pressure_kpa
)&kpa);
//pressure_sensor_get_temperature_c(&sensor, Get temperature in Celsius
result_t pressure_sensor_get_temperature_c(
const pressure_sensor_data_t *data,
float *temperature_c
)&temp_c);
pressure_sensor_get_voltage(&sensor, &voltage);
pressure_sensor_is_valid(&sensor, &valid);
Calibration
//* GetkPa raw= V × scale + offset; marks the sensor voltage
result_t pressure_sensor_get_voltage(
const pressure_sensor_data_tcalibrated *data,
float *voltage
);
//
Verifypressure_sensor_set_calibration(&sensor, sensorscale_kpa_per_volt, validity
result_t pressure_sensor_is_valid(
const pressure_sensor_data_t *data,
bool *is_valid
)offset_kpa);
Pressure Unit Conversions
Function-Based Conversions
// Convert pressure from bar to psi
result_t bar_to_psi(float bar, float *psi);
// Convert pressure from psi to bar
result_t psi_to_bar(float psi, float *bar);Conversion Table
From | To | Multiply By |
|---|---|---|
bar | kPa | 100 |
psi | kPa | 6.895 |
atm | kPa | 101.325 |
kPa | bar | 0.01 |
kPa | psi | 0.145 |
kPa | atm | 0.00987 |
Examples
Function-based
// 100 kPa = 1 bar
float kpa = 100.0f;
float bar = kpa * 0.01f; // Result: 1.0 bar
// 50 psi to bar
float psi = 50.0f;
float bar = psi / 14.504f; // Result: 3.45 bar
// Altitude from pressureconversions (simplified)bar_to_psi, //psi_to_bar) Altitudeare ≈declared 44330in ×the (1utility -library (P/P0)^(1/5.255))but floatcurrently altitude_mcommented =out; 44330.0fsee *Sensor (1.0fBoard -Utility pow(pressure_kpa/101.325f, 1.0f/5.255f));Library.
Protobuf Message Format
message SensorBoardPressureInfo {
uint32 sensor_index; //* 0 or 1 */
float pressure_kpa;
float temperature_c;
float voltage;
bool is_calibrated;
SensorState state;
PressureErrorCode error_code; }/* DualNO_ERROR, SensorCOMMUNICATION_FAILURE, Management
INVALID_DATA Configuration Example
/*/
Initialize both sensors
for (size_t i = 0; i < 2; i++) {
pressure_sensor_init(&pressure_data[i]);
}
// Poll both in sequence
poll_pressure_sensor(&pressure_data[0]);
poll_pressure_sensor(&pressure_data[1]);
// Access by index
float pressure_0_kpa = pressure_data[0].pressure_kpa;
float pressure_1_kpa = pressure_data[1].pressure_kpa;Temperature Compensation
Pressure readings often need temperature compensation for accuracy:
// Simplified temperature compensation
float compensated_pressure = pressure_data[0].pressure_kpa *
(reference_temperature + 273.15f) /
(pressure_data[0].temperature_c + 273.15f);
Applications
Robotic Gripper Control (Primary Use Case)
// Gripper force feedback for adaptive grip strength
// Pressure reading controls servo/motor PWM to regulate grip force
#define GRIPPER_MIN_PRESSURE_KPA 20.0f // Minimum safe grip
#define GRIPPER_MAX_PRESSURE_KPA 150.0f // Maximum allowed grip
#define GRIPPER_TARGET_PRESSURE_KPA 80.0f // Desired grip force
// PID controller for gripper force regulation
typedef struct {
float kp, ki, kd; // PID coefficients
float integral_error;
float previous_error;
} gripper_pid_t;
// Adjust servo PWM based on pressure feedback
void adjust_gripper_force(float current_pressure_kpa, gripper_pid_t *pid) {
float error = GRIPPER_TARGET_PRESSURE_KPA - current_pressure_kpa;
pid->integral_error += error;
float derivative_error = error - pid->previous_error;
float pid_output = (pid->kp * error) +
(pid->ki * pid->integral_error) +
(pid->kd * derivative_error);
// Clamp servo PWM to valid range
uint16_t servo_pwm = (uint16_t)(GRIPPER_NEUTRAL_PWM + pid_output);
servo_pwm = (servo_pwm < GRIPPER_MIN_PWM) ? GRIPPER_MIN_PWM : servo_pwm;
servo_pwm = (servo_pwm > GRIPPER_MAX_PWM) ? GRIPPER_MAX_PWM : servo_pwm;
set_gripper_pwm(servo_pwm);
pid->previous_error = error;
}Gripper Control Features:
- Grip force feedback for object handling
- Object presence detection (pressure spike threshold)
- Adaptive compliance for varying object
sizes/sizes and materials - Dual sensors support load sharing across gripper pads
ImplementedPossible butSecondary NotUses Primary(not implemented)
- Depth
Sensingsensing (Water)
//altitude Pressure to depth in water
// P = ρ × g × h
// where ρ = 1025 kg/m³sensing (seawater)air), g = 9.81 m/s²
float depth_meters = (pressure_kpa - atmospheric_pressure_kpa) / 10.0f;Altitude Sensing (Air)
// Barometric formula (simplified)
float altitude_m = 44330.0f * (1.0f - pow(pressure_kpa/101.325f, 1.0f/5.255f));System Pressure Monitoring
if (pressure_kpa > PRESSURE_WARNING_THRESHOLD) {
// Highsystem pressure detectedmonitoring, -if safetya alert
}Common Pressure Sensor Ranges
|
|
|
|---|---|---|
|
|
|
|
|
|
|
|
|
Integration Notes
Primary Application:Robotic gripper force feedback and controlSupports up to 2Two independentpressureunitssensorspolled(dualeverygripper pads)Temperature measurement for compensation algorithmsHardware-specific ADC or I2C implementationPressure-voltage conversion implemented internallyReal-time depth/altitude sensing capabilityPID controlmain loopintegrationiteration,foreachadaptivetransmittedgripinforceits own envelope with its sensor_index (logged under the name "Force0"/"Force1")- Each sensor maintains independent calibration and error reporting
TemperatureThetrackingtemperature_c field exists foraccuracyfutureimprovementscompensation algorithms; no temperature source is wired up yetSlipUntildetectiontheviaADCpressureisvarianceenabledanalysisthe sensors are harmless placeholders: IDLE / DISCONNECTED, zeroed values