-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
executable file
·34 lines (29 loc) · 1 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
* TongSheng TSDZ2 motor controller firmware/
*
* Copyright (C) Casainho, 2018.
*
* Released under the GPL License, Version 3
*/
#ifndef _UTILS_H
#define _UTILS_H
#include "main.h"
typedef struct pi_controller_state
{
uint8_t ui8_current_value;
uint8_t ui8_target_value;
uint8_t ui8_controller_output_value;
uint8_t ui8_kp_dividend;
uint8_t ui8_kp_divisor;
uint8_t ui8_ki_dividend;
uint8_t ui8_ki_divisor;
int16_t i16_i_term;
} struct_pi_controller_state;
int32_t map (int32_t x, int32_t in_min, int32_t in_max, int32_t out_min, int32_t out_max);
int32_t map_inverse (int32_t x, int32_t in_min, int32_t in_max, int32_t out_min, int32_t out_max);
uint8_t ui8_max (uint8_t value_a, uint8_t value_b);
uint8_t ui8_min (uint8_t value_a, uint8_t value_b);
void pi_controller (struct_pi_controller_state *pi_controller_state);
void pi_controller_reset (struct_pi_controller_state *pi_controller);
void crc16(uint8_t ui8_data, uint16_t* ui16_crc);
#endif /* _UTILS_H */