Exemplo n.º 1
0
        // Create a new task with incorrect port number
        public static void CTUC00400_CTUC00500()
        {
            // Make sure by browser that no task is present.

            SceneResource scene = CTUB00100();

            string xmlFilepath = "C:\\connection2.xml";

            XmlDocument  document = new XmlDocument();
            StreamReader reader   = new StreamReader(xmlFilepath, Encoding.UTF8);

            document.Load(reader);

            string taskName       = document.GetElementsByTagName("taskname")[0].InnerText;
            string taskType       = document.GetElementsByTagName("tasktype")[0].InnerText;
            string controllerip   = document.GetElementsByTagName("controllerip")[0].InnerText;
            int    controllerport = 9999;

            BinPickingTask task = (BinPickingTask)scene.GetOrCreateTaskFromName(
                taskName, taskType, controllerip, controllerport);

            try
            {
                task.GetJointValues();
            }
            catch (ClientException ex)
            {
                if (!ex.ToString().Contains("Controller port number is not correct"))
                {
                    throw new Exception("Test case CTUC00400_CTUC00500 failed");
                }
            }
        }
        public SceneDatabase()
        {
            mAllGeoms = new SceneResource<RTGeometry>();
            mAllMaterials = new SceneResource<RTMaterial>();
            mAllTextures = new SceneResource<RTTexture>();
            mAllLights = new SceneResource<RTLight>();

            // the default material: index of 0
            RTMaterial m = new RTMaterial();
            mAllMaterials.AddResource(m);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            string hostname = "controller65";
            string username = "******";
            string password = "******";
            string scenepk  = "knowledgepicking1.mujin.dae";

            ControllerClient controllerClient = new ControllerClient(username, password, "http://" + hostname);

            SceneResource  scene = controllerClient.GetScene(scenepk);
            BinPickingTask task  = (BinPickingTask)scene.GetOrCreateTaskFromName("test_task_1", "binpicking");

            // slave request id for the target slave, usually hostname + "_slave0"
            task.SlaveRequestID = hostname + "_slave0";

            // remove objects in the scene whose names have this prefix, optional
            string prefix = "detected_sourcecontainer_";

            // list of objects and their poses to be updated in the scene
            List <Dictionary <string, object> > envstate = new List <Dictionary <string, object> >()
            {
                new Dictionary <string, object>()
                {
                    { "name", prefix + "1" },
                    { "quat_", new List <double>()
                      {
                          1, 0, 0, 0
                      } },
                    { "translation_", new List <double>()
                      {
                          0, 0, 300
                      } },
                    { "object_uri", "mujin:/work1.mujin.dae" },
                },
                new Dictionary <string, object>()
                {
                    { "name", prefix + "2" },
                    { "quat_", new List <double>()
                      {
                          1, 0, 0, 0
                      } },
                    { "translation_", new List <double>()
                      {
                          0, 100, 400
                      } },
                    { "object_uri", "mujin:/work2_b.mujin.dae" },
                }
            };

            task.UpdateObjects(envstate, prefix);
        }
