Skip to content

Conversation

@MaartenS11
Copy link
Member

@MaartenS11 MaartenS11 commented Aug 19, 2024

This PR adds the initial support for reversible primitives to WARDuino. This makes it possible to define the action that should be executed to revert the action of a primitive. For example defining that if an led was off and is then turned on it should be turned off again when stepping back. This can be done using some new macros. To define the action you can use def_prim_reverse, to define the method used to serialize external state you use def_prim_serialize.

This PR also adds some useful code for invoking primitives from within code for example:

invoke_primitive(m, "chip_digital_write", 5, 1);

will run chip_digital_write(5, 1) in the vm.

Currently, the macros and code needed to have reversible primitives is replicated for all platforms which is not ideal. We should probably try reduce the amount of duplicated code in the primitive files in a future PR.

This allows the debugger to inspect the current io state and load io states from snapshots. Currently only works with chip_digital_write.
There currently is no support for analog values.
The main reason for this is to support boards such as Open Bot Brain which uses
an stm32l496zg. By porting to Zephyr we can also add support for some other
boards with relative ease.
This makes it so if the motor tries to move but it's not actually moving the
voltage applied to the motor is increased until it moves and completes the
operation.
Reversible primitives are now defined by using def_prim_reverse and def_prim_serialize.
Rebase was a bit complex due to main and this branch both have partially the
same feature (the Zephyr platform) so I ended up just merging main into this
branch. Will be squashed later anyway.
…ed and not for all primitives

This particularly important for motor primitives that for example drive two motors at the same time vs a primitive that drives one motor at a time, executing the wrong reverse operation will result in the correct angles but the wrong position.
Also added helper functions to reduce duplicated code between drive_motor_degrees and drive_motor_degrees_relative.
@MaartenS11
Copy link
Member Author

I think I'm just going to open this up for review. I'm not happy with how some of the code is duplicated for each of the platform primitives but fixing that requires a bit of a refactor to the primitive system that should probably be done in another PR. The PR adds the macros and functions needed for all platforms but currently only adds reversibility to chip_digital_write on the Arduino platform. Reversibility for other platforms such as Zephyr or the servo motor drivers (which are not yet merged) can be added later.

@MaartenS11 MaartenS11 marked this pull request as ready for review August 20, 2024 15:44
@MaartenS11 MaartenS11 requested a review from tolauwae August 20, 2024 15:44
@MaartenS11 MaartenS11 force-pushed the feat/reversible-primitives branch from b348083 to 296fffd Compare August 22, 2024 07:39
@tolauwae tolauwae force-pushed the main branch 2 times, most recently from 1996698 to 5d87aad Compare September 3, 2024 12:15
@tolauwae tolauwae enabled auto-merge (squash) September 24, 2024 11:42
@tolauwae tolauwae disabled auto-merge September 24, 2024 11:42
@tolauwae tolauwae merged commit d038faf into main Sep 24, 2024
@tolauwae tolauwae deleted the feat/reversible-primitives branch September 24, 2024 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants