miniFOC 1.0.3
This open-source project aims to accomplish a FOC(Field Oriented Control) scheme that is operatable with minimum costs in China.
report.c
Go to the documentation of this file.
1/**************************************************************************/
10#include "main.h"
11
16 unsigned int upload_var[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
17 unsigned char buffer[8] = {0, 0, 0, 0, 0, 0, 0, 0};
18
19 /* compress the angle deviation and motor phase sequence into a 32-bit integer */
22
23 /* converts user expect value to an integer */
24 switch (pid_control_mode_flag) {
25 default:
27 break;
29 break;
31 break;
32 }
33
34 /* converts speed pid parameters to an integer */
35 upload_var[2] = float_to_int32(speed_pid_handler.kp);
36 upload_var[3] = float_to_int32(speed_pid_handler.ki);
37 upload_var[4] = float_to_int32(speed_pid_handler.kd);
39
40 /* converts angle pid parameters to an integer */
41 upload_var[6] = float_to_int32(angle_pid_handler.kp);
42 upload_var[7] = float_to_int32(angle_pid_handler.ki);
43 upload_var[8] = float_to_int32(angle_pid_handler.kd);
45
46 for (unsigned char counter = 0; counter < 5; ++counter) {
47 /* separates 32-bit integer data into 8-bit integers */
48 buffer[0] = (unsigned char) ((upload_var[counter * 2] >> 24UL) & 0x000000ffUL);
49 buffer[1] = (unsigned char) ((upload_var[counter * 2] >> 16UL) & 0x000000ffUL);
50 buffer[2] = (unsigned char) ((upload_var[counter * 2] >> 8UL) & 0x000000ffUL);
51 buffer[3] = (unsigned char) (upload_var[counter * 2] & 0x000000ffUL);
52
53 /* separates 32-bit integer data into 8-bit integers */
54 buffer[4] = (unsigned char) ((upload_var[counter * 2 + 1] >> 24UL) & 0x000000ffUL);
55 buffer[5] = (unsigned char) ((upload_var[counter * 2 + 1] >> 16UL) & 0x000000ffUL);
56 buffer[6] = (unsigned char) ((upload_var[counter * 2 + 1] >> 8UL) & 0x000000ffUL);
57 buffer[7] = (unsigned char) (upload_var[counter * 2 + 1] & 0x000000ffUL);
58
59 /* packet and send through medium capacity data transmission protocol */
60 mdtp_data_transmit(0x01 + counter, buffer);
61 led_toggle();
62 delayms(20);
63 }
64}
65
70 unsigned char buffer[8] = {0, 0, 0, 0, 0, 0, 0, 0};
71
72 /* converts velocity and angle floating point data to an integer */
73 unsigned int velocity = float_to_int32(FOC_Struct.rotate_speed);
74 unsigned int angle = float_to_int32(FOC_Struct.mechanical_angle);
75
76 /* separates 32-bit velocity integer into 8-bit integers */
77 buffer[0] = (unsigned char) ((velocity >> 24UL) & 0x000000ffUL);
78 buffer[1] = (unsigned char) ((velocity >> 16UL) & 0x000000ffUL);
79 buffer[2] = (unsigned char) ((velocity >> 8UL) & 0x000000ffUL);
80 buffer[3] = (unsigned char) (velocity & 0x000000ffUL);
81
82 /* separates 32-bit angle integer into 8-bit integers */
83 buffer[4] = (unsigned char) ((angle >> 24UL) & 0x000000ffUL);
84 buffer[5] = (unsigned char) ((angle >> 16UL) & 0x000000ffUL);
85 buffer[6] = (unsigned char) ((angle >> 8UL) & 0x000000ffUL);
86 buffer[7] = (unsigned char) (angle & 0x000000ffUL);
87
88 /* packet and send through medium capacity data transmission protocol */
89 mdtp_data_transmit(0x00, buffer);
90}
volatile unsigned short machine_angle_offset
mechanical angle offset, which is used to align the mechanical angle with the zero point of the elect...
Definition: encoder.c:23
unsigned char foc_parameter_available_flag
flag variable for FOC parameter availability
Definition: foc.c:28
volatile FOC_Structure_t FOC_Struct
FOC handler.
Definition: foc.c:20
volatile unsigned char phase_sequence
motor phase sequence flag variable
Definition: foc.c:24
#define led_toggle()
flip the LED pin level
Definition: led.h:25
main function Header File
volatile unsigned char pid_control_mode_flag
flag variable of PID closed loop mode
Definition: pid.c:20
unsigned char pid_parameter_available_flag
flag variable for PID parameter availability
Definition: pid.c:16
volatile PID_Structure_t angle_pid_handler
algorithm handler of PID angle loop
Definition: pid.c:28
volatile PID_Structure_t speed_pid_handler
algorithm handler of PID speed loop
Definition: pid.c:24
#define ANGLE_LOOP_CONTROL
angle loop control mode
Definition: pid.h:18
#define TORQUE_LOOP_CONTROL
torque loop control mode
Definition: pid.h:14
#define SPEED_LOOP_CONTROL
speed loop control mode
Definition: pid.h:16
void report_local_variable(void)
report PID parameters and current user settings
Definition: report.c:15
void report_angle_speed(void)
report angle and speed using medium capacity transport protocol
Definition: report.c:69
float user_expect
user expect value of miniFOC
Definition: foc.h:20
float rotate_speed
motor rotate speed calculate from timer
Definition: foc.h:19
float mechanical_angle
mechanical angle read form encoder
Definition: foc.h:18
float ki
integral term coefficient in PID
Definition: pid.h:26
float kp
proportional term coefficient in PID
Definition: pid.h:25
float sum_maximum
maximum of anti saturation integral in PID
Definition: pid.h:32
float expect
user expectations in PID
Definition: pid.h:29
float kd
differential term coefficient in PID
Definition: pid.h:27
unsigned int float_to_int32(float data0)
convert floating point numbers to int32 type data
Definition: system.c:60
void delayms(unsigned long count)
millisecond delay function, any time time.
Definition: system.c:30
void mdtp_data_transmit(unsigned char pid, const unsigned char *buffer)
medium capacity data transmission protocol packing function
Definition: uart.c:113