Tower
TowerControl
Gamecontroll Stepper
Attributes:
Name | Type | Description |
---|---|---|
start_position |
int |
set Rocking Stepper in center position |
max_interval |
float |
max stepping time for Rotate Stepper |
min_interval |
float |
min stepping time for Rotate Stepper |
max_rock_interval |
float |
max stepping time for Rock Stepper |
min_rock_interval |
float |
min stepping time for Rock Stepper |
__init__(self)
special
Initialize Rock and Rotate Stepper
Source code in controls/tower.py
def __init__(self):
"""
Initialize Rock and Rotate Stepper
"""
self.rock_stepper = EncoderStepperHAL("Rock Stepper",1)
self.rotate_stepper = StepperHAL("Rotate Stepper",2)
game_run(self)
Mapping attributes to rotate() and rock()
Source code in controls/tower.py
def game_run(self):
"""
Mapping attributes to rotate() and rock()
"""
stepper1_start_dir=random.randint(1, 2)
if stepper1_start_dir==1:
self.rock_stepper.direction=STEPPER.FORWARD
else:
self.rock_stepper.direction=STEPPER.BACKWARD
self._rock_task = asyncio.create_task(self.rock_stepper.rock()) #stepper1
self._rotate_task = asyncio.create_task(self.rotate_stepper.rotate()) #stepper2
self._algo_task = asyncio.create_task(self._run(0.5))
get_score(self)
async
!!! Deprecated !!!
Control depending on the score
Source code in controls/tower.py
async def get_score(self):
"""
!!! Deprecated !!!
Control depending on the score
"""
if self.total_score<self._score_goal:
self.total_score=self.total_score+1
await asyncio.sleep(3)
else:
self.total_score=0
return self.total_score
on_exit(self)
async
Reset position Threading stop, motor_release via atexit register
Source code in controls/tower.py
async def on_exit(self):
"""
Reset position
Threading stop, motor_release via atexit register
"""
await self.game_stop()
self.rock_stepper.close() #todo:::::::::::: check hal.close
self.rotate_stepper.close()
set_score(self, score, max_score)
Set total score and max score for the rotation algorithm
Source code in controls/tower.py
def set_score(self, score, max_score):
"""
Set total score and max score for the rotation algorithm
"""
self._total_score = score
self._score_goal = max_score
self.rotate_stepper.interval, self.rotate_stepper.direction = self._rotate_algo()
set_start_position(self)
async
Set start position at initialisation and after each game round. Current version: uses stopper to determine middle_position
Source code in controls/tower.py
async def set_start_position(self):
"""
Set start position at initialisation and after each game round.
Current version: uses stopper to determine middle_position
"""
#self.stepper1.set_position(self.start_position) #without stopper; used init value start_position
await self.rock_stepper.calibrate() #with stopper