lerobot icon indicating copy to clipboard operation
lerobot copied to clipboard

calibration failed : ValueError: Magnitude 2114 exceeds 2047 (max for sign_bit_index=11)

Open FaboNo opened this issue 7 months ago • 7 comments

System Info

I followed the instruction  to create the environment with miniconda.

I numbered the motors with the corresponding script but when I wanted to start the calibration - for the follower- i had the following error:


file:///home/fabrice/Images/s101_error.png

Is there a script to read the position of each motor ?

Information

  • [x] One of the scripts in the examples/ folder of LeRobot
  • [ ] My own task or dataset (give details below)

Reproduction

Each time I start the calibration script

Expected behavior

Should be like in the video tutorial - an array with the motor and its position

FaboNo avatar Jun 14 '25 13:06 FaboNo

Hello there,

we had the same issue. Can you roll back a few commits ( like 20 ) and see if that solves the problem.

Good luck,

A.

andysign avatar Jun 14 '25 18:06 andysign

Could you paste here your full stack trace?

aliberts avatar Jun 15 '25 02:06 aliberts

Hello, you mean this one:

(lerobot) fabrice@fabrice-XMG:~/lerobot$ python -m lerobot.calibrate --robot.type=so101_follower --robot.port=/dev/ttyACM0 --robot.id=follower
Move follower SO101Follower to the middle of its range of motion and press ENTER....
Traceback (most recent call last):
  File "/home/fabrice/miniconda3/envs/lerobot/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/fabrice/miniconda3/envs/lerobot/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/fabrice/lerobot/lerobot/calibrate.py", line 84, in <module>
    calibrate()
  File "/home/fabrice/miniconda3/envs/lerobot/lib/python3.10/site-packages/draccus/argparsing.py", line 225, in wrapper_inner
    response = fn(cfg, *args, **kwargs)
  File "/home/fabrice/lerobot/lerobot/calibrate.py", line 79, in calibrate
    device.calibrate()
  File "/home/fabrice/lerobot/lerobot/common/robots/so101_follower/so101_follower.py", line 114, in calibrate
    homing_offsets = self.bus.set_half_turn_homings()
  File "/home/fabrice/lerobot/lerobot/common/motors/motors_bus.py", line 714, in set_half_turn_homings
    self.write("Homing_Offset", motor, offset)
  File "/home/fabrice/lerobot/lerobot/common/motors/motors_bus.py", line 1019, in write
    value = self._encode_sign(data_name, {id_: value})[id_]
  File "/home/fabrice/lerobot/lerobot/common/motors/feetech/feetech.py", line 317, in _encode_sign
    ids_values[id_] = encode_sign_magnitude(ids_values[id_], sign_bit)
  File "/home/fabrice/lerobot/lerobot/common/utils/encoding_utils.py", line 23, in encode_sign_magnitude
    raise ValueError(f"Magnitude {magnitude} exceeds {max_magnitude} (max for {sign_bit_index=})")
ValueError: Magnitude 2114 exceeds 2047 (max for sign_bit_index=11)

FaboNo avatar Jun 15 '25 09:06 FaboNo

Thanks. I'm not sure what's going on as it's difficult to reproduce. This error basically says that it's trying to write a value higher than what's allowed by that motor's register (for the homing offset). Did you try multiple times and get the same error each time?

aliberts avatar Jun 15 '25 12:06 aliberts

Ah yes this time it works and I was able to calibrate the follower. BUT now confident it work smoothly for the leader I got the message (I was too confident) below. Looks like that you want the same fimrware version for all servos. I am used to Robotis dynamixel environment and updating the firmware is easy. Here with this company, it is clearly painful - I found the exe to read the servos but I cannot find where the version of the firmware are stored, do you have any hint? Thank you very much

lerobot) fabrice@fabrice-XMG:~/lerobot$ python -m lerobot.calibrate --teleop.type=so101_leader --teleop.port=/dev/ttyACM0 --teleop.id=leader
Traceback (most recent call last):
  File "/home/fabrice/miniconda3/envs/lerobot/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/fabrice/miniconda3/envs/lerobot/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/fabrice/lerobot/lerobot/calibrate.py", line 84, in <module>
    calibrate()
  File "/home/fabrice/miniconda3/envs/lerobot/lib/python3.10/site-packages/draccus/argparsing.py", line 225, in wrapper_inner
    response = fn(cfg, *args, **kwargs)
  File "/home/fabrice/lerobot/lerobot/calibrate.py", line 78, in calibrate
    device.connect(calibrate=False)
  File "/home/fabrice/lerobot/lerobot/common/teleoperators/so101_leader/so101_leader.py", line 73, in connect
    self.bus.connect()
  File "/home/fabrice/lerobot/lerobot/common/motors/motors_bus.py", line 436, in connect
    self._connect(handshake)
  File "/home/fabrice/lerobot/lerobot/common/motors/motors_bus.py", line 445, in _connect
    self._handshake()
  File "/home/fabrice/lerobot/lerobot/common/motors/feetech/feetech.py", line 168, in _handshake
    self._assert_same_firmware()
  File "/home/fabrice/lerobot/lerobot/common/motors/feetech/feetech.py", line 159, in _assert_same_firmware
    raise RuntimeError(
RuntimeError: Some Motors use different firmware versions:
{1: '3.9', 2: '3.10', 3: '3.9', 4: '3.9', 5: '3.10', 6: '3.9'}
Update their firmware first using Feetech's software. Visit https://www.feetechrc.com/software.

FaboNo avatar Jun 15 '25 13:06 FaboNo

This has happened to me too; to fix I first wrapped this line in a try-catch with a log statment to know which motor the issue was coming from:

      try:
          ids_values[id_] = encode_sign_magnitude(ids_values[id_], sign_bit)
      except ValueError as e:
          logger.error(f"Error encoding sign for motor {id_}: {e}")
          raise

Then I restarted the calibration, moving that motor away from the mid-point towards on the extremes, to get the first enter hit to pass. Once it did, I restarted the calibration, this time putting all motors at their mid-point, and that time it worked.

afallou avatar Jun 15 '25 14:06 afallou

@afallou that help, i disconnected the motor and re-connecting it and it fiexed the problem.

zzarbi avatar Jun 22 '25 00:06 zzarbi

I encountered the same issue, just unplugging the AC adapter and plugging it back fixed the problem for me.

nxu96 avatar Jun 23 '25 03:06 nxu96

I've faced the same issue after upgrading the STS3215's firmware, but re-connecting the AC adapter solved the problem.

Tiryoh avatar Jun 23 '25 19:06 Tiryoh

Hello, you mean this one:

(lerobot) fabrice@fabrice-XMG:~/lerobot$ python -m lerobot.calibrate --robot.type=so101_follower --robot.port=/dev/ttyACM0 --robot.id=follower
Move follower SO101Follower to the middle of its range of motion and press ENTER....
Traceback (most recent call last):
  File "/home/fabrice/miniconda3/envs/lerobot/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/fabrice/miniconda3/envs/lerobot/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/fabrice/lerobot/lerobot/calibrate.py", line 84, in <module>
    calibrate()
  File "/home/fabrice/miniconda3/envs/lerobot/lib/python3.10/site-packages/draccus/argparsing.py", line 225, in wrapper_inner
    response = fn(cfg, *args, **kwargs)
  File "/home/fabrice/lerobot/lerobot/calibrate.py", line 79, in calibrate
    device.calibrate()
  File "/home/fabrice/lerobot/lerobot/common/robots/so101_follower/so101_follower.py", line 114, in calibrate
    homing_offsets = self.bus.set_half_turn_homings()
  File "/home/fabrice/lerobot/lerobot/common/motors/motors_bus.py", line 714, in set_half_turn_homings
    self.write("Homing_Offset", motor, offset)
  File "/home/fabrice/lerobot/lerobot/common/motors/motors_bus.py", line 1019, in write
    value = self._encode_sign(data_name, {id_: value})[id_]
  File "/home/fabrice/lerobot/lerobot/common/motors/feetech/feetech.py", line 317, in _encode_sign
    ids_values[id_] = encode_sign_magnitude(ids_values[id_], sign_bit)
  File "/home/fabrice/lerobot/lerobot/common/utils/encoding_utils.py", line 23, in encode_sign_magnitude
    raise ValueError(f"Magnitude {magnitude} exceeds {max_magnitude} (max for {sign_bit_index=})")
ValueError: Magnitude 2114 exceeds 2047 (max for sign_bit_index=11)

got the same issue when i do the leader arms calibration. but it works fine with follower arms.

bluebirdlboro avatar Jun 25 '25 01:06 bluebirdlboro

i have git checkout to earlier commit 4e4eec92dcc4ab4476c7c399b47678926b111ed9 it still failed. but after I unplug the cable and reconnect it again. the leader calibrate script works...

And then....I got the error message below...... then i tried again.....it finally worked

(lerobot) MacBook-2:lerobot bluebird$ python -m lerobot.calibrate --teleop.type=so101_leader --teleop.port=/dev/tty.usbmodem5A680088281 --teleop.id=anan_leader_arm Move anan_leader_arm SO101Leader to the middle of its range of motion and press ENTER.... Move all joints sequentially through their entire ranges of motion. Recording positions. Press ENTER to stop...


NAME | MIN | POS | MAX shoulder_pan | 2047 | 2295 | 2296 shoulder_lift | 2047 | 3136 | 3148 elbow_flex | 952 | 1098 | 2048 wrist_flex | 2047 | 2091 | 4368 wrist_roll | 144 | 152 | 3953 gripper | 2039 | 2046 | 2047 Traceback (most recent call last): File "/Users/bluebird/miniconda3/envs/lerobot/lib/python3.10/runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "/Users/bluebird/miniconda3/envs/lerobot/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) File "/Users/bluebird/compile_install/lerobot/lerobot/calibrate.py", line 84, in calibrate() File "/Users/bluebird/miniconda3/envs/lerobot/lib/python3.10/site-packages/draccus/argparsing.py", line 228, in wrapper_inner response = fn(cfg, *args, **kwargs) File "/Users/bluebird/compile_install/lerobot/lerobot/calibrate.py", line 79, in calibrate device.calibrate() File "/Users/bluebird/compile_install/lerobot/lerobot/common/teleoperators/so101_leader/so101_leader.py", line 97, in calibrate (lerobot) MacBook-2:lerobot bluebird$ File "/Users/bluebird/compile_install/lerobot/lerobot/common/motors/motors_bus.py", line 752, in record_ranges_of_motion positions = self.sync_read("Present_Position", motors, normalize=False) File "/Users/bluebird/compile_install/lerobot/lerobot/common/motors/motors_bus.py", line 1089, in sync_read ids_values, _ = self._sync_read( File "/Users/bluebird/compile_install/lerobot/lerobot/common/motors/motors_bus.py", line 1121, in _sync_read raise ConnectionError(f"{err_msg} {self.packet_handler.getTxRxResult(comm)}") ConnectionError: Failed to sync read 'Present_Position' on ids=[1, 2, 3, 4, 5, 6] after 1 tries. [TxRxResult] There is no status packet!

bluebirdlboro avatar Jun 25 '25 04:06 bluebirdlboro

Are there any other solutions? Unplugging AC does not work

gribok201 avatar Aug 04 '25 15:08 gribok201

For folks having similar issues: It might be due to the servo encoder overflow. If you are using feetech one, you can download the debug software from their website: https://www.feetechrc.com/software.html (FD 1.9.8.3). Attached are the parameters to connect to the servo. Click search, servo will pop up in the listr. Unmount your motor, and adjust the slider bar to around center position and then remount. The do the calibration error should be gone.

Image

mertonmeng avatar Aug 07 '25 03:08 mertonmeng

A solution that fixed my issue was to use the link above: https://www.feetechrc.com/software.html to download the debug software. The software worked on a Windows machine, but it did not work for my MacBook. Connect to the servos and select them one by one using the commands above. Click the Programming tab and set the torque enable option to 128. After this, rerun the calibrate script. You may have to do this for each servo if it doesn't fix it.

Coded190 avatar Sep 27 '25 02:09 Coded190

Hi @mertonmeng and @Coded190,

Thank you for your help and answers on this calibration issue. I believe the error was caused by an assembly error : if the servos should be assembled in the zero position, but it's hard to tell on Feetech's servos.

In cas you'd prefer to stay on MacOS/Linux to debug the motors, you can check the tools provided at the end of this doc : https://huggingface.co/docs/lerobot/feetech

Best,

Caroline.

CarolinePascal avatar Sep 29 '25 11:09 CarolinePascal

FWIW I had this issue, and what ended up solving it for me was unplugging both USB and AC power, and then moving the affected motors to their home position. While holding them in the home position, plugging back in USB and AC power. I don't know if this is just wishful thinking but that seemed to do the trick. Simply unplugging the AC power or AC + USB many times didn't work. Here's a diff I made as well just to print out the affected motor.

diff --git a/src/lerobot/motors/feetech/feetech.py b/src/lerobot/motors/feetech/feetech.py
index 88d45ba3..133f6c81 100644
--- a/src/lerobot/motors/feetech/feetech.py
+++ b/src/lerobot/motors/feetech/feetech.py
@@ -315,7 +315,10 @@ class FeetechMotorsBus(MotorsBus):
             encoding_table = self.model_encoding_table.get(model)
             if encoding_table and data_name in encoding_table:
                 sign_bit = encoding_table[data_name]
-                ids_values[id_] = encode_sign_magnitude(ids_values[id_], sign_bit)
+                try:
+                    ids_values[id_] = encode_sign_magnitude(ids_values[id_], sign_bit)
+                except ValueError as error:
+                    print(f"Failed to calibrate motor {id_}: {error}")
 
         return ids_values
 

mklingen avatar Oct 04 '25 10:10 mklingen

Hi @mklingen,

Thank you for sharing this addition to the _encode_sign method, I think this could be a nice PR ! If you are willing to open a PR, could you turn your print statement into a ValueError and replace Failed to calibrate motor {id_}: by a more generic message displaying id_ as well as data_name (e.g. Failed to encode sign for motor ... with data ...) ? Thanks !

Best,

Caroline.

CarolinePascal avatar Oct 06 '25 15:10 CarolinePascal

Hi all, I also ran into this issue while trying to calibrate a SO-101 arm. What fixed it for me was:

  1. Follow instructions on https://huggingface.co/docs/lerobot/en/feetech through Step 4: Scan for Motors, stop before Step 5.
  2. Select the Programming tab.
  3. Move ALL joints to the middle of their range; for me it looks like an upside-down L with the gripper/thumb thing half "open".
  4. Click Offset.
Image

This seems to set all the current servo positions as the positional midpoint in the Debug view. Before doing this, one of the servos scrolled off the top of the graph on one end of its movement. I'm new to all this though, so hopefully my guess is correct. :) I had access to a Windows machine, it's possible this could be accomplished with the Feetech Debug Tool as well?

williamito avatar Oct 08 '25 23:10 williamito

Hi @williamito,

Nice discovery, thanks ! This is way easier than disassembling all the servos with shifted zero positions ;) I assume this button must set the current value of the encoder to 0, so you don't have the exceeding value error anymore.

It would be a nice addition to our doc about fetch motors if you feel like opening a PR !

Best,

Caroline,

CarolinePascal avatar Oct 20 '25 03:10 CarolinePascal

Encoutered the same issue just unpluged the adapter and conneted back as @nxu96 suggested and issue has been resolved.

mortezaadi avatar Oct 30 '25 17:10 mortezaadi