Guest User

Untitled

a guest
Oct 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. </head>
  6. <body>
  7.  
  8. <script>
  9. // This is the x and y of the next point you're moving to
  10. var nextPoint_x = 33;
  11. var nextPoint_y = 72;
  12.  
  13. // Measure the x and y point of the Plinkquito chassis when totally unspooled
  14. var startingPoint_x = 0;
  15. var startingPoint_y = 0;
  16.  
  17. // Measure the x and y positions of your motors
  18. var leftMotor_x = -200;
  19. var leftMotor_y = 150;
  20. var rightMotor_x = 200;
  21. var rightMotor_y = 150;
  22.  
  23. // Measure the string width and the motor diameter
  24. var stringWidth = .032;
  25. var motorDiameter = 2.5;
  26. var motorCircumference = Math.PI*motorDiameter;
  27.  
  28. // Set these percentages to test different proportions of error for spiraling and doubling
  29. var percentSpiraling = .5;
  30. var percentDoubling = .5;
  31.  
  32. // General purpose function to calculate the distance between two points with coordinates (x1, y1) and (x2, y2)
  33. function calculateDistance (x1, y1, x2, y2) {
  34. var deltaX = x2 - x1;
  35. var deltaY = y2 - y1;
  36. var distance = Math.sqrt(Math.pow(deltaX, 2)+Math.pow(deltaY, 2));
  37.  
  38. return distance;
  39. }
  40.  
  41. // Calculate initial, unspooled length from right motor
  42. var initRightLength = calculateDistance(rightMotor_x, rightMotor_y, startingPoint_x, startingPoint_y);
  43.  
  44. // Calculate initial, unspooled length from left motor
  45. var initLeftLength = calculateDistance(leftMotor_x, leftMotor_y, startingPoint_x, startingPoint_y);
  46.  
  47. // General purpose funtion to calculate turns needed to get to get to a certain string length
  48. function calculateTurns (initLength, currLength) {
  49. var spooledLength = initLength - currLength;
  50.  
  51. var numDoublingTurns = (Math.sqrt(Math.PI*Math.pow(motorDiameter, 2) + 2*Math.PI*motorDiameter*stringWidth + 4*spooledLength*stringWidth + Math.PI*Math.pow(stringWidth, 2)) - Math.sqrt(Math.PI)*motorDiameter - Math.sqrt(Math.PI)*stringWidth)/(2*Math.sqrt(Math.PI)*stringWidth);
  52.  
  53. var numSpiralingTurns = spooledLength / Math.sqrt(Math.pow((Math.PI*motorDiameter), 2) + Math.pow(stringWidth, 2));
  54.  
  55. var turns = percentDoubling*numDoublingTurns + percentSpiraling*numSpiralingTurns;
  56.  
  57. console.log("Turns is "+turns);
  58. return turns;
  59. }
  60.  
  61. // Calculate left motor turns to get to next point
  62. calculateTurns (initLeftLength, calculateDistance(leftMotor_x, leftMotor_y, nextPoint_x, nextPoint_y));
  63.  
  64. // Calculate right motor turns to get to next point
  65. calculateTurns (initRightLength, calculateDistance(rightMotor_x, rightMotor_y, nextPoint_x, nextPoint_y));
  66.  
  67. </script>
  68.  
  69. </body>
  70. </html>
Add Comment
Please, Sign In to add comment