Skip to content

Fix RotateHandler overwriting shape_num - #2

Open
TermiT wants to merge 1 commit into
microbotsio:mainfrom
TermiT:fix/rotatehandler-shape-num
Open

TermiT wants to merge 1 commit into
microbotsio:mainfrom
TermiT:fix/rotatehandler-shape-num

Conversation

@TermiT

@TermiT TermiT commented Aug 4, 2026

Copy link
Copy Markdown

shape_num = 2 in RotateHandler is an assignment, not a comparison. Every rotation during a shape rewrites shape_num to 2, so the routine turns into a triangle at its first corner.

Reproduce with examples/path shapes/square/square.ino unmodified — the robot drives a triangle instead of a square.

The MicroLink app is unaffected: it drives through rx_joystick_x/y, leaving _manual_mode at 0, so || short-circuits before the assignment runs. Sketches hit it because DriveSquare(), DriveInfinity() and Rotate() all set _manual_mode = 1. Triangle escapes only because it is already shape 2.

== is not the fix. The condition is always true today and the body has to run — DriveHandler mirrors leg angles with a < 180 ? 180-a : (360-a)+180, and rotation targets are in that same frame:

square raw mirrored
legs 90, 0, 270, 180 90, 180, 270, 360
rotations 0, 270, 180, 90 180, 270, 360, 90

Each rotation lands on the next leg's heading. With ==, manual-mode squares would skip the transform and two of four corners would be 180° out. Dropping the always-true condition keeps behaviour identical and removes only the stray write.

`shape_num = 2` is an assignment, not a comparison. Every rotation during
a shape rewrites shape_num to 2, so the routine turns into a triangle at
its first corner. examples/path shapes/square/square.ino reproduces it
unmodified.

The MicroLink app is unaffected: it leaves _manual_mode at 0, so || short
-circuits before the assignment runs. Sketches hit it because
DriveSquare(), DriveInfinity() and Rotate() all set _manual_mode = 1.

`==` is not the fix. The condition is always true today and the body has
to run: DriveHandler mirrors leg angles, and rotation targets use the same
frame, so skipping the transform leaves corners 180 degrees out. Dropping
the always-true condition keeps behaviour identical.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant