Git Product home page Git Product logo

Comments (7)

virtuald avatar virtuald commented on July 19, 2024

I have an alternative idea for this. What if instead we used a prefix scheme to inject things? Something like...

class Component:
    motor = wpilib.Talon


class MyRobot:
    left_component = Component
    right_component = Component
    
    def create_objects(self):
        left_component_motor = wpilib.Talon
        right_component_motor = wpilib.Talon

So when it was looking for variables to inject, it looks first for the actual name, and if it doesn't find it then it looks for the variable name prefixed by the component name? This would solve your issue, yeah?

Keep in mind that you could inject anything you wanted, it doesn't have to be a motor -- it could be a tuple too I think.

from robotpy-wpilib-utilities.

virtuald avatar virtuald commented on July 19, 2024

The thing I'm undecided on is whether it should look for the prefixed version of the variable first, or whether it should look for the variable name first. For backwards compatibility, probably variable name first..

from robotpy-wpilib-utilities.

CarterFendley avatar CarterFendley commented on July 19, 2024

So my main issue is that there is a lot of things in my constructor. To use magic bot components I would have to create two motor object and one encoder object for each Swerve Module. Then I would have to call multiple functions to turn off and on flags and also set the zero value for the encoder. For each module that I initialized it would be around 8 lines of code. I would end up with around 32 lines of just creating swerve module things.

from robotpy-wpilib-utilities.

CarterFendley avatar CarterFendley commented on July 19, 2024

I would be happy if some how we had access to the arguments passed to the setup() method.

from robotpy-wpilib-utilities.

virtuald avatar virtuald commented on July 19, 2024

You could do:

class MyRobot:
    module_args = (1,2,3,4)

class Component:
    module_args = tuple

from robotpy-wpilib-utilities.

virtuald avatar virtuald commented on July 19, 2024

Turns out I had already implemented the prefix thing. You should use a tuple to pass your args to the underlying component. I'll write some docs.

from robotpy-wpilib-utilities.

virtuald avatar virtuald commented on July 19, 2024

Docs are up here: http://robotpy.readthedocs.io/en/stable/frameworks/magicbot.html#variable-injection

from robotpy-wpilib-utilities.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.