private Task GetTaskFromName(string taskName, string taskType, string controllerip, int controllerport) { string apiParameters = string.Format("scene/{0}/task/?format=json&limit=1&name={1}&fields=pk,tasktype", this.scenePrimaryKey, taskName); Dictionary <string, object> jsonMessage = controllerClient.GetJsonMessage(HttpMethod.GET, apiParameters); List <object> tasks = (List <object>)jsonMessage["objects"]; if (tasks.Count == 0) { return(null); } Dictionary <string, object> resultMap = (Dictionary <string, object>)tasks[0]; string taskPrimaryKey = (string)resultMap["pk"]; string taskTypeResult = (string)resultMap["tasktype"]; if (!taskType.Equals(taskTypeResult)) { throw new ClientException("unsupported task type: " + taskTypeResult); } return(new BinPickingTask(taskPrimaryKey, taskName, controllerip, controllerport, this.controllerClient)); }
public RobotState GetJointValues(long timeOutMilliseconds = 30000) { string apiParameters = string.Format("task/{0}/?format=json&fields=pk", this.taskPrimaryKey); Dictionary <string, object> apistring = new Dictionary <string, object>(); apistring["controllerip"] = this.controllerip; apistring["controllerport"] = this.controllerport; apistring["command"] = "GetJointValues"; Dictionary <string, object> command = new Dictionary <string, object>(); command["tasktype"] = "binpicking"; command["taskparameters"] = apistring; string message = JSON.ToJSON(command); // Update task controllerClient.GetJsonMessage(HttpMethod.PUT, apiParameters, message); Dictionary <string, object> result = this.Execute(timeOutMilliseconds); Dictionary <string, object> jointValuesMap = (Dictionary <string, object>)result["output"]; RobotState state = new RobotState(); List <object> jointnames = (List <object>)jointValuesMap["jointnames"]; state.jointNames = new string[jointnames.Count]; for (int i = 0; i < jointnames.Count; i++) { state.jointNames[i] = (string)jointnames[i]; } List <object> currentjointvalues = (List <object>)jointValuesMap["currentjointvalues"]; Debug.Assert(currentjointvalues.Count == jointnames.Count); state.jointValues = new double[currentjointvalues.Count]; for (int i = 0; i < currentjointvalues.Count; ++i) { state.jointValues[i] = (double)currentjointvalues[i]; } Dictionary <string, object> tools = (Dictionary <string, object>)jointValuesMap["tools"]; state.tools = new Dictionary <string, double[]>(); foreach (KeyValuePair <string, object> keyvalue in tools) { List <object> toolvalues = (List <object>)keyvalue.Value; Debug.Assert(toolvalues.Count == 6); double[] dsttoolvalues = new double[6]; for (int i = 0; i < 6; ++i) { dsttoolvalues[i] = (double)toolvalues[i]; } state.tools[keyvalue.Key] = dsttoolvalues; } return(state); }