44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
namespace RoboidControl {
|
|
|
|
/// <summary>
|
|
/// A sensor measuring the distance in the forward direction
|
|
/// </summary>
|
|
public class DistanceSensor : Thing {
|
|
/// <summary>
|
|
/// The current measured distance
|
|
/// </summary>
|
|
public float distance = 0;
|
|
|
|
/// <summary>
|
|
/// Constructor for a new distance sensor
|
|
/// </summary>
|
|
/// <param name="participant">The participant for which the sensor is needed</param>
|
|
public DistanceSensor(Participant participant) : base(participant) { }
|
|
/// <summary>
|
|
/// Create a distance sensor with the given ID
|
|
/// </summary>
|
|
/// <param name="participant">The participant for with the sensor is needed</param>
|
|
/// <param name="networkId">The network ID of the sensor</param>
|
|
/// <param name="thingId">The ID of the thing</param>
|
|
public DistanceSensor(Participant participant, byte networkId, byte thingId) : base(participant, networkId, thingId, (byte)Type.TemperatureSensor) {
|
|
}
|
|
|
|
#if UNITY_5_3_OR_NEWER
|
|
/// @copydoc Passer::RoboidControl::Thing::CreateComponent
|
|
public override void CreateComponent() {
|
|
this.component = Unity.DistanceSensor.Create(this);
|
|
this.component.core = this;
|
|
}
|
|
#endif
|
|
/// <summary>
|
|
/// Function to extract the distance received in the binary message
|
|
/// </summary>
|
|
/// <param name="bytes">The byte array</param>
|
|
public override void ProcessBinary(byte[] bytes) {
|
|
byte ix = 0;
|
|
this.distance = LowLevelMessages.ReceiveFloat16(bytes, ref ix);
|
|
}
|
|
|
|
}
|
|
|
|
} |