無人機《iGCS》學習

項目《iGCS》

項目架構

項目架構
架構圖

主控制器 MainViewController

  • 繼承自UITabBarController,有三個子控制器
    SWRevealViewController是第三方庫 側滑效果
    WaypointsViewController ---飛行路線設置
    CommsViewController ---飛機狀態(tài)
  • SWRevealViewController 有兩個自控制器
    GCSMapViewController ----主界面
    GCSSidebarController ---側滑界面
  • MainViewController.m中兩個重要方法
// 處理消息
- (void) handlePacket:(mavlink_message_t*)msg {
    [self.gcsMapVC handlePacket:msg];
    [self.gcsSidebarVC handlePacket:msg];
    [self.waypointVC handlePacket:msg];
    
#ifdef DEBUG
    [self.commsVC  handlePacket:msg];
#endif
}

- (void) replaceMission:(WaypointsHolder*)mission {
    [self.gcsMapVC   replaceMission:mission];
    [self.waypointVC replaceMission:mission];
}

MainViewController遵守了MavLinkPacketHandler協(xié)議
其代理方法
- (void) handlePacket:(mavlink_message_t*)msg;
MavLinkPacketHandler定義在 MavLinkPacketHandler.h文件中 只有一個聲明文件 在其遵守協(xié)議控制器中實現其方法

MavLinkPacketHandler
  • MainViewController- (void) handlePacket:(mavlink_message_t*)msg方法中其子控制器都遵守MavLinkPacketHandler協(xié)議禽捆,分別執(zhí)行其代理方法

一個個來看

  • [self.gcsMapVC handlePacket:msg];GCSMapViewController 實現
/**
 處理消息
 此控制器事主界面 根據接收到的消息 判斷消息的msgid 來判斷消息類型  根據不同的類型 更新相應信息
 
消息的處理 第三方庫里已經封裝好了
判斷出相應類型的消息  只需調用相應消息的decode方法
傳入 msg 和 消息結構體指針呼股,就會返回相應解析的消息

 @param msg 消息
 */


