1

I am designing a web script to automatically create a Java file to perform autonomous actions for a robotics team based on nodes created by the player. It also features a simulation to check collision (I could use an algorithm to do this but sometimes we want it to hit the walls). The robot takes relative degrees, but atan2 gives radians on the unit circle. If I use atan, it just doesn't work right. I've tried this:

function findDegrees(node1, node2){
  return Math.atan((node2.y - node1.y) / (node2.x - node1.x)) * 180 / Math.PI;
}

But it just doesn't work. This piece of code writes the data too the output. (Also, I'm following the pattern: Drive, then turn towards next node).

  let theta = currentAngle - findDegrees(nextNode, twoNodes);
  currentAngle += theta;
  if (theta && typeof theta !== 'undefined'){
    middle += `${INDENTSPACE}turn(${theta}, 1.0);\n`;
  }

The way I change the x and y of the robot simulation is this:

turn(degrees, speed){
  this.theta -= degrees;
}

But sometimes it goes the other way. How do I get the robot to rotate at a relative angle to the current angle where directly forward is 0°? (If you want the full code here it is.)

Arkin Solomon
  • 592
  • 1
  • 5
  • 23
  • This post might have some useful ideas for you: https://stackoverflow.com/questions/7570808/how-do-i-calculate-the-difference-of-two-angle-measures – calebkm Apr 18 '21 at 21:56

0 Answers0