UASWaypointManager.cc 3.25 KB
Newer Older
1 2 3 4
#include "UASWaypointManager.h"
#include "UAS.h"

UASWaypointManager::UASWaypointManager(UAS &_uas)
pixhawk's avatar
pixhawk committed
5 6 7 8 9 10
        : uas(_uas),
        current_wp_id(0),
        current_count(0),
        current_state(WP_IDLE),
        current_partner_systemid(0),
        current_partner_compid(0)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
{
}

void UASWaypointManager::waypointChanged(Waypoint*)
{
}

void UASWaypointManager::currentWaypointChanged(int)
{
}

void UASWaypointManager::removeWaypointId(int)
{
}

void UASWaypointManager::requestWaypoints()
{
    if(current_state == WP_IDLE)
    {
pixhawk's avatar
pixhawk committed
30
        qDebug() << "handleWaypointCount";
31 32 33 34
        mavlink_message_t message;
        mavlink_waypoint_request_list_t wprl;

        wprl.target_system = uas.getUASID();
pixhawk's avatar
pixhawk committed
35
        wprl.target_component = MAV_COMP_ID_WAYPOINTPLANNER;
36 37 38 39 40 41

        current_state = WP_GETLIST;
        current_wp_id = 0;
        current_partner_systemid = uas.getUASID();
        current_partner_compid = MAV_COMP_ID_WAYPOINTPLANNER;

pixhawk's avatar
pixhawk committed
42
        mavlink_msg_waypoint_request_list_encode(uas.mavlink->getSystemId(), uas.mavlink->getComponentId(), &message, &wprl);
43 44 45 46 47 48 49 50
        uas.sendMessage(message);
    }
}

void UASWaypointManager::handleWaypointCount(quint8 systemId, quint8 compId, quint16 count)
{
    if (current_state == WP_GETLIST && systemId == current_partner_systemid && compId == current_partner_compid)
    {
pixhawk's avatar
pixhawk committed
51 52
        qDebug() << "handleWaypointCount";

53 54 55 56 57 58
        current_count = count;

        mavlink_message_t message;
        mavlink_waypoint_request_t wpr;

        wpr.target_system = uas.getUASID();
pixhawk's avatar
pixhawk committed
59 60
        wpr.target_component = MAV_COMP_ID_WAYPOINTPLANNER;
        wpr.seq = 0;
61

pixhawk's avatar
pixhawk committed
62
        current_wp_id = 0;
63 64
        current_state = WP_GETLIST_GETWPS;

pixhawk's avatar
pixhawk committed
65
        mavlink_msg_waypoint_request_encode(uas.mavlink->getSystemId(), uas.mavlink->getComponentId(), &message, &wpr);
66 67 68 69
        uas.sendMessage(message);
    }
}

pixhawk's avatar
pixhawk committed
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
void UASWaypointManager::handleWaypoint(quint8 systemId, quint8 compId, mavlink_waypoint_t *wp)
{
    if (systemId == current_partner_systemid && compId == current_partner_compid && current_state == WP_GETLIST_GETWPS && wp->seq == current_wp_id)
    {
        qDebug() << "handleWaypoint";

        if(wp->seq == current_wp_id)
        {
            //update the UI FIXME
            emit waypointUpdated(uas.getUASID(), wp->seq, wp->x, wp->y, wp->z, wp->yaw, wp->autocontinue, wp->current);

            //get next waypoint
            current_wp_id++;

            if(current_wp_id < current_count)
            {
                mavlink_message_t message;
                mavlink_waypoint_request_t wpr;

                wpr.target_system = uas.getUASID();
                wpr.target_component = MAV_COMP_ID_WAYPOINTPLANNER;
                wpr.seq = current_wp_id;

                mavlink_msg_waypoint_request_encode(uas.mavlink->getSystemId(), uas.mavlink->getComponentId(), &message, &wpr);
                uas.sendMessage(message);
            }
            else
            {
                current_state = WP_IDLE;
                current_count = 0;
                current_wp_id = 0;
                current_partner_systemid = 0;
                current_partner_compid = 0;
            }
        }
        else
        {
            //FIXME error handling
        }
    }
}

112 113 114 115 116 117 118 119
void UASWaypointManager::getWaypoint(quint16 seq)
{

}

void UASWaypointManager::clearWaypointList()
{
}