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
| #include "drv_UWB_LinkTrack.hpp" #include "Commulink.hpp" #include "Basic.hpp" #include "FreeRTOS.h" #include "task.h" #include "SensorsBackend.hpp" #include "MeasurementSystem.hpp"
struct DriverInfo { uint32_t param; Port port; uint32_t sensor_key; };
typedef struct { uint8_t id; uint8_t role; int pos_x:24; int pos_y:24; int pos_z:24; int vel_x:24; int vel_y:24; int vel_z:24; int dis_0:24; int dis_1:24; int dis_2:24; int dis_3:24; int dis_4:24; int dis_5:24; int dis_6:24; int dis_7:24; float imuGyro[3]; float imuAcc[3]; uint8_t reserved1[12]; int16_t angle[3]; float q[4]; uint8_t reserved2[4]; uint32_t localTime; uint32_t systemTime; uint8_t reserved3[1]; uint8_t eop[3]; uint16_t voltage; uint8_t reserved4[5]; }__PACKED _Uwb; static const unsigned char packet_ID[2] = { 0x55 , 0x01 };
static void OpticalFlow_Server(void* pvParameters) { DriverInfo driver_info = *(DriverInfo*)pvParameters; delete (DriverInfo*)pvParameters; _Uwb Uwb; unsigned char rc_counter = 0; signed char sum = 0; while( get_Altitude_MSStatus() != MS_Ready ) os_delay(1); double angleOffset = 0; if( driver_info.param>360 ) { Quaternion quat; get_Attitude_quat(&quat); angleOffset = quat.getYaw(); } else angleOffset = degree2rad((double)driver_info.param); uint32_t sensor_key = PositionSlamSensorRegister( default_uwb_sensor_index , \ "UWB_LinkTrack" ,\ Position_Sensor_Type_RelativePositioning , \ Position_Sensor_DataType_s_xy , \ Position_Sensor_frame_SLAM , \ 0.1, angleOffset, 100 ); int lastP = 0; uint8_t pUCCounter = 0; while(1) { uint8_t rdata; if( driver_info.port.read( &rdata, 1, 2, 0.5 ) ) { if( rc_counter < sizeof(packet_ID) ) { if( rdata != packet_ID[ rc_counter ] ) { rc_counter = 0; sum = 0; } else { ++rc_counter; sum += rdata; } } else if( rc_counter < sizeof(packet_ID) + sizeof(_Uwb) ) { ( (unsigned char*)&Uwb )[ rc_counter - sizeof(packet_ID) ] = rdata; sum += rdata; ++rc_counter; } else { if( sum == rdata ) { if( Uwb.eop[0]>200 || Uwb.eop[1]>200 ) PositionSensorSetInavailable(default_uwb_sensor_index,driver_info.sensor_key); else { vector3<double> pos, vel; pos.x = Uwb.pos_x*0.1; pos.y = Uwb.pos_y*0.1; pos.z = Uwb.pos_z * 0.1; vel.x = Uwb.vel_x*0.01; vel.y = Uwb.vel_y*0.01; vel.z = Uwb.vel_z * 0.01; if( Uwb.eop[2] > 200 ) PositionSensorChangeDataType( default_uwb_sensor_index,sensor_key, Position_Sensor_DataType_s_xy ); else PositionSensorChangeDataType( default_uwb_sensor_index,sensor_key, Position_Sensor_DataType_s_xyz ); double eop_xy = sqrtf( Uwb.eop[0]*Uwb.eop[0] + Uwb.eop[1]*Uwb.eop[1] ); if( Uwb.dis_0 != lastP ) { lastP = Uwb.dis_0; pUCCounter = 0; } else { if( pUCCounter < 255 ) ++pUCCounter; } if( pUCCounter>100 ) PositionSensorSetInavailable( default_uwb_sensor_index,sensor_key ); else PositionSensorUpdatePosition( default_uwb_sensor_index,sensor_key, pos, true, -1, eop_xy<100?100:eop_xy, Uwb.eop[2] ); } } rc_counter = 0; sum = 0; } } } }
static bool UWB_LinkTrack_DriverInit( Port port, uint32_t param ) { port.SetBaudRate( 460800, 2, 2 ); DriverInfo* driver_info = new DriverInfo; driver_info->param = param; driver_info->port = port; xTaskCreate( OpticalFlow_Server, "OptFlowGL9306", 1024, (void*)driver_info, SysPriority_ExtSensor, NULL); return true; }
void init_drv_UWB_LinkTrack() { PortFunc_Register( 41, UWB_LinkTrack_DriverInit ); }
|