This part is for members
Membership opens soon. Leave your email and we'll tell you the day it does. Founding members get the launch price.
Keep watching the free partsMulti-turn 4: the second encoder behind the gearbox
Some joints carry a second encoder on the output, after the gearbox. Running example: the gim6010 header, two MT68xx encoders (2,097,152 counts a turn each) and an 8:1 gearbox; the joint is power-cycled at 200° and the host asks for 90°. Following the code: the header's ENCODER2_TYPE_OPTION names encoder 2 and PMSM_LOAD_ENC_DIR = 1 makes the driver mirror it; the driver hands it to ENCODER_ID_LOAD, PosSpeedLoopCtrl reads both counts every position tick, and load_pos_sensor adds the load count up with 12a's half-turn rule into the joint total. At power-up MotorCtlSmStateInit starts box 6 at turns × counts per turn = 0, and the load side's turns have only a TODO (every motor header gives the load encoder a multi-turn resolution of 0, so today that changes nothing): in the real run box 6 starts at 932,067 (0.444 of a turn) and the joint total at 1,165,084 (200°). With a load encoder, get_app_Position_actual_value_inc reports the joint total as it is, so the host reads 200° right at power-up with no homing (12c's division would say 20°, worked out from the code). Box 6 and the joint are 4 motor turns apart and the position loop still runs on box 6, so PP and CSP move by the distance measured at the joint: (target − reading) × 8 × P_load_2_motor, added to box 6 as it is, redone every tick; the real run aims at −4,194,302 and the joint stops at 90.01°. The backlash GEAR_BACKLASH_MOTOR_PULSE is 1,398 motor counts: with less than that left the loop holds where it is, and the joint stops 0.013° past 90°. Homing's Index comes from the joint encoder's zero crossing: from 200° to 400° it comes on once while box 6 crosses 4 turns (→ episode 25). A real bug: a joint powered up below 180° reads one turn too many (150° reads 510°, and a move to 90° really turns 420° to −270°): the first tick copies an empty receive buffer, the all-zero frame passes the MT68xx CRC (11d), the self-test takes the mirrored 2,097,151 as the start, the load input is never set, and load_pos_sensor counts an extra turn; fixed on the fork's branch fix/selftest-empty-encoder-frame (patched run: reads 150°, moves 60° to 90.01°). Your turn: power up at 330°, ask for 30°.