MCPcopy Create free account
hub / github.com/DexterInd/GoPiGo3 / set_speed

Function set_speed

Software/Scratch/GoPiGo3Scratch.py:811–834  ·  view source on GitHub ↗

change GoPigo3 speed where 300 is 50%, 700 is 100% and 100 is 10%

(regObj)

Source from the content-addressed store, hash-verified

809 return None
810
811def set_speed(regObj):
812 '''
813 change GoPigo3 speed where 300 is 50%, 700 is 100% and 100 is 10%
814 '''
815 if regObj.group(SPEED_GROUP_NEW_SPEED):
816 try:
817 new_speed = int(regObj.group(SPEED_GROUP_NEW_SPEED))
818 except Exception as e:
819 print("Set Speed: {}".format(e))
820
821 # put some cap onto the new speed values
822 if new_speed < 10 and new_speed > 0:
823 # 0 meeans stop but anything between 0 and 10 is a 10
824 new_speed = 10
825 if new_speed > 100:
826 new_speed = 100
827 # basic algebra to match 10-100 to 100-700 approximately
828 real_new_speed = (new_speed * 20 // 3) + 40
829 print ("percent speed is {}, actual speed is {}".format(new_speed, real_new_speed))
830 if new_speed == 0:
831 gpg.stop()
832 else:
833 gpg.set_speed(real_new_speed)
834 return None
835
836def turn_gpg(regObj):
837 ''&#x27;

Callers 1

handle_GoPiGo3_msgFunction · 0.85

Calls 2

set_speedMethod · 0.80
stopMethod · 0.45

Tested by

no test coverage detected