Skip to content

Commit

Permalink
Add async await syntax for set_position
Browse files Browse the repository at this point in the history
  • Loading branch information
jmblixt3 committed Oct 30, 2024
1 parent c71be3b commit e2670a8
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/digger/digger/digger_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,6 @@ def toggle(self, digger_belt_power: float) -> None:
else:
self.set_power(digger_belt_power)

def set_position(self, position: int) -> None:
"""This method sets the position (in degrees) of the digger."""
self.cli_motor_set.call_async(
MotorCommandSet.Request(
type="position",
can_id=self.DIGGER_LIFT_MOTOR,
value=float(position + self.lift_encoder_offset),
)
).result()

def stop_lift(self) -> None:
"""This method stops the lift."""
Expand Down Expand Up @@ -149,10 +140,16 @@ def toggle_callback(self, request, response):
response.success = 0 # indicates success
return response

def set_position_callback(self, request, response):
async def set_position_callback(self, request, response):
"""This service request sets the position of the lift."""
self.set_position(request.position)
# ^ this should already wait due to vesc set position not returning until done
"""This method sets the position (in degrees) of the digger."""
await self.cli_motor_set.call_async(
MotorCommandSet.Request(
type="position",
can_id=self.DIGGER_LIFT_MOTOR,
value=float(request.position + self.lift_encoder_offset),
)
)
response.success = 0 # indicates success
return response

Expand Down

0 comments on commit e2670a8

Please sign in to comment.