3-GPS室外定位导航车和底盘通信接口

单片机往外发送的接口

在rosNodeNom.c


void dataPackSend(void)
{       com_x_send_data.x_pos.fv = position_x;//x坐标--->转换为经度E      com_x_send_data.y_pos.fv = position_y;//y坐标--->转换为纬度N坐标系      com_x_send_data.x_v.fv = velocity_linear_x;//x方向速度      com_x_send_data.y_v.fv = velocity_linear_y;//y 方向速度      com_x_send_data.angular_v.fv = velocity_angular;//角速度 绕z轴      com_x_send_data.pose_angular.fv = velocity_angular;//yaw偏航角       com_x_send_data.vr.fv = velocity_linear_r;      com_x_send_data.vl.fv = velocity_linear_l;  USARTzTxBuffer[0] = 0xaa;
    USARTzTxBuffer[1] = 0xaa;

    USARTzTxBuffer[2] = com_x_send_data.x_pos.cv[0];
    USARTzTxBuffer[3] = com_x_send_data.x_pos.cv[1];
    USARTzTxBuffer[4] = com_x_send_data.x_pos.cv[2];
    USARTzTxBuffer[5] = com_x_send_data.x_pos.cv[3];

    USARTzTxBuffer[6] = com_x_send_data.y_pos.cv[0];
    USARTzTxBuffer[7] = com_x_send_data.y_pos.cv[1];
    USARTzTxBuffer[8] = com_x_send_data.y_pos.cv[2];
    USARTzTxBuffer[9] = com_x_send_data.y_pos.cv[3];

    USARTzTxBuffer[10] = com_x_send_data.x_v.cv[0];
    USARTzTxBuffer[11] = com_x_send_data.x_v.cv[1];
    USARTzTxBuffer[12] = com_x_send_data.x_v.cv[2];
    USARTzTxBuffer[13] = com_x_send_data.x_v.cv[3];

    USARTzTxBuffer[14] = com_x_send_data.y_v.cv[0];
    USARTzTxBuffer[15] = com_x_send_data.y_v.cv[1];
    USARTzTxBuffer[16] = com_x_send_data.y_v.cv[2];
    USARTzTxBuffer[17] = com_x_send_data.y_v.cv[3];

    USARTzTxBuffer[18] = com_x_send_data.angular_v.cv[0];
    USARTzTxBuffer[19] = com_x_send_data.angular_v.cv[1];
    USARTzTxBuffer[20] = com_x_send_data.angular_v.cv[2];
    USARTzTxBuffer[21] = com_x_send_data.angular_v.cv[3];

    USARTzTxBuffer[22] = com_x_send_data.pose_angular.cv[0];
    USARTzTxBuffer[23] = com_x_send_data.pose_angular.cv[1];
    USARTzTxBuffer[24] = com_x_send_data.pose_angular.cv[2];
    USARTzTxBuffer[25] = com_x_send_data.pose_angular.cv[3];

    USARTzTxBuffer[26] = USARTzTxBuffer[2]^USARTzTxBuffer[3]^USARTzTxBuffer[4]^USARTzTxBuffer[5]^USARTzTxBuffer[6]^
                                                USARTzTxBuffer[7]^USARTzTxBuffer[8]^USARTzTxBuffer[9]^USARTzTxBuffer[10]^USARTzTxBuffer[11]^
                                                USARTzTxBuffer[12]^USARTzTxBuffer[13]^USARTzTxBuffer[14]^USARTzTxBuffer[15]^USARTzTxBuffer[16]^
                                                USARTzTxBuffer[17]^USARTzTxBuffer[18]^USARTzTxBuffer[19]^USARTzTxBuffer[20]^USARTzTxBuffer[21]^
                                                USARTzTxBuffer[22]^USARTzTxBuffer[23]^USARTzTxBuffer[24]^USARTzTxBuffer[25];

    uart_send(1, USARTzTxBuffer, 27);

}

树莓派下发控制函数


在stm32_Control.c 中(树莓派路径 /home/pi/2navi_app/src ) 


/**********************************************************
 * 数据打包,将获取的cmd_vel信息打包并通过串口发送
 * ********************************************************/
