下面列出圆点博士小四轴所支持的通讯命令的源代码。 if((anbt_com_command_HH=='R')&&(anbt_com_command_HL=='C')) anbt_com_command_ops=0xA0; //remote ctrol
else if((anbt_com_command_HH=='B')&&(anbt_com_command_HL=='A')&&(anbt_com_command_LH=='T')) anbt_com_command_ops=0xA1; //read voltage
else if((anbt_com_command_HH=='V')&&(anbt_com_command_HL=='E')&&(anbt_com_command_LH=='R')) anbt_com_command_ops=0xA2; //return version
else if((anbt_com_command_HH=='C')&&(anbt_com_command_HL=='T')&&(anbt_com_command_LH=='R')&&(anbt_com_command_LL=='L')) anbt_com_command_ops=0xA3; //read PI data
else if((anbt_com_command_HH=='P')&&(anbt_com_command_HL=='A')&&(anbt_com_command_LH=='L')&&(anbt_com_command_LL=='L')) anbt_com_command_ops=0xA4; //read PI data
else if((anbt_com_command_HH=='I')&&(anbt_com_command_HL=='A')&&(anbt_com_command_LH=='L')&&(anbt_com_command_LL=='L')) anbt_com_command_ops=0xA5; //read PI data
else if((anbt_com_command_HH=='W')&&(anbt_com_command_HL=='R')&&(anbt_com_command_LH=='P')&&(anbt_com_command_LL=='X')) anbt_com_command_ops=0xA6; //write PX
else if((anbt_com_command_HH=='W')&&(anbt_com_command_HL=='R')&&(anbt_com_command_LH=='P')&&(anbt_com_command_LL=='Y')) anbt_com_command_ops=0xA7; //write PY
else if((anbt_com_command_HH=='W')&&(anbt_com_command_HL=='R')&&(anbt_com_command_LH=='P')&&(anbt_com_command_LL=='Z')) anbt_com_command_ops=0xA8; //write PZ
else if((anbt_com_command_HH=='W')&&(anbt_com_command_HL=='R')&&(anbt_com_command_LH=='I')&&(anbt_com_command_LL=='X')) anbt_com_command_ops=0xA9; //write IX
else if((anbt_com_command_HH=='W')&&(anbt_com_command_HL=='R')&&(anbt_com_command_LH=='I')&&(anbt_com_command_LL=='Y')) anbt_com_command_ops=0xAA; //write IY
else if((anbt_com_command_HH=='W')&&(anbt_com_command_HL=='R')&&(anbt_com_command_LH=='I')&&(anbt_com_command_LL=='Z')) anbt_com_command_ops=0xAB; //write IZ
else if((anbt_com_command_HH=='P')&&(anbt_com_command_HL=='W')&&(anbt_com_command_LH=='O')&&(anbt_com_command_LL=='N')) anbt_com_command_ops=0xAC; //motor pwm on
else if((anbt_com_command_HH=='P')&&(anbt_com_command_HL=='W')&&(anbt_com_command_LH=='O')&&(anbt_com_command_LL=='F')) anbt_com_command_ops=0xAD; //motor pwm on
else anbt_com_command_ops=0;
命令相应一:返回电池电压值。 if(anbt_com_command_ops==0xA1) //圆点博士:返回电池电压,注意,如果电机电源没开,将返回0
{
BS004_COM1_Send_Str_Head();
BS004_COM1_Send_Str_Body("read bat voltage .");
BS004_COM1_Send_4bits_BCD_Num(bs004_bat_value);
BS004_COM1_Send_Str_Tail();
} 命令相应二:返回版本号。 else if(anbt_com_command_ops==0xA2) //圆点博士:返回版本号
{
BS004_COM1_Send_Str_Head();
BS004_COM1_Send_Str_Body("version 10.");
BS004_COM1_Send_Str_Tail();
} 命令相应三:返回接收到的最后一次遥控器指令。包括油门数据,俯昂角度,滚动角度,和航向 else if(anbt_com_command_ops==0xA3) //圆点博士:返回遥控器数据
{
BS004_COM1_Send_Str_Head();
BS004_COM1_Send_Str_Body("read remote control data .");
//
BS004_COM1_Send_4bits_BCD_Num(BS004_Ctrl_Gas);
BS004_COM1_Send_Char(',');
BS004_COM1_Send_4bits_BCD_Num(BS004_Ctrl_Pitch);
BS004_COM1_Send_Char(',');
BS004_COM1_Send_4bits_BCD_Num(BS004_Ctrl_Roll);
BS004_COM1_Send_Char(',');
BS004_COM1_Send_4bits_BCD_Num(BS004_Ctrl_Yaw);
//
BS004_COM1_Send_Str_Tail();
}
命令响应四:返回PID参数中各个轴的P值 else if(anbt_com_command_ops==0xA4) //圆点博士:返回P值
{
BS004_COM1_Send_Str_Head();
BS004_COM1_Send_Str_Body("read All P data .");
//
for(i=0;i<3;i++)
{
BS004_COM1_Send_4bits_BCD_Num(pid_setting_P_value);
BS004_COM1_Send_Char(',');
}
//
BS004_COM1_Send_Str_Tail();
} 命令响应五:返回PID参数中各个轴的I值 else if(anbt_com_command_ops==0xA5) //圆点博士:返回I值
{
BS004_COM1_Send_Str_Head();
BS004_COM1_Send_Str_Body("read All I data .");
//
for(i=0;i<3;i++)
{
BS004_COM1_Send_4bits_BCD_Num(pid_setting_I_value);
BS004_COM1_Send_Char(',');
}
//
BS004_COM1_Send_Str_Tail();
} 命令响应六:设置X轴P值 else if(anbt_com_command_ops==0xA6) //圆点博士:设置X轴P值
{
BS004_COM1_Send_Str_Head();
BS004_COM1_Send_Str_Body("write PX data .");
//
if(pid_data_buffer_valid==1)
{
pid_setting_P_value[0]=pid_data_buffer;
pid_data_buffer_valid=0;
}
//
BS004_COM1_Send_4bits_BCD_Num(pid_data_buffer);
BS004_COM1_Send_Str_Tail();
} 命令响应七:设置Y轴P值 else if(anbt_com_command_ops==0xA7) //圆点博士:设置Y轴P值
{
BS004_COM1_Send_Str_Head();
BS004_COM1_Send_Str_Body("write PY data .");
//
if(pid_data_buffer_valid==1)
{
pid_setting_P_value[1]=pid_data_buffer;
pid_data_buffer_valid=0;
}
//
BS004_COM1_Send_4bits_BCD_Num(pid_data_buffer);
BS004_COM1_Send_Str_Tail();
} 命令响应八:设置Z轴P值 else if(anbt_com_command_ops==0xA8) //圆点博士:设置Z轴P值
{
BS004_COM1_Send_Str_Head();
BS004_COM1_Send_Str_Body("write PZ data .");
//
if(pid_data_buffer_valid==1)
{
pid_setting_P_value[2]=pid_data_buffer;
pid_data_buffer_valid=0;
}
//
BS004_COM1_Send_4bits_BCD_Num(pid_data_buffer);
BS004_COM1_Send_Str_Tail();
命令相应九:设置X轴I值 else if(anbt_com_command_ops==0xA9) //圆点博士:设置X轴I值
{
BS004_COM1_Send_Str_Head();
BS004_COM1_Send_Str_Body("write IX data .");
//
if(pid_data_buffer_valid==1)
{
pid_setting_I_value[0]=pid_data_buffer;
pid_data_buffer_valid=0;
}
//
BS004_COM1_Send_4bits_BCD_Num(pid_data_buffer);
BS004_COM1_Send_Str_Tail();
} 命令相应十:设置Y轴I值 else if(anbt_com_command_ops==0xAA) //圆点博士:设置Y轴I值
{
BS004_COM1_Send_Str_Head();
BS004_COM1_Send_Str_Body("write IY data .");
//
if(pid_data_buffer_valid==1)
{
pid_setting_I_value[1]=pid_data_buffer;;
pid_data_buffer_valid=0;
}
//
BS004_COM1_Send_4bits_BCD_Num(pid_data_buffer);
BS004_COM1_Send_Str_Tail();
} 命令相应十一:设置Z轴I值 else if(anbt_com_command_ops==0xAB) //圆点博士:设置Z轴I值
{
BS004_COM1_Send_Str_Head();
BS004_COM1_Send_Str_Body("write IZ data .");
//
if(pid_data_buffer_valid==1)
{
pid_setting_I_value[2]=pid_data_buffer;
pid_data_buffer_valid=0;
}
//
BS004_COM1_Send_4bits_BCD_Num(pid_data_buffer);
BS004_COM1_Send_Str_Tail();
}
下面命令用于电机电源的开启或者关闭。
else if(anbt_com_command_ops==0xAC) //圆点博士:打开电机电源
{
BS004_COM1_Send_Str_Head();
BS004_COM1_Send_Str_Body("motor power on.");
BS004_COM1_Send_Str_Tail();
//
BS004_Motor_Power_On();
}
//
else if(anbt_com_command_ops==0xAD) //圆点博士:关闭电机电源
{
BS004_COM1_Send_Str_Head();
BS004_COM1_Send_Str_Body("motor power off.");
BS004_COM1_Send_Str_Tail();
//
BS004_Motor_Power_Off();
}
|