一;收货组装02
二;电机驱动
三;软件程序学习
(4)小车绕8字走
一;收货组装
下单过了将近一个星期才到的货,心情非常好。
抱着激动的心情打开了包裹,清点了材料。
下面就是组装,对我来说是挑战,为什么这么说呢?首先得装铜柱,可我怎么就按不进去,弄了好久,才知道自己安错铜柱了,之后固定板子,
在后来,就是安显示屏,直接插入排针就可以了,但是有时候它接触不良,所以还是要把它焊接。
接下来连接电机线,和电池线。
接下来就是.安装上层保护板子。
最后,就是打开开关,测试硬件是否好坏。
当你看到小车来回摆动是正常的。
关于上面的英文,在下面说下。
第一行,获取角度的方法,有DMP KALMAN 互补
第二行 主板温度
第三行 编码器速度
第四行 编码器速度
第五行 电池电压
最后一行 角度。
首先先连接上串口,PL2303,
将小车botto0打至高电平,打开mucisp,开始编译。
编译成功后,左边显示如图
接下来,打开上位机波显,以管理员的身份运行。具体操作课参考http://forum.eepw.com.cn/thread/273198/1
于是我们可以得到数据,如图
在调试的过程中,各数据在不断的变化,唯一就是不知道,为什么不显示波形。
对于这个软件不太会,根据777的提示说这个是因为效果不明显,而不是显示不出。于是去参考了xxjian的帖子,考虑用visual scope来得到波形。
对于visual scope,具体可参考http://forum.eepw.com.cn/thread/273082/1#2。
对于PID参数的调试,由于对代码这方面很多不熟悉,所以参考别人的代码,具体代码地址;http://forum.eepw.com.cn/thread/273082/2#13
代码;int B_Kp,B_Ki,B_Kd,V_Kp,V_Ki, T_Kp,T_Kd;首先在前行定义。
主函数如下;usart.c文件
if(USART3->SR&(1<<5))//½ÓÊÕµ½Êý¾Ý
{
static int uart_receive=0;//À¶ÑÀ½ÓÊÕÏà¹Ø±äÁ¿
uart_receive=USART3->DR;
if(uart_receive<10) mode_data[0]=uart_receive;
if((mode_data[0]==six_data_2[0]
&&mode_data[1]==six_data_2[1]
&&mode_data[2]==six_data_2[2]
&&mode_data[3]==six_data_2[3])
||(mode_data[0]==six_data_1[0]
&&mode_data[1]==six_data_1[1]
&&mode_data[2]==six_data_1[2]
&&mode_data[3]==six_data_1[3]))
{
Flag_Stop=!Flag_Stop;
mode_data[0]=0; mode_data[1]=0; mode_data[2]=0; mode_data[3]=0;
}
if(uart_receive==0x00) Flag_Qian=0,Flag_Hou=0,Flag_Left=0,Flag_Right=0;//////////////ɲ³µ
if(uart_receive==0x01) Flag_Qian=1,Flag_Hou=0,Flag_Left=0,Flag_Right=0;//////////////Ç°
if(uart_receive==0x05) Flag_Qian=0,Flag_Hou=1,Flag_Left=0,Flag_Right=0;//////////////ºó
else if(uart_receive==0x02||uart_receive==0x03||uart_receive==0x04)
Flag_Qian=0,Flag_Hou=0,Flag_Left=0,Flag_Right=1;
else if(uart_receive==0x06||uart_receive==0x07||uart_receive==0x08)
Flag_Qian=0,Flag_Hou=0,Flag_Left=1,Flag_Right=0;
mode_data[7]=mode_data[6];
mode_data[6]=mode_data[5];
mode_data[5]=mode_data[4];
mode_data[4]=mode_data[3];
mode_data[3]=mode_data[2];
mode_data[2]=mode_data[1];
mode_data[1]=mode_data[0];
if(uart_receive>0x20) TuningPIDdata[0]=uart_receive;
{ if(TuningPIDdata[0]=='+'
&&TuningPIDdata[1]=='B'
&&TuningPIDdata[2]=='A')
{
AngleBias = AngleBias + 0.1;
while((USART3->SR&0X40)==0);
USART3->DR = 'A';
while((USART3->SR&0X40)==0);
USART3->DR = 'n';
while((USART3->SR&0X40)==0);
USART3->DR = 'g';
while((USART3->SR&0X40)==0);
USART3->DR = 'l';
while((USART3->SR&0X40)==0);
USART3->DR = 'e';
while((USART3->SR&0X40)==0);
USART3->DR = 'B';
while((USART3->SR&0X40)==0);
USART3->DR = 'i';
while((USART3->SR&0X40)==0);
USART3->DR = 'a';
while((USART3->SR&0X40)==0);
USART3->DR = 's';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
if(AngleBias<0)
{
while((USART3->SR&0X40)==0);
USART3->DR = '-';
}
while((USART3->SR&0X40)==0);
if(AngleBias<0)
USART3->DR = (int32_t)-AngleBias%10+'0';
else
USART3->DR = (int32_t)AngleBias%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
if(AngleBias<0)
USART3->DR = (uint32_t)(-AngleBias*10)%10+'0';
else
USART3->DR = (uint32_t)(AngleBias*10)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
if(TuningPIDdata[0]=='-'
&&TuningPIDdata[1]=='B'
&&TuningPIDdata[2]=='A')
{
AngleBias = AngleBias - 0.1;
while((USART3->SR&0X40)==0);
USART3->DR = 'A';
while((USART3->SR&0X40)==0);
USART3->DR = 'n';
while((USART3->SR&0X40)==0);
USART3->DR = 'g';
while((USART3->SR&0X40)==0);
USART3->DR = 'l';
while((USART3->SR&0X40)==0);
USART3->DR = 'e';
while((USART3->SR&0X40)==0);
USART3->DR = 'B';
while((USART3->SR&0X40)==0);
USART3->DR = 'i';
while((USART3->SR&0X40)==0);
USART3->DR = 'a';
while((USART3->SR&0X40)==0);
USART3->DR = 's';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
if(AngleBias<0)
{
while((USART3->SR&0X40)==0);
USART3->DR = '-';
}
while((USART3->SR&0X40)==0);
if(AngleBias<0)
USART3->DR = (int32_t)-AngleBias%10+'0';
else
USART3->DR = (int32_t)AngleBias%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
if(AngleBias<0)
USART3->DR = (uint32_t)(-AngleBias*10)%10+'0';
else
USART3->DR = (uint32_t)(AngleBias*10)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
//-------------------------------------------------------------
//Balance PID
//update Balance Kp
if(TuningPIDdata[0]=='+'
&&TuningPIDdata[1]=='p'
&&TuningPIDdata[2]=='B')
{
B_Kp = B_Kp + 0.1;
while((USART3->SR&0X40)==0);
USART3->DR = 'B';
while((USART3->SR&0X40)==0);
USART3->DR = '_';
while((USART3->SR&0X40)==0);
USART3->DR = 'K';
while((USART3->SR&0X40)==0);
USART3->DR = 'p';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
while((USART3->SR&0X40)==0);
USART3->DR = B_Kp/10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (int32_t)B_Kp%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(B_Kp*10)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
if(TuningPIDdata[0]=='-'
&&TuningPIDdata[1]=='p'
&&TuningPIDdata[2]=='B')
{
B_Kp = B_Kp - 0.1;
while((USART3->SR&0X40)==0);
USART3->DR = 'B';
while((USART3->SR&0X40)==0);
USART3->DR = '_';
while((USART3->SR&0X40)==0);
USART3->DR = 'K';
while((USART3->SR&0X40)==0);
USART3->DR = 'p';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
while((USART3->SR&0X40)==0);
USART3->DR = B_Kp/10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (int32_t)B_Kp%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(B_Kp*10)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
//update Balance Ki
if(TuningPIDdata[0]=='+'
&&TuningPIDdata[1]=='i'
&&TuningPIDdata[2]=='B')
{
B_Ki = B_Ki + 0.001;
while((USART3->SR&0X40)==0);
USART3->DR = 'B';
while((USART3->SR&0X40)==0);
USART3->DR = '_';
while((USART3->SR&0X40)==0);
USART3->DR = 'K';
while((USART3->SR&0X40)==0);
USART3->DR = 'i';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
while((USART3->SR&0X40)==0);
USART3->DR = '0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(B_Ki*10)+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(B_Ki*100)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(B_Ki*1000)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
if(TuningPIDdata[0]=='-'
&&TuningPIDdata[1]=='i'
&&TuningPIDdata[2]=='B')
{
B_Ki = B_Ki - 0.001;
while((USART3->SR&0X40)==0);
USART3->DR = 'B';
while((USART3->SR&0X40)==0);
USART3->DR = '_';
while((USART3->SR&0X40)==0);
USART3->DR = 'K';
while((USART3->SR&0X40)==0);
USART3->DR = 'i';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
while((USART3->SR&0X40)==0);
USART3->DR = '0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(B_Ki*10)+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(B_Ki*100)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(B_Ki*1000)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
//update Balance Kd
if(TuningPIDdata[0]=='+'
&&TuningPIDdata[1]=='d'
&&TuningPIDdata[2]=='B')
{
B_Kd = B_Kd + 0.001;
while((USART3->SR&0X40)==0);
USART3->DR = 'B';
while((USART3->SR&0X40)==0);
USART3->DR = '_';
while((USART3->SR&0X40)==0);
USART3->DR = 'K';
while((USART3->SR&0X40)==0);
USART3->DR = 'd';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
while((USART3->SR&0X40)==0);
USART3->DR = '0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(B_Kd*10)+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(B_Kd*100)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(B_Kd*1000)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
if(TuningPIDdata[0]=='-'
&&TuningPIDdata[1]=='d'
&&TuningPIDdata[2]=='B')
{
B_Kd = B_Kd - 0.001;
while((USART3->SR&0X40)==0);
USART3->DR = 'B';
while((USART3->SR&0X40)==0);
USART3->DR = '_';
while((USART3->SR&0X40)==0);
USART3->DR = 'K';
while((USART3->SR&0X40)==0);
USART3->DR = 'd';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
while((USART3->SR&0X40)==0);
USART3->DR = '0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(B_Kd*10)+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(B_Kd*100)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(B_Kd*1000)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
//-------------------------------------------------------------
//Velocity PID
//update Velocity Kp
if(TuningPIDdata[0]=='+'
&&TuningPIDdata[1]=='p'
&&TuningPIDdata[2]=='V')
{
V_Kp = V_Kp + 0.1;
while((USART3->SR&0X40)==0);
USART3->DR = 'V';
while((USART3->SR&0X40)==0);
USART3->DR = '_';
while((USART3->SR&0X40)==0);
USART3->DR = 'K';
while((USART3->SR&0X40)==0);
USART3->DR = 'p';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
while((USART3->SR&0X40)==0);
USART3->DR = V_Kp/10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (int32_t)V_Kp%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(V_Kp*10)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
if(TuningPIDdata[0]=='-'
&&TuningPIDdata[1]=='p'
&&TuningPIDdata[2]=='V')
{
V_Kp = V_Kp - 0.1;
while((USART3->SR&0X40)==0);
USART3->DR = 'V';
while((USART3->SR&0X40)==0);
USART3->DR = '_';
while((USART3->SR&0X40)==0);
USART3->DR = 'K';
while((USART3->SR&0X40)==0);
USART3->DR = 'p';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
while((USART3->SR&0X40)==0);
USART3->DR = V_Kp/10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (int32_t)V_Kp%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(V_Kp*10)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
//update Velocity Ki
if(TuningPIDdata[0]=='+'
&&TuningPIDdata[1]=='i'
&&TuningPIDdata[2]=='V')
{
V_Ki = V_Ki + 0.001;
while((USART3->SR&0X40)==0);
USART3->DR = 'V';
while((USART3->SR&0X40)==0);
USART3->DR = '_';
while((USART3->SR&0X40)==0);
USART3->DR = 'K';
while((USART3->SR&0X40)==0);
USART3->DR = 'i';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
while((USART3->SR&0X40)==0);
USART3->DR = '0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(V_Ki*10)+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(V_Ki*100)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(V_Ki*1000)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
if(TuningPIDdata[0]=='-'
&&TuningPIDdata[1]=='i'
&&TuningPIDdata[2]=='V')
{
V_Ki = V_Ki - 0.001;
while((USART3->SR&0X40)==0);
USART3->DR = 'V';
while((USART3->SR&0X40)==0);
USART3->DR = '_';
while((USART3->SR&0X40)==0);
USART3->DR = 'K';
while((USART3->SR&0X40)==0);
USART3->DR = 'i';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
while((USART3->SR&0X40)==0);
USART3->DR = '0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(V_Ki*10)+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(V_Ki*100)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(V_Ki*1000)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
//-------------------------------------------------------------
//Turn PID
//update Turn Kp
if(TuningPIDdata[0]=='+'
&&TuningPIDdata[1]=='p'
&&TuningPIDdata[2]=='T')
{
T_Kp = T_Kp + 0.1;
while((USART3->SR&0X40)==0);
USART3->DR = 'T';
while((USART3->SR&0X40)==0);
USART3->DR = '_';
while((USART3->SR&0X40)==0);
USART3->DR = 'K';
while((USART3->SR&0X40)==0);
USART3->DR = 'p';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
while((USART3->SR&0X40)==0);
USART3->DR = T_Kp/10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (int32_t)T_Kp%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(T_Kp*10)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
if(TuningPIDdata[0]=='-'
&&TuningPIDdata[1]=='p'
&&TuningPIDdata[2]=='T')
{
T_Kp = T_Kp - 0.1;
while((USART3->SR&0X40)==0);
USART3->DR = 'T';
while((USART3->SR&0X40)==0);
USART3->DR = '_';
while((USART3->SR&0X40)==0);
USART3->DR = 'K';
while((USART3->SR&0X40)==0);
USART3->DR = 'p';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
while((USART3->SR&0X40)==0);
USART3->DR = T_Kp/10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (int32_t)T_Kp%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(T_Kp*10)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
//update Turn Kd
if(TuningPIDdata[0]=='+'
&&TuningPIDdata[1]=='d'
&&TuningPIDdata[2]=='T')
{
T_Kd = T_Kd + 0.001;
while((USART3->SR&0X40)==0);
USART3->DR = 'T';
while((USART3->SR&0X40)==0);
USART3->DR = '_';
while((USART3->SR&0X40)==0);
USART3->DR = 'K';
while((USART3->SR&0X40)==0);
USART3->DR = 'd';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
while((USART3->SR&0X40)==0);
USART3->DR = '0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(T_Kd*10)+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(T_Kd*100)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(T_Kd*1000)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
if(TuningPIDdata[0]=='-'
&&TuningPIDdata[1]=='d'
&&TuningPIDdata[2]=='T')
{
T_Kd = T_Kd - 0.001;
while((USART3->SR&0X40)==0);
USART3->DR = 'T';
while((USART3->SR&0X40)==0);
USART3->DR = '_';
while((USART3->SR&0X40)==0);
USART3->DR = 'K';
while((USART3->SR&0X40)==0);
USART3->DR = 'd';
while((USART3->SR&0X40)==0);
USART3->DR = '=';
while((USART3->SR&0X40)==0);
USART3->DR = '0';
while((USART3->SR&0X40)==0);
USART3->DR = '.';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(T_Kd*10)+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(T_Kd*100)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = (uint32_t)(T_Kd*1000)%10+'0';
while((USART3->SR&0X40)==0);
USART3->DR = '\n';
}
TuningPIDdata[4]=TuningPIDdata[3];
TuningPIDdata[3]=TuningPIDdata[2];
TuningPIDdata[2]=TuningPIDdata[1];
TuningPIDdata[1]=TuningPIDdata[0];
}
}
}
像旁边出现感叹号,删掉分号,即可消失。但是也可以不管。
在未调参数实验前效果如下;
视频地址:http://player.youku.com/player.php/sid/XMTI2ODg1MDUxMg==/v.swf
实验后效果如下;
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |