Skip to content

[Feature] Multi-File Project on PrimeHub/InventorHub #189

Closed

Description

@TheVinhLuong102

Hi @dlech and @laurensvalk,

Happy New Year to you! Antoni and I are looking forward to exciting PyBricks releases this year.

Antoni and I are trying out PyBricks on the InventorHub, and we would like to ask if it is possible yet/soon to download multiple files of one same project onto the InventorHub and import code classes/functions among such files?

Each robot in the Inventor set has many variants and plays many different games, so it would be great if we can organize a base class and many subclasses for each robot.

Thank you very much!

Vinh

Activity

  1. added
    triage
    on Jan 2, 2021
  2. laurensvalk commented on Jan 2, 2021

    @laurensvalk
    Member

    Wow, you guys are quick! 🚀

    we would like to ask if it is possible yet/soon to download multiple files of one same project onto the InventorHub and import code classes/functions among such files?

    In the long run, probably yes. However, knowing how fast you are, probably not before you have built all the models 😄

    Each robot in the Inventor set has many variants and plays many different games, so it would be great if we can organize a base class and many subclasses for each robot.

    However, a base class for each robot is probably still a good idea. You'd have to have a copy in each program for now. Perhaps we could split it out to a library (or something like it) later when we have file system support.

    Since this system is a bit different from EV3, I do have a few suggestions for minor style changes for these projects. Perhaps we can discuss those when you make the first pull request.

  3. added
    cool project
    hub: primehub/inventorhub
    and removed
    triage
    on Jan 2, 2021
  4. laurensvalk commented on Jan 2, 2021

    @laurensvalk
    Member

    Since this system is a bit different from EV3, I do have a few suggestions for minor style changes for these projects. Perhaps we can discuss those when you make the first pull request.

    Since you've shared a snippet in #190, perhaps I can share what I mean here. These are some performance considerations as well as suggestions to make them easier to read for beginning users.

    #!/usr/bin/env pybricks-micropython
    
    
    from pybricks.hubs import InventorHub
    from pybricks.pupdevices import Motor, ColorSensor, UltrasonicSensor
    from pybricks.parameters import Direction, Port
    from pybricks.robotics import DriveBase
    
    
    class Tricky:
        WHEEL_DIAMETER = 44
        AXLE_TRACK = 88
    
        def __init__(
                self,
                left_wheel_motor_port: Port = Port.A,
                right_wheel_motor_port: Port = Port.B,
                sport_motor_port: Port = Port.C,
                distance_sensor_port: Port = Port.D,
                color_sensor_port: Port = Port.E):
            self.hub = InventorHub()
    
            self.driving_base = \
                DriveBase(
                    left_motor=Motor(port=left_wheel_motor_port,
                                     positive_direction=Direction.CLOCKWISE),
                    right_motor=Motor(port=right_wheel_motor_port,
                                      positive_direction=Direction.CLOCKWISE),
                    wheel_diameter=self.WHEEL_DIAMETER,
                    axle_track=self.AXLE_TRACK)
    
            self.sport_motor = Motor(port=sport_motor_port,
                                     positive_direction=Direction.CLOCKWISE)
    
            self.color_sensor = ColorSensor(port=color_sensor_port)
    
            self.distance_sensor = UltrasonicSensor(port=distance_sensor_port)
    
    
    if __name__ == '__main__':
        TRICKY = Tricky()
    
        TRICKY.distance_sensor.lights.on(100)
    
        TRICKY.distance_sensor.lights.off()
    • You may omit #!/usr/bin/env pybricks-micropython. This was specific to ev3dev
    • I think it would be good to omit this as well:
                left_wheel_motor_port: Port = Port.A,
                right_wheel_motor_port: Port = Port.B,
                sport_motor_port: Port = Port.C,
                distance_sensor_port: Port = Port.D,
                color_sensor_port: Port = Port.E):

    Basically I think we can rely on the building instructions for cables/ports, just like we assume users have built the rest of the robot according to the instructions.

    • Within the class methods, it may be better to use regular arguments for required arguments, while using keyword arguments only for optional arguments. Sometimes, this makes the script a bit easier to read, and on these hubs it is also better for performance.
    • Omitting if __name__ == '__main__': would be fine as well.

    What do you think?

  5. laurensvalk commented on Aug 23, 2022

    @laurensvalk
    Member

    We've got a proof of concept where this works! If you want to give it a go:

    See pybricks/pybricks-micropython#115 for details.

  6. dlech commented on Oct 21, 2022

    @dlech
    Member

    This is now possible in both Pybricks Code Beta and pybricksdev. Both "magically" search for imports and include imports in the same directory as the main script when downloading and running.

  7. added theissue type on Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cool projecthub: primehub/inventorhub

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions