void EnvironmentStep() { if (stepCount % DecisionPeriod == 0) { var actionReq = new BrainActionRequest(); foreach (KeyValuePair <int, RemoteAction> agent in m_RemoteAgents) { float[] lowerObs = agent.Value.remoteAgent.GetLowerObservations(); float[] upperObs = agent.Value.remoteAgent.GetUpperObservations(); var obs = new Observations() { }; obs.LowerObservations.AddRange(lowerObs); obs.UpperObservations.AddRange(upperObs); obs.ArucoMarkerID = agent.Value.remoteAgent.m_ArucoMarkerID; actionReq.Observations.Add(obs); } // Send sensor data to remote brain brainActionRes = brainServerClient.GetAction(actionReq); MakeActions(brainActionRes); } else if (TakeActionsBetweenDecisions) { MakeActions(brainActionRes); } stepCount++; }
void MakeActions(BrainActionResponse actions) { foreach (var robotAction in actions.Actions) { var action = robotAction.Action; var arucoMarkerID = robotAction.ArucoMarkerID; m_RemoteAgents[arucoMarkerID].remoteAgent.OnActionReceived(new float[] { action }); } }
public override Task <BrainActionResponse> GetAction(BrainActionRequest req, ServerCallContext context) { try { foreach (var actionReq in req.Observations) { var lowerObsList = new List <float>(); lowerObsList.AddRange(actionReq.LowerObservations); var upperObsList = new List <float>(); upperObsList.AddRange(actionReq.UpperObservations); // Set observations to remote agent. agentDict[actionReq.ArucoMarkerID].SetObservations(lowerObsList.ToArray(), upperObsList.ToArray()); agentDict[actionReq.ArucoMarkerID].RequestDecision(); } var brainActionRes = new BrainActionResponse(); foreach (KeyValuePair <int, RemoteAIRobotAgent> agent in agentDict) { int action = -1; while (action < 0) { action = agent.Value.GetDecidedAction(); if (action != -1) { break; } Thread.Sleep(3); } var newAction = new RobotAction() { Action = action, ArucoMarkerID = agent.Key }; brainActionRes.Actions.Add(newAction); } // Send remote agents action back. return(Task.FromResult(brainActionRes)); } catch (Exception error) { Debug.Log(error); var brainActionResFail = new BrainActionResponse(); foreach (KeyValuePair <int, RemoteAIRobotAgent> agent in agentDict) { var newAction = new RobotAction() { Action = 0, ArucoMarkerID = agent.Key }; brainActionResFail.Actions.Add(newAction); } return(Task.FromResult(brainActionResFail)); } }