GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — code/APP/ControlTask.c at master · sysulion/code

Expand file tree

/

ControlTask.c

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
196 lines (175 loc) · 5.74 KB
/

ControlTask.c

Copy path

File metadata and controls

196 lines (175 loc) · 5.74 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include "main.h"
PID_Regulator_t CMRotatePID = CHASSIS_MOTOR_ROTATE_PID_DEFAULT;
PID_Regulator_t CM1SpeedPID = CHASSIS_MOTOR_SPEED_PID_DEFAULT;
PID_Regulator_t CM2SpeedPID = CHASSIS_MOTOR_SPEED_PID_DEFAULT;
PID_Regulator_t CM3SpeedPID = CHASSIS_MOTOR_SPEED_PID_DEFAULT;
PID_Regulator_t CM4SpeedPID = CHASSIS_MOTOR_SPEED_PID_DEFAULT;
/*--------------------------------------------CTRL Variables----------------------------------------*/
WorkState_e lastWorkState = PREPARE_STATE;
WorkState_e workState = PREPARE_STATE;
RampGen_t GMPitchRamp = RAMP_GEN_DAFAULT;
RampGen_t GMYawRamp = RAMP_GEN_DAFAULT;
float error_now=0,error_last=0;
float error_now_yaw=0,error_last_yaw=0;
/*
*********************************************************************************************************
* FUNCTIONS
*********************************************************************************************************
*/
static void SetWorkState(WorkState_e state)
{
workState = state;
}
WorkState_e GetWorkState()
{
return workState;
}
//底盘控制任务
void CMControlLoop(void)
{
//底盘旋转量计算
if(GetWorkState()==PREPARE_STATE) //启动阶段,底盘不旋转
{
ChassisSpeedRef.rotate_ref = 0;
}
else if(GimbalRef.yaw_angle_dynamic_ref == 0.0)
{
ChassisSpeedRef.rotate_ref = 0;
}
else
{
ChassisSpeedRef.rotate_ref = 5*GimbalRef.yaw_angle_dynamic_ref;
}
CM1SpeedPID.ref = -ChassisSpeedRef.forward_back_ref*0.075 + ChassisSpeedRef.left_right_ref*0.075 + 0.9*ChassisSpeedRef.rotate_ref;
CM2SpeedPID.ref = ChassisSpeedRef.forward_back_ref*0.075 + ChassisSpeedRef.left_right_ref*0.075 + 0.9*ChassisSpeedRef.rotate_ref;
CM3SpeedPID.ref = ChassisSpeedRef.forward_back_ref*0.075 - ChassisSpeedRef.left_right_ref*0.075 + 0.9*ChassisSpeedRef.rotate_ref;
CM4SpeedPID.ref = -ChassisSpeedRef.forward_back_ref*0.075 - ChassisSpeedRef.left_right_ref*0.075 + 0.9*ChassisSpeedRef.rotate_ref;
CM1SpeedPID.fdb = 0.04*CM1Encoder.filter_rate;
CM2SpeedPID.fdb = 0.04*CM2Encoder.filter_rate;
CM3SpeedPID.fdb = 0.04*CM3Encoder.filter_rate;
CM4SpeedPID.fdb = 0.04*CM4Encoder.filter_rate;
CM1SpeedPID.Calc(&CM1SpeedPID);
CM2SpeedPID.Calc(&CM2SpeedPID);
CM3SpeedPID.Calc(&CM3SpeedPID);
CM4SpeedPID.Calc(&CM4SpeedPID);
if((GetWorkState() == STOP_STATE) || GetWorkState() == CALI_STATE || GetWorkState() == PREPARE_STATE)//if((GetWorkState() == STOP_STATE) ||Is_Serious_Error() || GetWorkState() == CALI_STATE || GetWorkState() == PREPARE_STATE) //|| dead_lock_flag == 1紧急停车,编码器校准,无控制输入时都会使底盘控制停止
{
Set_CM_Speed(CAN2, 0,0,0,0);
}
else
{
Set_CM_Speed(CAN2, CHASSIS_SPEED_ATTENUATION * CM1SpeedPID.output, CHASSIS_SPEED_ATTENUATION * CM2SpeedPID.output, CHASSIS_SPEED_ATTENUATION * CM3SpeedPID.output, CHASSIS_SPEED_ATTENUATION * CM4SpeedPID.output);
}
// char temp[50];
// sprintf(temp,"ref:%10.3f ",CM1SpeedPID.ref);
// UART3_PutStr (temp);//发送字符串
// sprintf(temp,"fdb:%10.3f ",CM1SpeedPID.fdb);
// UART3_PutStr (temp);//发送字符串
// sprintf(temp,"output:%10.3f ",CM1SpeedPID.output);
// UART3_PutStr (temp);//发送字符串
// USART_SendData(USART3, '\n');
}
//发射机构射击电机任务
int16_t pwm_ccr = 0;
static uint32_t time_tick_1ms = 0;
//控制任务,放在timer6 1ms定时中断中执行
void Control_Task(void)
{
time_tick_1ms++;
WorkStateFSM();
WorkStateSwitchProcess();
//chassis motor control
if(time_tick_1ms%4 == 0) //motor control frequency 4ms
{
CMControlLoop();
}
}
/**********************************************************
*工作状态切换状态机,与1ms定时中断同频率
**********************************************************/
void WorkStateFSM(void)
{
lastWorkState = workState;
switch(workState)
{
case PREPARE_STATE:
{
if(GetInputMode() == STOP) //|| Is_Serious_Error())
{
workState = STOP_STATE;
}
else if(time_tick_1ms > PREPARE_TIME_TICK_MS)
{
workState = NORMAL_STATE;
}
}break;
case NORMAL_STATE:
{
if(GetInputMode() == STOP) //|| Is_Serious_Error())
{
workState = STOP_STATE;
}
}break;
case STANDBY_STATE:
{
if(GetInputMode() == STOP) //|| Is_Serious_Error())
{
workState = STOP_STATE;
}
else if(IsRemoteBeingAction() || (GetShootState()==SHOOTING) || GetFrictionState() == FRICTION_WHEEL_START_TURNNING)
{
workState = NORMAL_STATE;
}
}break;
case STOP_STATE:
{
if(GetInputMode() != STOP) //&& !Is_Serious_Error())
{
workState = PREPARE_STATE;
}
}break;
case CALI_STATE:
{
if(GetInputMode() == STOP) //|| Is_Serious_Error())
{
workState = STOP_STATE;
}
}break;
default:
{
}
}
}
static void WorkStateSwitchProcess(void)
{
//如果从其他模式切换到prapare模式,要将一系列参数初始化
if((lastWorkState != workState) && (workState == PREPARE_STATE))
{
ControtLoopTaskInit();
RemoteTaskInit();
}
}
/*
************************************************************************************************************************
*Name : GimbalYawControlModeSwitch
* Description: This function process the yaw angle ref and fdb according to the WORKSTATE.
* Arguments : void
* Returns : void
* Note(s) : 1) from NORMAL to STANDBY it need to delay a few seconds to wait for the IMU to be steady.
STATE_SWITCH_DELAY_TICK represents the delay time.
************************************************************************************************************************
*/
//控制任务初始化程序
void ControtLoopTaskInit(void)
{
//计数初始化
time_tick_1ms = 0; //中断中的计数清零
//设置工作模式
SetWorkState(PREPARE_STATE);
//PID初始化
CMRotatePID.Reset(&CMRotatePID);
CM1SpeedPID.Reset(&CM1SpeedPID);
CM2SpeedPID.Reset(&CM2SpeedPID);
CM3SpeedPID.Reset(&CM3SpeedPID);
CM4SpeedPID.Reset(&CM4SpeedPID);
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.