{"action":"opened","issue":{"url":"https://api.github.com/repos/orbotix/sphero.js/issues/82","repository_url":"https://api.github.com/repos/orbotix/sphero.js","labels_url":"https://api.github.com/repos/orbotix/sphero.js/issues/82/labels{/name}","comments_url":"https://api.github.com/repos/orbotix/sphero.js/issues/82/comments","events_url":"https://api.github.com/repos/orbotix/sphero.js/issues/82/events","html_url":"https://github.com/orbotix/sphero.js/issues/82","id":188348476,"number":82,"title":"Feature Request: Go to a position in a coordination system.","user":{"login":"TechniclabErdmann","id":6872663,"avatar_url":"https://avatars.githubusercontent.com/u/6872663?v=3","gravatar_id":"","url":"https://api.github.com/users/TechniclabErdmann","html_url":"https://github.com/TechniclabErdmann","followers_url":"https://api.github.com/users/TechniclabErdmann/followers","following_url":"https://api.github.com/users/TechniclabErdmann/following{/other_user}","gists_url":"https://api.github.com/users/TechniclabErdmann/gists{/gist_id}","starred_url":"https://api.github.com/users/TechniclabErdmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TechniclabErdmann/subscriptions","organizations_url":"https://api.github.com/users/TechniclabErdmann/orgs","repos_url":"https://api.github.com/users/TechniclabErdmann/repos","events_url":"https://api.github.com/users/TechniclabErdmann/events{/privacy}","received_events_url":"https://api.github.com/users/TechniclabErdmann/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-11-09T20:47:20Z","updated_at":"2016-11-09T20:47:20Z","closed_at":null,"body":"Hey dev team,\r\n\r\nI started to develop a functionality to move sphero to a defined waypoint. You can integrate this feature in your sdk.\r\n\r\nThere are two open tasks:\r\n- calculate time for moving and callback for \"timeout\" function. Maybe there is a better solution?\r\n- before first moving, sphero has to align to Earth's magnetic field. So the coord system is the same everytime running the code.\r\n\r\nFunction: \r\n\r\n    function goToPosition(pos, x, y, speed) {\r\n        last_angle = 0;\r\n        var locationInterval = setInterval(function() {\r\n            orb.readLocator(function(err, data) {\r\n                if (err) {\r\n                    console.log(\"error: \", err);\r\n                } else {\r\n                    var xcomp = (x - data.xpos == 0) ? 1 : (x - data.xpos);\r\n                    var ycomp = (y - data.ypos == 0) ? 1 : (y - data.ypos);\r\n\r\n                    var angle = Math.atan(ycomp / xcomp);\r\n                    angle = angle * 180 / Math.PI;\r\n              \r\n                    if(angle < 90) {\r\n                        angle = 90 - angle;\r\n                    }\r\n                    if((x - data.xpos) < 0) {\r\n                        angle = angle + 180;\r\n                    }\r\n\r\n                    console.log(\"  --\" + pos + \"--\");\r\n                    console.log(\"  xpos:\", data.xpos);\r\n                    console.log(\"  ypos:\", data.ypos);\r\n                    console.log(\"  xerror:\", x - data.xpos);\r\n                    console.log(\"  yerror:\", y - data.ypos);\r\n                    console.log(\"  angle:\", angle   );\r\n\r\n                    orb.roll(speed, angle);\r\n\r\n                    // positon arrived\r\n                    if(((angle < 0) || (Math.abs(angle - last_angle) > 50)) && (last_angle != 0)) {\r\n                        clearInterval(locationInterval);\r\n                        orb.stop();\r\n                        console.log(\"Position arrived!\");\r\n                    }\r\n                    last_angle = angle;\r\n                }\r\n        });\r\n        }, 500);\r\n    }\r\n\r\nAn example use case:\r\n\r\n    var sphero = require(\"sphero\"),\r\n    orb = sphero(\"EE:75:8E:48:D5:6D\"); // change BLE address accordingly\r\n    var last_angle = 0;\r\n\r\n    /* place function goToPostion() {...} here */\r\n\r\n    orb.connect(function() {\r\n        var opts = {\r\n            flags: 0x01,\r\n            x: 0x0000,\r\n            y: 0x0000,\r\n            yawTare: 0x0\r\n        };\r\n    \r\n    console.log(\"::START CALIBRATION::\");\r\n    orb.startCalibration();\r\n    setTimeout(function() {\r\n        console.log(\"::FINISH CALIBRATION::\");\r\n        orb.finishCalibration();\r\n\r\n        orb.setBackLed(255);\r\n        orb.configureLocator(opts);\r\n        orb.color({ red: 255, green: 0, blue: 0 });\r\n\r\n        goToPosition(\"toPos1\", 0, 350, 50);\r\n        setTimeout(function() {\r\n            goToPosition(\"toPos2\", 200, 350, 50);\r\n\r\n        setTimeout(function() {\r\n            goToPosition(\"toPos3\", 200, 100, 50);\r\n\r\n        setTimeout(function() {\r\n            goToPosition(\"toPos4\", 5, 5, 50);\r\n        }, 10000);\r\n        }, 10000);\r\n        }, 10000);\r\n    }, 5000);\r\n    });\r\n\r\nI'm happy about feedback the the current code and help for the open tasks. Next step will be to enable communication between to spheros for simulation swarm intelligence. Feel free to contact me if you want to support.\r\n\r\nBye,\r\nNiklas"}}
{"actor":{"display_login":"TechniclabErdmann"}}