我在 Nios 2 中为学校作业编写了一个临时巡航控制系统。我用 github 对其进行了版本控制。我们希望巡航控制在速度 >= 25 m/s 时最多相差 2 m/s。我能做的最新改进是检查确实改善了控制的条件下的速度。在我尝试改变之前我无法证明改变会产生效果,所以这是一种临时的试错方法,不太好。现在,如果激活,巡航控制实际上会将速度保持在 2 m/s 以内。既然我设法改进了一次,还能做些什么呢?我可以使用控制理论中的东西来改进行为吗?
/*
* The task 'ControlTask' is the main task of the application. It reacts
* on sensors and generates responses.
*/
void ControlTask(void* pdata)
{
INT8U err;
INT8U throttle = 40; /* Value between 0 and 80, which is interpreted as between 0.0V and 8.0V */
void* msg;
INT16S* current_velocity;
int btn_reg;
INT16S* current_output;
printf("Control Task created!\n");
while (1)
{
OSSemPend(aSemaphore, 1, &err); // Trying to access the key
msg = OSMboxPend(Mbox_Velocity, 0, &err);
current_velocity = (INT16S*) msg;
printf("Control Task!\n");
ButtonIO(current_velocity, throttle);
btn_reg = IORD_ALTERA_AVALON_PIO_DATA(DE2_PIO_KEYS4_BASE);
printf("btn_reg %d\n", btn_reg);
if (btn_reg == 7) {
++throttle;
} else if (cruise_control_increase_velocity == 1) {
printf("increase velocity \n");
if (*current_velocity <= cruise_velocity) {
throttle = throttle + 15;
}
cruise_control_increase_velocity = 0;
}
else if (btn_reg == 11) {
if (throttle > 0) {
--throttle;
}
} else if (cruise_control_decrease_velocity == 1) {
printf("decrease_velocity \n");
if (throttle >= 15 && current_velocity >= cruise_velocity) {
throttle = throttle -15;
}
cruise_control_decrease_velocity = 0;
}
if (btn_reg== 13) {
printf("do cruise control\n" );
cruise_velocity = *current_velocity;
}
Button1IO(current_velocity);
SwitchIO(current_velocity, getGlobalPosition());
err = OSMboxPost(Mbox_Throttle, (void *) &throttle);
}
}