ccourson / xArmServoController

LewanSoul-Lobot-HiWonder 6-DOF xArm servo controller libraries
https://ccourson.github.io/xArmServoController/
MIT License
63 stars 30 forks source link

List index out of range Index error when getting servo position #5

Open abkeble opened 2 years ago

abkeble commented 2 years ago

I am using xarm to try and control my LeArm 6-DOF robotic arm via a USB connection. I am running on a Windows 10 machine and have pip installed the xarm library, and the libapi library. I am able to connect to the arm and print out the serial number. However when I try and get the position of one of the servos (it doesn't matter which one) I get the following error:

Traceback (most recent call last): File "C:\Users\aaron\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\aaron\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "c:\Users\aaron.vscode\extensions\ms-python.python-2022.4.1\pythonFiles\lib\python\debugpy__main.py", line 45, in cli.main() File "c:\Users\aaron.vscode\extensions\ms-python.python-2022.4.1\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
run() File "c:\Users\aaron.vscode\extensions\ms-python.python-2022.4.1\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file runpy.run_path(target_as_str, run_name=compat.force_str("
main__")) File "C:\Users\aaron\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path return _run_module_code(code, init_globals, run_name, File "C:\Users\aaron\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 97, in _run_module_code _run_code(code, mod_globals, init_globals, File "C:\Users\aaron\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "c:\Users\aaron\Documents\SeatSpy\GitHubRepos\robot-arm\main.py", line 7, in position = arm.getPosition(1) File "c:\Users\aaron\Documents\SeatSpy\GitHubRepos\robot-arm\venv\lib\site-packages\xarm\controller.py", line 91, in getPosition data = self._recv(self.CMD_GET_SERVO_POSITION) File "c:\Users\aaron\Documents\SeatSpy\GitHubRepos\robot-arm\venv\lib\site-packages\xarm\controller.py", line 174, in _recv if self._input_report[0] == self.SIGNATURE and self._input_report[1] == self.SIGNATURE and self._input_report[3] == cmd: IndexError: list index out of range

The code I am attempting to run is as follows:

import xarm

arm = xarm.Controller('USB')

servo1 = xarm.Servo(1)

position = arm.getPosition(1)
print('Servo 1 position:', position)

I have inspected the self._input_report variable and it is set to an empty list

Any help would be appreciated!

Additionally, I am also confused about how the setPosition function works, when I pass an angle of 0.0 the servo moves to its minimum value, and when I set 125.0 (which seems to be the max value from the docs) the servo only moves about 45 degrees from the 0.0 position, and any negative value I pass does nothing. Is there something I am misunderstanding, why can't I get the full range of motion for the servos?

Seferovic8 commented 9 months ago

I have the same problem, Did you find a solution?

Mcneelsh commented 7 months ago

@Seferovic8 @abkeble Did either of you ever find a solution?

abkeble commented 7 months ago

@Mcneelsh I never found a solution to this unfortunately.

Seferovic8 commented 7 months ago

No, you can't read the position on LeArm; that feature only works on XArm. But, regarding setPosition command, you need to change the xarm library source code. It's defined to set values between 0-1000, but for LeArm, you need to set values between 500-2500 (for all IDs from 2 to 6) and 1500-2500 for ID:1 (gripper). If you need additional help, you're free to contact me.

Mcneelsh commented 7 months ago

Good to know, thank you! I've got it figured out for the most part now. Thanks for such a speedy reply, as this was very frustrating when I started.

eric-rosen commented 6 months ago

@Seferovic8 Thank you, this was very helpful for me for setting the position of the LeArm!

I was wondering about getting the position, is that fundamentally not possible to access or would just involve extending this codebase? Shouldn't the servos have some encoders that report their position? If not, how did people figure out the full scope of the controller interface, I'm curious if there is any documentation? (All I see are the hard-coded values in https://github.com/ccourson/xArmServoController/blob/c0b62f7def35019f17916ca24a314ed486657731/Python/xarm/controller.py#L7 but I'm curious where those came from / are they everything?)