Skip to content

Commit 06b3ebc

Browse files
author
sam
committed
Some small improvements to the MotorConnector
1 parent c401c58 commit 06b3ebc

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

source/ev3dev2/motor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def __init__(self, address=None, name_pattern=SYSTEM_DEVICE_NAME_CONVENTION, nam
407407
self.max_dps = self.max_rps * 360
408408
self.max_dpm = self.max_rpm * 360
409409

410-
self.connector = MotorConnector(self.address)
410+
self.connector = MotorConnector(self.address, self.max_speed)
411411
self.running_until = time.time()
412412

413413

@@ -864,7 +864,7 @@ def run_direct(self):
864864

865865
self.command = self.COMMAND_RUN_DIRECT
866866

867-
self.connector.set_stop_action(self.STOP_ACTION_BRAKE)
867+
self.connector.set_stop_action(self.STOP_ACTION_HOLD)
868868
self.connector.stop()
869869

870870
run_time = self.connector.run_direct()

source/ev3dev2/simulator/connector/MotorCommandCreator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def create_drive_command(self, speed: float, distance: float, stop_action: str,
2828
Create the command required to rotate the motor at the address for a distance at a speed.
2929
:param speed: in degrees per second.
3030
:param distance: in degrees.
31-
:param stop_action: of the motor, this can be 'hold' or 'coast'.
31+
:param stop_action: of the motor, this can be 'hold', 'break' or 'coast'.
3232
:param address: of the motor to create a command for.
3333
"""
3434

@@ -49,7 +49,7 @@ def create_stop_command(self, speed: float, stop_action: str, address: str) -> f
4949
"""
5050
Create the command required to stop the motor at the address.
5151
:param speed: in degrees per second the motor is traveling when stopped.
52-
:param stop_action: of the motor, this can be 'hold' or 'coast'.
52+
:param stop_action: of the motor, this can be 'hold', 'break' or 'coast'.
5353
:param address: of the motor to create a stop command for.
5454
"""
5555

source/ev3dev2/simulator/connector/MotorConnector.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ class MotorConnector:
1212
"""
1313

1414

15-
def __init__(self, address: str):
15+
def __init__(self, address: str, max_speed: int):
1616
self.address = address
17+
self.max_speed = max_speed
1718

1819
self.duty_cycle = None
1920
self.speed = None
@@ -110,7 +111,7 @@ def run_direct(self) -> float:
110111
the given run operation will take.
111112
"""
112113

113-
self.speed = self.duty_cycle / 100 * 1050
114+
self.speed = self.duty_cycle / 100 * self.max_speed
114115
self.distance = self.speed * FOREVER_MOCK_SECONDS
115116

116117
return self._run()
@@ -140,7 +141,7 @@ def stop(self) -> float:
140141
"""
141142

142143
speed = self.speed if self.speed else 0
143-
stop_action = self.stop_action if self.stop_action else 0
144+
stop_action = self.stop_action if self.stop_action else 'hold'
144145
distance = self.distance if self.distance else 0
145146

146147
if speed == 0:

0 commit comments

Comments
 (0)