@@ -54,12 +54,12 @@ def start(self, speed=None):
5454 if not (speed >= - 100 and speed <= 100 ):
5555 raise MotorError ("Invalid Speed" )
5656 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 "
5858 self ._write (cmd )
5959
6060 def stop (self ):
6161 """Stop motor"""
62- cmd = "port {} ; off\r " . format ( self . port )
62+ cmd = f "port { self . port } ; off\r "
6363 self ._write (cmd )
6464 self ._currentspeed = 0
6565
@@ -71,7 +71,7 @@ def plimit(self, plimit):
7171 """
7272 if not (plimit >= 0 and plimit <= 1 ):
7373 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 " )
7575
7676 def bias (self , bias ):
7777 """Bias motor
@@ -81,7 +81,7 @@ def bias(self, bias):
8181 """
8282 if not (bias >= 0 and bias <= 1 ):
8383 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 " )
8585
8686
8787class MotorRunmode (Enum ):
@@ -192,8 +192,8 @@ def _run_positional_ramp(self, pos, newpos, speed):
192192 # Collapse speed range to -5 to 5
193193 speed *= 0.05
194194 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 " )
197197 self ._write (cmd )
198198 with self ._hat .rampcond [self .port ]:
199199 self ._hat .rampcond [self .port ].wait ()
@@ -248,8 +248,8 @@ def run_to_position(self, degrees, speed=None, blocking=True, direction="shortes
248248
249249 def _run_for_seconds (self , seconds , speed ):
250250 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 " )
253253 self ._write (cmd )
254254 with self ._hat .pulsecond [self .port ]:
255255 self ._hat .pulsecond [self .port ].wait ()
@@ -296,10 +296,10 @@ def start(self, speed=None):
296296 else :
297297 if not (speed >= - 100 and speed <= 100 ):
298298 raise MotorError ("Invalid Speed" )
299- cmd = "port {} ; set {}\r " . format ( self . port , speed )
299+ cmd = f "port { self . port } ; set { speed } \r "
300300 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 " )
303303 self ._runmode = MotorRunmode .FREE
304304 self ._currentspeed = speed
305305 self ._write (cmd )
@@ -372,7 +372,7 @@ def plimit(self, plimit):
372372 """
373373 if not (plimit >= 0 and plimit <= 1 ):
374374 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 " )
376376
377377 def bias (self , bias ):
378378 """Bias motor
@@ -382,7 +382,7 @@ def bias(self, bias):
382382 """
383383 if not (bias >= 0 and bias <= 1 ):
384384 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 " )
386386
387387 def pwm (self , pwmv ):
388388 """PWM motor
@@ -392,11 +392,11 @@ def pwm(self, pwmv):
392392 """
393393 if not (pwmv >= - 1 and pwmv <= 1 ):
394394 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 " )
396396
397397 def coast (self ):
398398 """Coast motor"""
399- self ._write ("port {} ; coast\r " . format ( self . port ) )
399+ self ._write (f "port { self . port } ; coast\r " )
400400
401401 def float (self ):
402402 """Float motor"""
0 commit comments