Skip to content

Commit

Permalink
clad 2.1.0 sdk update (#5)
Browse files Browse the repository at this point in the history
Updated for use with clad 2.1.0
      - All robotIds removed from actions and connections
      - Connection satisfied with RobotState, rather than checking for robotId
  • Loading branch information
ankiNicolas authored Dec 6, 2017
1 parent ee385ba commit 239d1fd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
Binary file modified clad_library/CladCSharp.dll
Binary file not shown.
8 changes: 3 additions & 5 deletions csharp_interface/cozmoInterface/action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class Action
{
private SdkConnection _connection = null;
private ExternalInterface.QueueSingleAction _message = null;
private byte _robotId = 0;
private uint _id = 0;
private bool _completed = false;

Expand All @@ -31,10 +30,9 @@ public class Action
public uint ID { get { return _id; } }
public ExternalInterface.QueueSingleAction Message { get { return _message; } }

public Action(SdkConnection connection, byte robotId)
public Action(SdkConnection connection)
{
_connection = connection;
_robotId = robotId;

_id = _nextActionId;
_nextActionId++;
Expand All @@ -46,7 +44,7 @@ public Action(SdkConnection connection, byte robotId)

public void Abort()
{
_connection.SendMessage(new ExternalInterface.CancelActionByIdTag(_id, _robotId));
_connection.SendMessage(new ExternalInterface.CancelActionByIdTag(_id));
}

public void MarkAsComplete()
Expand All @@ -67,7 +65,7 @@ public void Initialize<T>(T state, int numRetries, bool inParallel)
Cozmo.QueueActionPosition position = inParallel ? Cozmo.QueueActionPosition.IN_PARALLEL : Cozmo.QueueActionPosition.NOW;
ExternalInterface.RobotActionUnion action = new ExternalInterface.RobotActionUnion();
action.Initialize(state);
_message = new ExternalInterface.QueueSingleAction(robotID: _robotId, idTag: _id, numRetries: (byte)numRetries, position: position, action: action);
_message = new ExternalInterface.QueueSingleAction(idTag: _id, numRetries: (byte)numRetries, position: position, action: action);
}
}
} // namespace Cozmo
Expand Down
18 changes: 6 additions & 12 deletions csharp_interface/cozmoInterface/connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ public class SdkConnection
private Dictionary<System.Type, Dictionary<object, iCallback>> _callbacks = new Dictionary<System.Type, Dictionary<object, iCallback>>();
private List<Action> _inFlightActions = new List<Action>();
private bool _open = false;
private byte _currentRobotId = byte.MaxValue;

public byte CurrentRobotId { get { return _currentRobotId; } }
private bool _robotIsConnected = false;

public SdkConnection(string ip, int socket, bool verboseLogging = false)
{
Expand All @@ -62,7 +60,7 @@ public SdkConnection(string ip, int socket, bool verboseLogging = false)
_open = true;

// wait for robot
while (_currentRobotId == byte.MaxValue)
while (!_robotIsConnected)
{
Thread.Sleep(5);
}
Expand All @@ -85,7 +83,7 @@ public void Close()

public Action SendAction<T>(T state, int numRetries = 0, bool inParallel = false)
{
Action result = new Action(this, _currentRobotId);
Action result = new Action(this);
result.Initialize(state, numRetries, inParallel);

_inFlightActions.Add(result);
Expand Down Expand Up @@ -136,7 +134,6 @@ private void SendMessageInternal(SDKMessageOut messageOut)
private void ReceiveMessage(SDKMessageIn messageIn)
{
var message = messageIn.Message;

if (_verboseLogging) { System.Console.WriteLine("Recieved Message - " + message.GetTag()); }

// since the property to access individual message data in a CLAD message shares its name
Expand All @@ -154,13 +151,10 @@ private void ReceiveMessage(SDKMessageIn messageIn)
}
}

// does this give us a robot id?
string robotIDPropertyName = "robotID";
if (_currentRobotId == byte.MaxValue && messageData.GetType().GetProperty(robotIDPropertyName) != null)
if (!_robotIsConnected && message.GetTag() == Anki.Cozmo.ExternalInterface.MessageEngineToGame.Tag.RobotState)
{
uint robotId = (uint)messageData.GetType().GetProperty(robotIDPropertyName).GetValue(messageData, null);
_currentRobotId = (byte)robotId;
System.Console.WriteLine("Robot connected with id " + _currentRobotId.ToString());
_robotIsConnected = true;
System.Console.WriteLine("Robot connected!");
}
}

Expand Down
2 changes: 1 addition & 1 deletion csharp_interface/cozmoInterface/version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Cozmo
{
public static class SDKVersion
{
public static readonly string _Data = "0.1.0";
public static readonly string _Data = "0.4.0";
}
} // namespace Cozmo
} // namespace Anki

0 comments on commit 239d1fd

Please sign in to comment.