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: Inject into component __init__ #204

Merged
merged 1 commit into from
Feb 12, 2023
Merged

magicbot: Inject into component __init__ #204

merged 1 commit into from
Feb 12, 2023

Conversation

auscompgeek
Copy link
Member

See #21

A good motivating example could look something like the following:

class Vision:
	def __init__(self, name: str):
		self.camera = PhotonCamera(name)

	def execute(self): ...

class Robot(MagicRobot):
	vision: Vision

	def createObjects(self):
		self.vision_name = 'camera'

Of course, it could also be used like this, to make things less magic:

@dataclass
class Chassis:
	module_a: SwerveModule
	module_b: SwerveModule
	module_c: SwerveModule

	def __post_init__(self): ...

	def execute(self): ...

class Robot(MagicRobot):
	chassis: Chassis

	def createObjects(self):
		self.chassis_module_a = SwerveModule(...)
		self.chassis_module_b = SwerveModule(...)
		self.chassis_module_c = SwerveModule(...)

@auscompgeek auscompgeek added the magicbot magicbot package label Feb 8, 2023
Copy link
Member

@virtuald virtuald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
magicbot magicbot package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants