Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

magicbot: Add marker to cause variables to be reset #53

Closed
virtuald opened this issue Mar 20, 2017 · 0 comments
Closed

magicbot: Add marker to cause variables to be reset #53

virtuald opened this issue Mar 20, 2017 · 0 comments

Comments

@virtuald
Copy link
Member

virtuald commented Mar 20, 2017

Magicbot programs have some boilerplate involved with variables that get reset at the end of each execute loop. An idea I have is to mark some variables to be reset to defaults at the end of each loop.

Notionally, a component using this functionality would look like this:

class Climber:
  motor = wpilib.Talon
  do_climb = magic_reset_to(False)

  def climb(self):
    self.do_climb = True

  def execute(self):
    self.motor.set(1 if self.do_climb else 0)

I imagine the implementation would be similar to how tunable is implemented: an object is stored on the class, and then at initialization time the object is switched with the default value. At the end of every loop, the defaults are placed. I imagine an efficient implementation would just store a per-class dictionary, and then do component.__dict__.update(defaults).

Haven't decided on a name for the marker yet. Some proposals were:

  • magicreset
  • magicdefault
  • magicDefaultTo
  • magic_reset_to
  • will_reset_to
  • magic_loop_var

Other proposals accepted!

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

No branches or pull requests

1 participant