Exemplo n.º 4
0
        // Create a new task and get the task
        public static BinPickingTask CTUC00100()
        {
            // Make sure by browser that no task is present.

            SceneResource scene = CTUB00100();

            string xmlFilepath = "C:\\connection2.xml";

            XmlDocument  document = new XmlDocument();
            StreamReader reader   = new StreamReader(xmlFilepath, Encoding.UTF8);

            document.Load(reader);

            string taskName       = document.GetElementsByTagName("taskname")[0].InnerText;
            string taskType       = document.GetElementsByTagName("tasktype")[0].InnerText;
            string controllerip   = document.GetElementsByTagName("controllerip")[0].InnerText;
            int    controllerport = int.Parse(document.GetElementsByTagName("controllerport")[0].InnerText);

            BinPickingTask task = (BinPickingTask)scene.GetOrCreateTaskFromName(
                taskName, taskType, controllerip, controllerport);

            return((BinPickingTask)scene.GetOrCreateTaskFromName(
                       taskName, taskType, controllerip, controllerport));
        }
        internal void AddRTScene(RayTracer_552.RTCamera c, RayTracer_552.SceneDatabase rtScene)
        {
            UWB_Primitive prim;

            NewSceneDatabase();
            SceneResource <RTGeometry> allGeom = rtScene.GetAllGeom();

            for (int i = 0; i < allGeom.Count; i++)
            {
                RTGeometry g = (RTGeometry)allGeom.ResourceLookup(i);
                switch (g.GeomType())
                {
                case RTGeometry.RTGeometryType.Sphere:
                    RTSphere s = (RTSphere)g;
                    prim = CreateSphereMesh();
                    SetMeshMaterial(prim, rtScene.GetMaterial(s.GetMaterialIndex()));
                    float scale = s.Radius / 2f;
                    CreateNode(s.Center, scale, scale, scale, prim);
                    break;

                case RTGeometry.RTGeometryType.Rectangle:
                    RTRectangle r = (RTRectangle)g;
                    prim = CreateRectangle(r);
                    SetMeshMaterial(prim, rtScene.GetMaterial(r.GetMaterialIndex()));
                    UWB_SceneNode node = CreateNode(r.GetCenter(), r.GetUSize() / 2f, 1f, r.GetVSize() / 2f, prim);
                    // now rotate the y-vector of node to point towards r.Normal;
                    float dot = (float)Math.Abs(Vector3.Dot(Vector3.UnitY, r.GetNormal()));
                    if (dot < 0.9999f)
                    {
                        float   angle = (float)Math.Acos(dot);
                        Vector3 axis  = Vector3.Cross(Vector3.UnitY, r.GetNormal());
                        axis.Normalize();
                        Quaternion    q  = Quaternion.CreateFromAxisAngle(axis, angle);
                        UWB_XFormInfo xf = node.getXFormInfo();
                        xf.SetRotationQuat(q);
                        node.setXFormInfo(xf);
                    }
                    break;

                case RTGeometry.RTGeometryType.Triangle:
                    RTTriangle t = (RTTriangle)g;
                    Vector3[]  v = t.GetVertices();
                    prim = new UWB_PrimitiveTriangle(v[0], v[1], v[2]);
                    prim.EnableLighting(true);
                    prim.EnableTexturing(false);
                    SetMeshMaterial(prim, rtScene.GetMaterial(t.GetMaterialIndex()));
                    CreateNode(Vector3.Zero, 1f, 1f, 1f, prim);
                    break;
                }
            }
            AddCamera(c);
            AddLights(rtScene);

            // to show ray list
            mShownRayX  = mShownRayY = 0;
            mRaysToShow = new UWB_PrimitiveList();

            mDebugInfo = new UWB_SceneNode();
            mDebugInfo.setPrimitive(mRaysToShow);
            mDebugInfo.insertChildNode(mPixelsToShow.GetAllPixels());
            mDebugInfo.insertChildNode(mPixelInWorld.GetAllPixels());
        }
Exemplo n.º 6
0
        public ResourceReference Save(IResource resource, ResourceOperationContext context)
        {
            if (context.CurrentUser == null)
            {
                throw new InvalidOperationException("User not found");
            }

            Data.Resource dbResource = null;

            //check if the resource already exist in the database
            if (resource.Id > 0)
            {
                dbResource = _dbContext.Resources.Find(resource.Id);
            }

            if (dbResource != null)
            {
                //Update the Resource and Content
                dbResource.Name           = resource.Name;
                dbResource.LastUpdateDate = DateTime.Now;
                dbResource.UpdateUserId   = context.CurrentUser.UserId;
            }
            else
            {
                //Else this is a new resource that was created or was delete from the respository.
                //So create the Resource ,the Content Store and add the resource to the ResourceManager's cache
                var resourceType = GetResourceType(resource);
                var folder       = GetFolder(resourceType);

                dbResource = _dbContext.Resources.Create();
                dbResource.CreateUserId   = context.CurrentUser.UserId;
                dbResource.UpdateUserId   = context.CurrentUser.UserId;
                dbResource.LastUpdateDate = DateTime.Now;
                dbResource.Name           = resource.Name;
                dbResource.ResourceTypeId = resourceType != null ? (int?)resourceType.ResourceTypeId : null;
                dbResource.FolderId       = folder.FolderId;

                dbResource = _dbContext.Resources.Add(dbResource);
                _dbContext.SaveChanges();

                resource.Id = dbResource.Id;

                //The resoures does'n has an Id until it was saved.
                //Then initialize the reference counter
                _resourceManager.Add(resource);
            }

            //mark as saved
            context.SetIsSaved(resource, true);

            //Check if the resource is saved with a context Scene
            if (context.Scene != null && !context.Scene.IsDesignOnly)
            {
                //IF true then link the resource to the context Scene
                if (!_dbContext.SceneResources.Any(x => x.ResourceId == dbResource.Id &&
                                                   x.SceneId == context.Scene.Id))
                {
                    //create the SceneResource
                    SceneResource sceneResource = new SceneResource()
                    {
                        ResourceId = dbResource.Id,
                        SceneId    = context.Scene.Id,
                    };
                    _dbContext.SceneResources.Add(sceneResource);
                }
            }

            //Creates the Reference
            ResourceReference reference;

            if (!_references.TryGetValue(dbResource.Id, out reference))
            {
                reference = new ResourceReference(dbResource.Id);
                _references.Add(dbResource.Id, reference);
            }

            if (dbResource.Content == null)
            {
                //Creates the resource content
                dbResource.Content = new Content();
            }

            //write the resource content data
            var data = CreateAsset(resource, context);

            Debug.Assert(data != null, "Invalid Resource " + resource.Name);
            dbResource.Content.Data = data;

            _dbContext.SaveChanges();

            return(reference);
        }