void data_pack(const char * cmd_vel){
    unsigned char i;
    float_union Vx,Vy,Ang_v;

    memcpy(Vx.cvalue,cmd_vel+3,4);
    memcpy(Vy.cvalue,cmd_vel+7,4);
    memcpy(Ang_v.cvalue,cmd_vel+11,4);
    printf("vx speed:%.2f \n",Vx.fvalue);
    printf("ang  speed:%.2f \n",Ang_v.fvalue);
    memset(s_buffer,0,sizeof(s_buffer));
    //数据打包
    s_buffer[0] = 0xff;
    s_buffer[1] = 0xff;
    s_buffer[2] = 15;
    //Vx
    s_buffer[3] = Vx.cvalue[0];
    s_buffer[4] = Vx.cvalue[1];
    s_buffer[5] = Vx.cvalue[2];
    s_buffer[6] = Vx.cvalue[3];
    //Vy
    s_buffer[7] = Vy.cvalue[0];
    s_buffer[8] = Vy.cvalue[1];
    s_buffer[9] = Vy.cvalue[2];
    s_buffer[10] = Vy.cvalue[3];
    //Ang_v
    s_buffer[11] = Ang_v.cvalue[0];
    s_buffer[12] = Ang_v.cvalue[1];
    s_buffer[13] = Ang_v.cvalue[2];
    s_buffer[14] = Ang_v.cvalue[3];
    //CRC
    s_buffer[15] = s_buffer[3]^s_buffer[4]^s_buffer[5]^s_buffer[6]^s_buffer[7]^s_buffer[8]^s_buffer[9]^s_buffer[10]^s_buffer[11]^s_buffer[12]^s_buffer[13]^s_buffer[14];

    write(imu_fd, s_buffer,sBUFFERSIZE);  
}

/**********************************************************
 * 数据打包,将获取的cmd_vel信息打包并通过串口发送
 * ********************************************************/
void cmd_send(const char cmd_v){
    unsigned char i;
    char cmd_vel[16];
    float_union Vx,Vy,Ang_v;
    Vx.fvalue =0;
    Ang_v.fvalue = 0;
    if(cmd_v==1){
      Vx.fvalue = 20;
         Ang_v.fvalue = 0;
        }
   else if(cmd_v == 2){
       Vx.fvalue = -20;
          Ang_v.fvalue = 0;
    }
     else if(cmd_v == 3)
        {
        Vx.fvalue = 0; 
       Ang_v.fvalue = 0.3;
         }
     else if(cmd_v == 4){
       Ang_v.fvalue = -0.3;
         Vx.fvalue = 0; 
        }
   else if(cmd_v == 0){
        Vx.fvalue = 0; 
         Ang_v.fvalue = 0;
          //Ang_v.fvalue = 0;
    }
      Vy.fvalue = 0;

    memset(s_buffer,0,sizeof(s_buffer));
    //数据打包
    s_buffer[0] = 0xff;
    s_buffer[1] = 0xff;
    s_buffer[2] = 15;
    //Vx
    s_buffer[3] = Vx.cvalue[0];
    s_buffer[4] = Vx.cvalue[1];
    s_buffer[5] = Vx.cvalue[2];
    s_buffer[6] = Vx.cvalue[3];
    //Vy
    s_buffer[7] = Vy.cvalue[0];
    s_buffer[8] = Vy.cvalue[1];
    s_buffer[9] = Vy.cvalue[2];
    s_buffer[10] = Vy.cvalue[3];
    //Ang_v
    s_buffer[11] = Ang_v.cvalue[0];
    s_buffer[12] = Ang_v.cvalue[1];
    s_buffer[13] = Ang_v.cvalue[2];
    s_buffer[14] = Ang_v.cvalue[3];
    //CRC
    s_buffer[15] = s_buffer[3]^s_buffer[4]^s_buffer[5]^s_buffer[6]^s_buffer[7]^s_buffer[8]^s_buffer[9]^s_buffer[10]^s_buffer[11]^s_buffer[12]^s_buffer[13]^s_buffer[14];

    write(imu_fd, s_buffer,sBUFFERSIZE);  
}


sitemap