Skip to content

add func to check drone connection status #137

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Assets/Scripts/Drone Scripts/DroneMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class DroneMenu : MonoBehaviour {
private Dictionary<Text, string> infoTextsDict; // Holds all Text boxes and their topic names
private bool initialized;
private Transform headsetTransform;
private bool connection_status;

/// <summary>
/// Creates text box for each subscriber and properly displays them above the drone.
Expand Down Expand Up @@ -118,6 +119,9 @@ void Update() {
// canvas LookAt code is funky. Credit: https://answers.unity.com/questions/132592/lookat-in-opposite-direction.html
menuCanvas.transform.LookAt(2 * menuCanvas.transform.position - targetPosition);
}

connection_status = connection.CheckConnectionStatus();
//TODO: change drone info UI to indicate connection status!
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ public bool sdk_ready
/// </summary>
bool home_position_set = false;

double prev_gps_msg_time = -1;
//double curr_gps_msg_time = -1;
bool connection_status = false;

/// <summary>
/// Function called by ROSManager when Drone Gameobject is initilized to start the ROS connection with requested subscribers.
/// </summary>
Expand Down Expand Up @@ -865,6 +869,7 @@ public ROSBridgeMsg OnReceiveMessage(string topic, JSONNode raw_msg, ROSBridgeMs
case "/dji_sdk/gps_position":
case "/dji_sdk/rtk_position":
gps_position = (parsed == null) ? new NavSatFixMsg(raw_msg) : (NavSatFixMsg)parsed;
prev_gps_msg_time = DateTime.Now.TimeOfDay.TotalMilliseconds;
result = gps_position;
if (gps_position.GetLatitude() == 0.0f && gps_position.GetLongitude() == 0.0f)
{
Expand Down Expand Up @@ -897,6 +902,17 @@ public ROSBridgeMsg OnReceiveMessage(string topic, JSONNode raw_msg, ROSBridgeMs
return result;
}

//int prev_gps_timestamp;
//int curr_gps_timestamp;
public bool CheckConnectionStatus()
{
if (prev_gps_msg_time > -1)
{
return DateTime.Now.TimeOfDay.TotalMilliseconds - prev_gps_msg_time < 500;
}
return false;

}
/// <summary>
/// Get ROS message type for a valid topic.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,16 @@ public interface ROSDroneConnectionInterface
/// </summary>
void DisconnectROSConnection();

/// <summary>
/// Checks whether new GPS messages are bring receivied i.e. connection status is good
/// </summary>
bool CheckConnectionStatus();

// Optional in the future
// void DoTask()



}

public interface ROSSensorConnectionInterface
Expand Down