Exemplo n.º 7
0
 string SceneName(SceneResource target_scene)
 {
     return(Enum.GetName(typeof(SceneResource), target_scene));
 }
Exemplo n.º 8
0
 public void ToScene(SceneResource target_scene)
 {
     next_scene = SceneName(target_scene);
     SceneManager.LoadScene("loading");
 }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            if (true)
            {
                ControllerClient controllerClient2 = new ControllerClient("testuser", "mytestpass", "http://controller13");

                //controllerClient.Initialize("mujin:/irex2013/irex2013.WPJ", "mujincollada", "wincaps", "mujin:/irex2013.mujin.dae");

                //SceneResource scene2 = controllerClient2.GetScene("test.mujin.dae");

                // JSON creation
                //Dictionary<string, object> jsonMessage = controllerClient2.GetJsonMessage(HttpMethod.POST, "scene/?format=json", "{\"name\":\"newname\", \"reference_uri\":\"mujin:/plasticnut-center.mujin.dae\"}");

                // XML creation
                Dictionary <string, object> xmlMessage = controllerClient2.GetXMLMessage(HttpMethod.POST, "scene/?format=xml", "<request><name>newname3</name><reference_uri>mujin:/plasticnut-center.mujin.dae</reference_uri></request>");
            }

            // Default XML path:
            // string xmlFilepath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "..\\..\\samples\\getsceneinfo\\config\\connection.xml";

            // Custom XML path;
            string xmlFilepath = "C:\\connection2.xml";

            XmlDocument  document = new XmlDocument();
            StreamReader reader   = new StreamReader(xmlFilepath, Encoding.UTF8);

            document.Load(reader);

            string mujinIpAddress  = document.GetElementsByTagName("ipaddress")[0].InnerText;
            string scenePrimaryKey = document.GetElementsByTagName("scenepk")[0].InnerText;
            string username        = document.GetElementsByTagName("username")[0].InnerText;
            string password        = document.GetElementsByTagName("password")[0].InnerText;
            string taskName        = document.GetElementsByTagName("taskname")[0].InnerText;
            string taskType        = document.GetElementsByTagName("tasktype")[0].InnerText;
            string controllerip    = document.GetElementsByTagName("controllerip")[0].InnerText;
            int    controllerport  = int.Parse(document.GetElementsByTagName("controllerport")[0].InnerText);

            ControllerClient controllerClient = new ControllerClient(username, password, mujinIpAddress);

            //controllerClient.Initialize("mujin:/irex2013/irex2013.WPJ", "mujincollada", "wincaps", "mujin:/irex2013.mujin.dae");

            SceneResource  scene = controllerClient.GetScene(scenePrimaryKey);
            BinPickingTask task  = (BinPickingTask)scene.GetOrCreateTaskFromName(taskName, taskType, controllerip, controllerport);

            // Test1: GetJointValues
            RobotState robotState = task.GetJointValues();

            /*
             * // Test2: MoveJoints
             * robotState.jointValues[1] += 30;
             * robotState.jointValues[3] -= 30;
             * List<double> jointValues = new List<double>() { robotState.jointValues[1], robotState.jointValues[3] };
             * List<int> jointIndices = new List<int>(){1, 3};
             * task.MoveJoints(jointValues, jointIndices, 30, 0.2, "");
             */

            List <double> jointValues = new List <double>()
            {
                45
            };
            List <int> jointIndices = new List <int>()
            {
                6
            };

            task.MoveJoints(jointValues, jointIndices, 30, 0.2, "");

            jointValues = new List <double>()
            {
                0, 0, 0, 0, 0, 0, 0
            };
            jointIndices = new List <int>()
            {
                0, 1, 2, 3, 4, 5, 6
            };
            task.MoveJoints(jointValues, jointIndices, 30, 0.2, "");

            /*
             * // Test3: MoveToHandPosition
             * double[] basepos = robotState.tools["1Base"];
             * basepos[1] += 50;
             * basepos[3] -= 50;
             * task.MoveToHandPosition(new List<double>(basepos), GoalType.transform6d, "1Base", 0.2);
             */

            // Test4: PickAndMove
            //task.PickAndMove("container3", "camera3", "1Base", GoalType.translationdirection5d, new List<double>() { 1900, 240, 700, 0, 0, 1 }, 0.2);
        }