This is an archive of G2M. Please refer to this post for more information. Archived on 2026-01-09.

Atan function returns completely incorrect numbers

TheRealShrek420
01/11/2023 at 06:21:05 PM PST

I am attempting to code my mecanum wheel bot to be able to head any direction. This involves the atan function, as far as I have been able to tell. When I enter two values into the atan function, the numbers returned are completely incorrect. For example, atan(100/-10) should return ~-1.47. VexCode returns -84. As another example, atan(86/81) should give ~0.815. VexCode returns 45. Left and right directions return zero, no matter what. Is there a workaround? Am I doing something wrong? Code is in attachment.

Creation
01/11/2023 at 06:47:45 PM PST

When using blocks, the return value of atan is in degrees (as the following math shows with the examples that you provided):


Example block code:

VEXcode’s Blocks-to-Text (python):

brain.screen.print(math.atan(15) / math.pi * 180)

As you can see, there is an internal conversion to degrees.

You can invert the math if you want the value in radians (divide by 180/π or multiply by π/180).

TheRealShrek420
01/12/2023 at 06:43:01 AM PST

Replying to Creation ↩️

That makes sense, thanks. Do you know why the left and right directions return zero? After 45 degrees in either direction, it will switch to zero.

Creation
01/12/2023 at 12:29:02 PM PST

Replying to TheRealShrek420 ↩️

Could you please clarify “left and right directions”? I was probably missing something, but I didn’t quite understand how it relates to the code.

TheRealShrek420
01/12/2023 at 05:30:05 PM PST

Replying to Creation ↩️


The (roughly marked) red sections return zero no matter what

Creation
01/12/2023 at 09:33:16 PM PST

Replying to TheRealShrek420 ↩️

Expected controller points where the return value is 0:

If the position of axis4 is 0, there may be a ZeroDivisionError caused by (you guessed it), dividing by zero. It doesn’t explain why you get 0 anywhere in the range you specified though. I suggest converting to a text project so that you can have a more dynamic output when debugging.

Any errors will show in this panel,


and you can print some test cases there too (such as printing axis3/axis4 in the while loop).

TheRealShrek420
01/14/2023 at 04:30:33 PM PST

Replying to Creation ↩️

I got it to return degrees 0-360. It took 111 blocks. Not ideal, but it works.
The joystick also has to be along the edge.