Page MenuHomec4science

communication.h
No OneTemporary

File Metadata

Created
Tue, May 28, 22:53

communication.h

#ifndef __COMMUNICATION_H
#define __COMMUNICATION_H
#include "main.h"
// Message IDs sent by host (PC) to the device (STM).
#define PC_MESSAGE_DO_NOTHING 0 // Do nothing.
#define PC_MESSAGE_TOGGLE_LED 1 // Toggle the LED (debug).
#define PC_MESSAGE_SEND_STATUS 2 // Request the device to send the main status register.
#define PC_MESSAGE_START_STREAMING 3 // Request the device to start streaming continuously.
#define PC_MESSAGE_STOP_STREAMING 4 // Request the device to stop streaming continuously.
#define PC_MESSAGE_GET_VAR 5 // Request the device to send the selected value.
#define PC_MESSAGE_SET_VAR 6 // Set the selected variable.
#define PC_MESSAGE_SET_STREAMED_VAR 7 // Set the variables to be streamed.
// Message IDs sent by device (STM) to the device (PC).
#define STM_MESSAGE_STATUS 0 // Main status register.
#define STM_MESSAGE_VAR 1 // Variable state.
#define STM_MESSAGE_STREAMING_PACKET 2 // Streaming packet.
// Variables IDs.
#define VAR_TIMESTAMP 0 // Timestamp. [us]
#define VAR_POS_REG_PID_P 1 // Position regulator - proportionnal coefficient. [1]
#define VAR_POS_REG_PID_I 2 // Position regulator - integral coefficient. [1]
#define VAR_POS_REG_PID_D 3 // Position regulator - derivative coefficient. [1]
#define VAR_POS_REG_PID_ARW 4 // Position regulator - ARW (integrator max value). [1]
#define VAR_POS_REG_PID_INTEGRATOR 5 // Position regulator - integrator state. [1]
#define VAR_POS_REG_PID_OUTPUT 6 // Position regulator - output. [mN.m]
#define VAR_POS_REG_SAMPLING_PERIOD 7 // Position regulator - sampling period [us]
#define VAR_WALL_POSITION 8 // Position regulator - target (wall position). [pulses]
#define VAR_MEASURED_ANGLE_RAW 9 // Measured output angle, unfiltered. [pulses]
#define VAR_MEASURED_ANGLE_FILTERED 10 // Measured output angle, filtered. [pulses]
#define VAR_COMM_TX_PERIOD 11 // Communication loop - sending period. [us]
#define VAR_ACTIVE_FILTER 12 // Active filter type (0: none, 1: first-order, 2: running mean). [None]
#define VAR_1ST_FILT_TAU 13 // First order filter - time constant. [1]
#define VAR_DAC1_VOLTAGE 14 // DAC 1 channel voltage. [V]
#define VAR_DAC2_VOLTAGE 15 // DAC 2 channel voltage. [V]
#define VAR_ADC1_VOLTAGE 16 // ACDC 1 channel voltage. [V]
#define VAR_ADC2_VOLTAGE 17 // ACDC 2 channel voltage. [V]
#define VAR_HALL_ANGLE 18 // Angle measured by the Hall sensor. [deg]
#define VAR_TACHO_SPEED 19 // Angular speed measured by the tachometer. [deg/s]
#define VAR_STRAIN_GAUGE_FORCE 20 // Force measured by the strain gauge. [?]
#define VAR_USER_VAR_1 21 // User Variable 1 []
#define VAR_USER_VAR_2 22 // User Variable 2 []
#define VAR_USER_VAR_3 23 // User Variable 3 []
#define VAR_USER_VAR_4 24 // User Variable 4 []
#define VAR_USER_VAR_5 25 // User Variable 5 []
#define N_VARIABLES 26 // Number of variables, used for enumeration of all variables.
/** @defgroup Communication Main / Communication
* @brief Control the communication with the computer.
*
* This module controls all the communication logic between the board and the
* computer. It uses a specific communication protocol between the
* computer and the board, with a system of messages. Thanks to this, the
* the MATLAB application is able to get the value of selected variables on the
* STM, and is even capable of modifiying them remotely.
*
* Make sure that the files communication.h/.c are up-to-date with the Excel
* spreadsheet "Protocol description.xlsx".
*
* Call comm_Init() to setup this module. Its interrupt function will be called
* automatically when a message arrives, or periodically when the data
* streaming is enabled.
*
* @addtogroup Communication
* @{
*/
void comm_Init(void);
/**
* @}
*/
#endif

Event Timeline