reset the encoders or go to a specific position
(regObj)
| 682 | |
| 683 | |
| 684 | def 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 | |
| 728 | def GoPiGo3_reset(): |
no test coverage detected