Skip to content

Commit

Permalink
Exposed enable_12v and enable_5v
Browse files Browse the repository at this point in the history
Also added an enabled_5v value that is tracked within green giant
similar to the exisiting enabled_12v
  • Loading branch information
MostlyTurquoise committed Nov 18, 2023
1 parent c32134c commit 8dd3318
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions robot/greengiant.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def __init__(self, bus):
self._bus = bus
self._version = self.get_version()
self.enabled_12v = False
self.enabled_5v = False
self.set_motor_power(self.enabled_12v)

def enable_motors(self,new_state):
Expand Down Expand Up @@ -222,6 +223,7 @@ def set_5v_acc_power(self, new_state):
# for GG this is always on, perhaps we should IOerror, for now just ignore
# this is likely only ever used internally
self._bus.write_byte_data(_GG_I2C_ADDR, _GG_ENABLE_5V_ACC, int(new_state))
self.enabled_5v = new_state



Expand Down
29 changes: 24 additions & 5 deletions robot/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def __init__(self,
wait_for_start=True,
camera=None,
max_motor_voltage=6,
logging_level=logging.INFO):
logging_level=logging.INFO,
start_enable_12v = True,
start_enable_5v = True,
):

self.zone = marker_setup.TEAM.RUSSET
self.mode = "competition"
Expand All @@ -84,7 +87,7 @@ def __init__(self,
except IOError:
pass

self.subsystem_init(camera)
self.subsystem_init(camera, start_enable_12v, start_enable_5v)
self.report_hardware_status()
self.enable_12v = True
type(self)._initialised = True
Expand All @@ -101,7 +104,7 @@ def __init__(self,
"`robot.wait_start`. Robot will not wait for the "
"start button until `robot.wait_start` is called.")

def subsystem_init(self, camera):
def subsystem_init(self, camera, start_enable_12v, start_enable_5v):
"""Allows for initalisation of subsystems after instansating `Robot()`
Can only be called once"""
if type(self)._initialised:
Expand All @@ -114,8 +117,8 @@ def subsystem_init(self, camera):
if self._gg_version >= 10:
# enable power rails
self._green_giant.set_motor_power(True)
self._green_giant.set_12v_acc_power(True) # Not sure, should this be controlled by user?
self._green_giant.set_5v_acc_power(True)
self._green_giant.set_12v_acc_power(start_enable_12v) # Not sure, should this be controlled by user?
self._green_giant.set_5v_acc_power(start_enable_5v)
self._adc_max = 5
# configure User IO Ports
self.servos = GreenGiantGPIOPinList(self.bus, self._gg_version, self._adc_max, _GG_SERVO_GPIO_BASE, _GG_SERVO_PWM_BASE)
Expand Down Expand Up @@ -211,6 +214,22 @@ def enable_motors(self, on):
"""An nice alias for set_12v"""
if self._version < 10:
return self._green_giant.enable_motors(on)

@property
def enable_12v(self):
return self._green_giant.enabled_12v

@enable_12v.setter
def enable_12v(self, on):
self._green_giant.set_12v_acc_power(on)

@property
def enable_5v(self):
return self._green_giant.enabled_5v

@enable_5v.setter
def enable_5v(self, on):
self._green_giant.set_5v_acc_power(on)

def stop(self):
"""Stops the robot and cuts power to the motors.
Expand Down

0 comments on commit 8dd3318

Please sign in to comment.