Skip to content
4rzael edited this page Sep 1, 2017 · 3 revisions

Drone

Role

Let's get to the biggest part : The Drone script. It represents one drone, and contains pretty much everything related to it.

Interface

  • Real Position Marker Prefab : This script shows the real position of the drone by moving a GameObject. This is its prefab.
  • Base Topic : The drone submodule topic in the drones OSC server
  • Id : The drone's ID
  • Radio URI : The drone's radio URI
  • Use As Input : When toggled on, the Unity client cannot send goals to the drone, and its real position is filtered by a low pass filter (Moving Average, at the moment)
  • Position Estimation Low Pass Filter Window Size : The size of the moving average filter's window. Greater values gets a less shaky result but a bigger latency.

Functions

  • OSC - Connect : Asks the drone to connect through OSC
  • OSC - Start Position Sync : Asks the drone to start sending the position of the gameObject as a goal
  • OSC - Stop Position Sync : Asks the drone to stop sending the position of the gameObject as a goal
  • OSC - Reset Kalman Filter : Asks the drone to reset their kalman filters
  • Osc - EMERGENCY : Asks the drone to make an emergency stop

Code

At the script startup, it creates a GameObject used as a real position marker, giving feedback from the drone position in the real world.

On each frame, the script refreshes the drone real position, rotation and battery usage, and sends back its position as a goal if the position sync has started.

This script also gives some functions usable by other scripts to use the crazyflie in more advanced way :

Events :

This scripts exposes some events which can be subscribed to from other scripts.

public event ConnectionEventCallback ConnectionEvent;
public event ConnectionFailedEventCallback ConnectionFailedEvent;
public event DisconnectionEventCallback DisconnectionEvent;
public event LinkQualityEventCallback LinkQualityEvent;
public event PositionEventCallback PositionEvent;
public event RollPitchYawEventCallback RollPitchYawEvent;
public event BatteryEventCallback BatteryEvent;

an usage example would be :

gameObject.GetComponent<Drone>().ConnectionEvent += (Drone drone) => {
  Debug.logFormat("Drone {0} connected", drone.Id);
}

Methods :

  • public void Connect() : Connects the drone.

  • public void Disconnect() : Disconnects the drone.

  • public void StartPositionSync() : Starts sending goals packets from the position of this gameobject. If the gameobject position is (0,0,0), it will be moved to the current drone's real position.

  • public void StopPositionSync() : Stops sending goals packet from the position of this gameobject.

  • public void ResetKalmanFilter() : Resets the kalman filter. Useful if the real position marker cannot seem to be able to converge to its position.

  • public void SendEmergencySignal() : Sends an emergency signal. Cuts the engine and prevent them from firing again.

  • public void AddLog(string logName, IEnumerable<LogVariable> logVariables, int periodMillis, OscManager.OscSubscribeCallback callback = null) : Adds a log to the drone, and optionally subscribe to it.

  • public void SetParam<T>(string paramGroup, string paramName, T value) : Sets a param in the drone.

  • public Vector3 GetRealPosition() : returns the drone real position.

Clone this wiki locally