- (void) handlePacket:(mavlink_message_t*)msg {
    
    switch (msg->msgid) {
        /*
        // Temporarily disabled in favour of MAVLINK_MSG_ID_GPS_RAW_INT
        // GPS定位信息
        case MAVLINK_MSG_ID_GLOBAL_POSITION_INT: {
            mavlink_global_position_int_t gpsPosIntPkt;
            mavlink_msg_global_position_int_decode(msg, &gpsPosIntPkt);
            
            CLLocationCoordinate2D pos = CLLocationCoordinate2DMake(gpsPosIntPkt.lat/10000000.0, gpsPosIntPkt.lon/10000000.0);
            [uavPos setCoordinate:pos];
            [self addToTrack:pos];
        }
        break;
        */
        
        // 消息類型
        
        /*
         
         The global position, as returned by the Global PositioningSystem (GPS). This is NOT the global position estimate of the system, butrather a RAW sensor value. See message GLOBAL_POSITION for the global positionestimate. Coordinate frame is right-handed, Z-axis up (GPS frame)
         全球定位吨拍,并非系統(tǒng)估計位置统翩,而是RAW傳感器值掐禁。(Raw Sensor 原始傳感器未玻?)——右手坐標系,Z軸向上忍坷。
         time_usec:時間戳粘舟,單位為microseconds微秒熔脂。
         Lat:Latitude (WGS84), in degrees * 1E7佩研,緯度,單位為度數*10的7次方霞揉。
         Lon:Longitude (WGS84), in degrees * 1E7旬薯,經度,單位為度數*10的7次方适秩。
         alt:Altitude (AMSL, NOT WGS84), in meters * 1000 (positive for up).Note that virtually all GPS modules provide the AMSL altitude     in addition to the WGS84 altitude.高度绊序,單位為km,向上為正秽荞。注意所有GPS模塊除了WGS84高度以外骤公,均提供AMSL(平均海平面以上)高  度。
         Eph:GPS HDOP (horizontal dilution of position) in cm (m*100). If unknown, set to: UINT16_MAX扬跋,GPS水平精度因子阶捆,單位為厘米。
         Epv: GPS VDOP vertical dilution of position in cm (m*100). Ifunknown, set to: UINT16_MAX钦听,GPS垂直精度因子洒试,單位為厘米。
         Vel: GPS ground speed (m/s * 100). If unknown, set to: UINT16_MAX朴上,全球定位系統(tǒng)地速度垒棋,單位為百米每秒。
         Cog:Course over ground (NOT heading, but direction of movement) indegrees * 100, 0.0..359.99 degrees. If unknown, set to: UINT16_MAX
         實際航跡向痪宰,單位為百分之一度叼架。
         fix_type:0-1: no fix, 2: 2D fix, 3: 3D fix, 4: DGPS, 5: RTK.GPS修正類型畔裕。
         satellites_visible:衛(wèi)星可見數,未知則填寫255乖订。
         
         */
        case MAVLINK_MSG_ID_GPS_RAW_INT: {
            mavlink_gps_raw_int_t gpsRawIntPkt;
            mavlink_msg_gps_raw_int_decode(msg, &gpsRawIntPkt);
            
            CLLocationCoordinate2D pos = CLLocationCoordinate2DMake(gpsRawIntPkt.lat/10000000.0, gpsRawIntPkt.lon/10000000.0);
            [self.uavPos setCoordinate:pos];
            [self addToTrack:pos];
        }
        break;
            
        // 姿態(tài) Attitude狀態(tài)報告柴钻,包括滾轉角、偏航角垢粮、俯仰角(及其速度)等信息贴届。
        case MAVLINK_MSG_ID_ATTITUDE: {
            mavlink_attitude_t attitudePkt;
            mavlink_msg_attitude_decode(msg, &attitudePkt);
            
            [self.ahIndicatorView setRoll:-attitudePkt.roll pitch:attitudePkt.pitch];
            [self.ahIndicatorView requestRedraw];
        }
        break;

        // 平視顯示器數據 Head Up Display
        case MAVLINK_MSG_ID_VFR_HUD: {
            mavlink_vfr_hud_t  vfrHudPkt;
            mavlink_msg_vfr_hud_decode(msg, &vfrHudPkt);
            
            self.uavView.image = [GCSMapViewController uavIconForCraft:[GCSDataManager sharedInstance].craft
                                                               withYaw:vfrHudPkt.heading * DEG2RAD];
            
            [self.compassView setHeading:vfrHudPkt.heading];
            [self.airspeedView setValue:vfrHudPkt.airspeed]; // m/s
            [self.altitudeView setValue:vfrHudPkt.alt];      // m

            [self.compassView  requestRedraw];
            [self.airspeedView requestRedraw];
            [self.altitudeView requestRedraw];
        }
        break;
       
        /*
         
         Outputs of the APM navigation controller. The primary use ofthis message is to check the response and signs of the controller before actualflight and to assist with tuning controller parameters.
         APM導航控制器的輸出,該信息主要功能為檢查實飛前控制器的回復和信號蜡吧,輔助調整控制參數毫蚓。
         nav_roll:當前所需的滾轉角
         ……
         alt_error:高度誤差
         aspd_error:當前空速誤差 m/s
         xtrack_erro:Current crosstrack error on x-y plane in meters.當前x-y平面橫向軌跡誤差  單位m
         nav_bearing:Current desired heading in degrees.當前任務/目標方位單位度
         target_bearing:Bearing to current MISSION/target in degrees.當前任務/目標方位單位度
         wp_dist:Distance to active MISSION in meters就,至當前任務點的距離昔善,單位為m
         共有 147 字節(jié)
         
         */
        case MAVLINK_MSG_ID_NAV_CONTROLLER_OUTPUT: {
            mavlink_nav_controller_output_t navCtrlOutPkt;
            mavlink_msg_nav_controller_output_decode(msg, &navCtrlOutPkt);
            
            [self.compassView setNavBearing:navCtrlOutPkt.nav_bearing];
            [self.airspeedView setTargetDelta:navCtrlOutPkt.aspd_error]; // m/s
            [self.altitudeView setTargetDelta:navCtrlOutPkt.alt_error];  // m
        }
        break;
        
        // 聲明當前活動任務項的序列號
        case MAVLINK_MSG_ID_MISSION_CURRENT: {
            mavlink_mission_current_t currentWaypoint;
            mavlink_msg_mission_current_decode(msg, &currentWaypoint);
            [self maybeUpdateCurrentWaypoint:currentWaypoint.seq];
        }
        break;
            
            
        /*
         常規(guī)系統(tǒng)狀態(tài)信息
         onboard_control_sensors_present:以位掩碼表示控制器及傳感器的存在狀態(tài)元潘,16776207(十進制)= 111111111111110000001111(二進制)
         onboard_control_sensors_enabled:以位掩碼表示控制器及傳感器的啟用狀態(tài),16751631(十進制)= 111111111001110000001111(二進制)
         onboard_control_sensors_health:以位掩碼表示控制器及傳感器處于可用狀態(tài)還是存在錯誤君仆。轉換為二進制同上翩概。
         以上掩碼信息中,第一位表示gyro陀螺儀返咱,第二位表示accelerometer加速度計钥庇,第六位表示GPS……詳情見MAV_SYS_STATUS文件。
         Load: Maximum usage in percent of the mainloop time,主循環(huán)內時間的最大使用比例咖摹,1000表示100%评姨,該值應保持小于1000。
         voltage_battery:電池電壓萤晴,單位毫伏特吐句。
         current_battery:當前電池(電流),單位毫安店读。-1表示飛控未測量嗦枢。
         drop_rate_comm:通信丟失百分比,1000表示100%屯断。
         errors_comm:通信錯誤 (UART, I2C, SPI, CAN)文虏,丟包。
         Errors_countX:Autopilot-specific errors,飛控特定錯誤裹纳,未知含義择葡。
         battery_remaining:剩余電量,1表示1%剃氧,-1:autopilot estimate the remainingbattery敏储,飛控估計電量
         */
        case MAVLINK_MSG_ID_SYS_STATUS: {
            mavlink_sys_status_t sysStatus;
            mavlink_msg_sys_status_decode(msg, &sysStatus);
            [self.voltageLabel setText:[NSString stringWithFormat:@"%0.1fV", sysStatus.voltage_battery/1000.0f]];
            [self.currentLabel setText:[NSString stringWithFormat:@"%0.1fA", sysStatus.current_battery/100.0f]];
        }
        break;

        case MAVLINK_MSG_ID_WIND: {
            mavlink_wind_t wind;
            mavlink_msg_wind_decode(msg, &wind);
            _windIconView.transform = CGAffineTransformMakeRotation(((360 + (NSInteger)wind.direction + WIND_ICON_OFFSET_ANG) % 360) * M_PI/180.0f);
        }
        break;
            
        case MAVLINK_MSG_ID_HEARTBEAT: {
            mavlink_heartbeat_t heartbeat;
            mavlink_msg_heartbeat_decode(msg, &heartbeat);
            
            // We got a heartbeat, so...
            [self rescheduleHeartbeatLossCheck];

            // Mutate existing craft, or replace if required (e.g. type has changed)
            [GCSDataManager sharedInstance].craft = [GCSCraftModelGenerator updateOrReplaceModel:[GCSDataManager sharedInstance].craft
                                                                                     withCurrent:heartbeat];

            // Update segmented control
            NSInteger idx = CONTROL_MODE_RC;
            if ([GCSDataManager sharedInstance].craft.isInAutoMode) {
                idx = CONTROL_MODE_AUTO;
            } else if ([GCSDataManager sharedInstance].craft.isInGuidedMode) {
                idx = CONTROL_MODE_GUIDED;
            }
            
            // Change the segmented control to reflect the heartbeat
            if (idx != self.controlModeSegment.selectedSegmentIndex) {
                self.controlModeSegment.selectedSegmentIndex = idx;
            }
            
            // If the current mode is not a GUIDED mode, and has just changed
            //   - unconditionally switch out of Follow Me mode
            //   - clear the guided position annotation markers
            if (![GCSDataManager sharedInstance].craft.isInGuidedMode && heartbeat.custom_mode != _lastCustomMode) {
                [self deactivateFollowMe];
                [self clearGuidedPositions];
            }
            _lastCustomMode = heartbeat.custom_mode;
        }
        break;
    }
}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市朋鞍,隨后出現的幾起案子已添,更是在濱河造成了極大的恐慌妥箕,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,590評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件更舞,死亡現場離奇詭異畦幢,居然都是意外死亡,警方通過查閱死者的電腦和手機缆蝉,發(fā)現死者居然都...
    沈念sama閱讀 95,157評論 3 399
  • 文/潘曉璐 我一進店門宇葱,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人刊头,你說我怎么就攤上這事黍瞧。” “怎么了原杂?”我有些...
    開封第一講書人閱讀 169,301評論 0 362
  • 文/不壞的土叔 我叫張陵印颤,是天一觀的道長。 經常有香客問我穿肄,道長年局,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 60,078評論 1 300
  • 正文 為了忘掉前任咸产,我火速辦了婚禮矢否,結果婚禮上,老公的妹妹穿的比我還像新娘锐朴。我一直安慰自己兴喂,他們只是感情好蔼囊,可當我...
    茶點故事閱讀 69,082評論 6 398
  • 文/花漫 我一把揭開白布焚志。 她就那樣靜靜地躺著,像睡著了一般畏鼓。 火紅的嫁衣襯著肌膚如雪酱酬。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,682評論 1 312
  • 那天云矫,我揣著相機與錄音膳沽,去河邊找鬼。 笑死让禀,一個胖子當著我的面吹牛挑社,可吹牛的內容都是我干的。 我是一名探鬼主播巡揍,決...
    沈念sama閱讀 41,155評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼痛阻,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了腮敌?” 一聲冷哼從身側響起阱当,我...
    開封第一講書人閱讀 40,098評論 0 277
  • 序言:老撾萬榮一對情侶失蹤俏扩,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后弊添,有當地人在樹林里發(fā)現了一具尸體录淡,經...
    沈念sama閱讀 46,638評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 38,701評論 3 342
  • 正文 我和宋清朗相戀三年油坝,在試婚紗的時候發(fā)現自己被綠了嫉戚。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,852評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡澈圈,死狀恐怖彼水,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情极舔,我是刑警寧澤凤覆,帶...
    沈念sama閱讀 36,520評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站拆魏,受9級特大地震影響盯桦,放射性物質發(fā)生泄漏。R本人自食惡果不足惜渤刃,卻給世界環(huán)境...
    茶點故事閱讀 42,181評論 3 335
  • 文/蒙蒙 一拥峦、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧卖子,春花似錦略号、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,674評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至诫舅,卻和暖如春羽利,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背刊懈。 一陣腳步聲響...
    開封第一講書人閱讀 33,788評論 1 274
  • 我被黑心中介騙來泰國打工这弧, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人虚汛。 一個月前我還...
    沈念sama閱讀 49,279評論 3 379
  • 正文 我出身青樓匾浪,卻偏偏與公主長得像,于是被迫代替她去往敵國和親卷哩。 傳聞我的和親對象是個殘疾皇子枫绅,可洞房花燭夜當晚...
    茶點故事閱讀 45,851評論 2 361

推薦閱讀更多精彩內容

  • Spring Cloud為開發(fā)人員提供了快速構建分布式系統(tǒng)中一些常見模式的工具(例如配置管理堡赔,服務發(fā)現羽圃,斷路器,智...
    卡卡羅2017閱讀 134,715評論 18 139
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,321評論 25 707
  • 轉至元數據結尾創(chuàng)建: 董瀟偉捌年,最新修改于: 十二月 23, 2016 轉至元數據起始第一章:isa和Class一....
    40c0490e5268閱讀 1,732評論 0 9
  • 1,NSObject中description屬性的意義挂洛,它可以重寫嗎?答案:每當 NSLog(@"")函數中出現 ...
    eightzg閱讀 4,150評論 2 19
  • “In me the tiger sniffs the rose.”心有猛虎礼预,細嗅薔薇。英國詩人西格夫里·薩...
    Miss伊柚閱讀 397評論 0 0