@@ -54,12 +54,12 @@ def start(self, speed=None):
54
54
if not (speed >= - 100 and speed <= 100 ):
55
55
raise MotorError ("Invalid Speed" )
56
56
self ._currentspeed = speed
57
- cmd = "port {} ; pwm ; set {} \r " . format ( self . port , speed / 100 )
57
+ cmd = f "port { self . port } ; pwm ; set { speed / 100 } \r "
58
58
self ._write (cmd )
59
59
60
60
def stop (self ):
61
61
"""Stop motor"""
62
- cmd = "port {} ; off\r " . format ( self . port )
62
+ cmd = f "port { self . port } ; off\r "
63
63
self ._write (cmd )
64
64
self ._currentspeed = 0
65
65
@@ -71,7 +71,7 @@ def plimit(self, plimit):
71
71
"""
72
72
if not (plimit >= 0 and plimit <= 1 ):
73
73
raise MotorError ("plimit should be 0 to 1" )
74
- self ._write ("port {} ; plimit {}\r " . format ( self . port , plimit ) )
74
+ self ._write (f "port { self . port } ; plimit { plimit } \r " )
75
75
76
76
def bias (self , bias ):
77
77
"""Bias motor
@@ -81,7 +81,7 @@ def bias(self, bias):
81
81
"""
82
82
if not (bias >= 0 and bias <= 1 ):
83
83
raise MotorError ("bias should be 0 to 1" )
84
- self ._write ("port {} ; bias {}\r " . format ( self . port , bias ) )
84
+ self ._write (f "port { self . port } ; bias { bias } \r " )
85
85
86
86
87
87
class MotorRunmode (Enum ):
@@ -192,8 +192,8 @@ def _run_positional_ramp(self, pos, newpos, speed):
192
192
# Collapse speed range to -5 to 5
193
193
speed *= 0.05
194
194
dur = abs ((newpos - pos ) / speed )
195
- cmd = "port {}; combi 0 1 0 2 0 3 0 ; select 0 ; pid {} 0 1 s4 0.0027777778 0 5 0 .1 3 ; set ramp {} {} {} 0 \r " . format (
196
- self . port , self . port , pos , newpos , dur )
195
+ cmd = ( f "port { self . port } ; combi 0 1 0 2 0 3 0 ; select 0 ; pid { self . port } 0 1 s4 0.0027777778 0 5 0 .1 3 ; "
196
+ f"set ramp { pos } { newpos } { dur } 0 \r " )
197
197
self ._write (cmd )
198
198
with self ._hat .rampcond [self .port ]:
199
199
self ._hat .rampcond [self .port ].wait ()
@@ -248,8 +248,8 @@ def run_to_position(self, degrees, speed=None, blocking=True, direction="shortes
248
248
249
249
def _run_for_seconds (self , seconds , speed ):
250
250
self ._runmode = MotorRunmode .SECONDS
251
- cmd = "port {} ; combi 0 1 0 2 0 3 0 ; select 0 ; pid {} 0 0 s1 1 0 0.003 0.01 0 100; set pulse {} 0.0 {} 0 \r " . format (
252
- self . port , self . port , speed , seconds )
251
+ cmd = ( f "port { self . port } ; combi 0 1 0 2 0 3 0 ; select 0 ; pid { self . port } 0 0 s1 1 0 0.003 0.01 0 100; "
252
+ f"set pulse { speed } 0.0 { seconds } 0 \r " )
253
253
self ._write (cmd )
254
254
with self ._hat .pulsecond [self .port ]:
255
255
self ._hat .pulsecond [self .port ].wait ()
@@ -296,10 +296,10 @@ def start(self, speed=None):
296
296
else :
297
297
if not (speed >= - 100 and speed <= 100 ):
298
298
raise MotorError ("Invalid Speed" )
299
- cmd = "port {} ; set {}\r " . format ( self . port , speed )
299
+ cmd = f "port { self . port } ; set { speed } \r "
300
300
if self ._runmode == MotorRunmode .NONE :
301
- cmd = "port {} ; combi 0 1 0 2 0 3 0 ; select 0 ; pid {} 0 0 s1 1 0 0.003 0.01 0 100; set {} \r " . format (
302
- self . port , self . port , speed )
301
+ cmd = ( f "port { self . port } ; combi 0 1 0 2 0 3 0 ; select 0 ; pid { self . port } 0 0 s1 1 0 0.003 0.01 0 100; "
302
+ f"set { speed } \r " )
303
303
self ._runmode = MotorRunmode .FREE
304
304
self ._currentspeed = speed
305
305
self ._write (cmd )
@@ -372,7 +372,7 @@ def plimit(self, plimit):
372
372
"""
373
373
if not (plimit >= 0 and plimit <= 1 ):
374
374
raise MotorError ("plimit should be 0 to 1" )
375
- self ._write ("port {} ; plimit {}\r " . format ( self . port , plimit ) )
375
+ self ._write (f "port { self . port } ; plimit { plimit } \r " )
376
376
377
377
def bias (self , bias ):
378
378
"""Bias motor
@@ -382,7 +382,7 @@ def bias(self, bias):
382
382
"""
383
383
if not (bias >= 0 and bias <= 1 ):
384
384
raise MotorError ("bias should be 0 to 1" )
385
- self ._write ("port {} ; bias {}\r " . format ( self . port , bias ) )
385
+ self ._write (f "port { self . port } ; bias { bias } \r " )
386
386
387
387
def pwm (self , pwmv ):
388
388
"""PWM motor
@@ -392,11 +392,11 @@ def pwm(self, pwmv):
392
392
"""
393
393
if not (pwmv >= - 1 and pwmv <= 1 ):
394
394
raise MotorError ("pwm should be -1 to 1" )
395
- self ._write ("port {} ; pwm ; set {}\r " . format ( self . port , pwmv ) )
395
+ self ._write (f "port { self . port } ; pwm ; set { pwmv } \r " )
396
396
397
397
def coast (self ):
398
398
"""Coast motor"""
399
- self ._write ("port {} ; coast\r " . format ( self . port ) )
399
+ self ._write (f "port { self . port } ; coast\r " )
400
400
401
401
def float (self ):
402
402
"""Float motor"""
0 commit comments