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

Function handle_encoders

Software/Scratch/GoPiGo3Scratch.py:684–725  ·  view source on GitHub ↗

reset the encoders or go to a specific position

(regObj)

Source from the content-addressed store, hash-verified

682
683
684def handle_encoders(regObj):
685 '''
686 reset the encoders or go to a specific position
687 '''
688 sensors = {}
689 # ask for an encode reset, either just one side, or both
690 if regObj.group(ENCODER_RESET_GROUP):
691 # print("encoder resetting")
692 # if the right encoder wasn't specified, then it's either
693 # a left reset or both.
694 if regObj.group(ENCODER_RIGHT_GROUP)==None and \
695 regObj.group(ENCODER_RIGHT2_GROUP)==None:
696 # print("resetting left encoder")
697 gpg.set_motor_power(gpg.MOTOR_LEFT, 0)
698 gpg.offset_motor_encoder(gpg.MOTOR_LEFT,
699 gpg.get_motor_encoder(gpg.MOTOR_LEFT))
700 # if the left encoder wasn't specified, then it's either
701 # the right or both
702 if regObj.group(ENCODER_LEFT_GROUP)==None and \
703 regObj.group(ENCODER_LEFT2_GROUP)==None:
704 # print("resetting right encoder")
705 gpg.set_motor_power(gpg.MOTOR_RIGHT, 0)
706 gpg.offset_motor_encoder(gpg.MOTOR_RIGHT,
707 gpg.get_motor_encoder(gpg.MOTOR_RIGHT))
708 # ask for a specific position
709 if regObj.group(ENCODER_VALUE_GROUP):
710 # if the right encoder wasn't specified, then it's either
711 # a left reset or both.
712 if regObj.group(ENCODER_RIGHT_GROUP)==None and \
713 regObj.group(ENCODER_RIGHT2_GROUP)==None:
714 gpg.set_motor_position(gpg.MOTOR_LEFT,
715 int(regObj.group(ENCODER_VALUE_GROUP)))
716 # if the left encoder wasn't specified, then it's either
717 # the right or both
718 if regObj.group(ENCODER_LEFT_GROUP)==None and \
719 regObj.group(ENCODER_LEFT2_GROUP)==None:
720 gpg.set_motor_position(gpg.MOTOR_RIGHT,
721 int(regObj.group(ENCODER_VALUE_GROUP)))
722 # done for every code path, but most notable for ENCODER READ
723 sensors["Encoder Left"] = gpg.get_motor_encoder(gpg.MOTOR_LEFT)
724 sensors["Encoder Right"] = gpg.get_motor_encoder(gpg.MOTOR_RIGHT)
725 return(sensors)
726
727
728def GoPiGo3_reset():

Callers 1

handle_GoPiGo3_msgFunction · 0.85

Calls 4

set_motor_powerMethod · 0.45
offset_motor_encoderMethod · 0.45
get_motor_encoderMethod · 0.45
set_motor_positionMethod · 0.45

Tested by

no test coverage detected