robot.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. this.initialize = function(){}
  2. this.initRobot = function(){
  3. let nodes = {
  4. 'left': {
  5. position: [-1,0,0]
  6. },
  7. 'right': {
  8. position: [1,0,0]
  9. },
  10. 'front': {
  11. position: [0,0,1]
  12. },
  13. 'back': {
  14. position: [0,0,-1]
  15. }
  16. };
  17. Object.keys(nodes).forEach(el=>{
  18. let legoBoostNode = {
  19. "extends": "proxy/objects/legoboost.vwf",
  20. "properties": {
  21. "boostID": el,
  22. "position": nodes[el].position,
  23. "displayName": el,
  24. "tracking": false
  25. }
  26. }
  27. this.children.create(el, legoBoostNode, function( child ) {
  28. child.createVisual();
  29. child.trackLego();
  30. })
  31. })
  32. }
  33. this.rotateFace = function(faceID){
  34. let direction = (faceID == faceID.toLowerCase()) ? -1 : 1;
  35. let angle = 90;
  36. //let dutyCycle = 80 * direction;
  37. let robotMap = {
  38. 'l': {
  39. 'robot': 'left',
  40. 'motor': 'B',
  41. 'dutyCycle': 70,
  42. 'direction': -1*direction
  43. },
  44. 'd': {
  45. 'robot': 'left',
  46. 'motor': 'C',
  47. 'dutyCycle': 80,
  48. 'direction': -1*direction
  49. },
  50. 'b': {
  51. 'robot': 'back',
  52. 'motor': 'A',
  53. 'dutyCycle': 60,
  54. 'direction': direction
  55. },
  56. 'r': {
  57. 'robot': 'right',
  58. 'motor': 'A',
  59. 'dutyCycle': 60,
  60. 'direction': direction
  61. },
  62. 'u': {
  63. 'robot': 'back',
  64. 'motor': 'C',
  65. 'dutyCycle': 60,
  66. 'direction': -1*direction
  67. },
  68. 'f': {
  69. 'robot': 'front',
  70. 'motor': 'A',
  71. 'dutyCycle': 70,
  72. 'direction': direction
  73. }
  74. }
  75. let robot = robotMap[faceID.toLowerCase()];
  76. this[robot.robot].setMotorAngle(robot.motor, angle, robot.dutyCycle*robot.direction, 'sync');
  77. }