SkoltechRobotics / rplidar

Python module for RPLidar A1 and A2 rangefinder scanners
MIT License
187 stars 126 forks source link

Check compatability wih A2 sensor #2

Closed newpavlov closed 7 years ago

newpavlov commented 7 years ago

It was reported that A2 sensor is not powering up motor while using this driver.

Seems that A2 does not react to DTR (Data Terminal Ready) signal, in case of A1 its not only used for initiating communication channel, but also to turn on motor. Evidently because motor stays turned off lidar can't collect data and returns nothing, which results in error.

Unfortunately I don't have A2 to test code on it, so help are welcomed!

arlarsonCSUF commented 7 years ago

Hi there, I've tested the module with the A2 sensor and I am experiencing exactly what you have described. The rplidar motor fails to start and I get an execution error.

scifiswapnil commented 7 years ago

Hi, got this error "Wrong response data type". Was the library built specifically for A1 or a general rplidar sensor? . After going through the program i saw few things odd like the STOP and RESET code are same, while in the documentation its different. Though i am able to connect to rplidar and able to get the info and health of the A2 lidar.

newpavlov commented 7 years ago

@scifiswapnil I've intended it both for A1 and A2, according to the documentation they share the same protocol. (except reaction to EXPRESS_SCAN byte) But as I don't have A2 I am unable to look into origin of this problem. I'll try to skim over documentation again, maybe I missed something.

Regarding stop() and reset() it's a bug, for some reason I've used incorrect value for STOP_BYTE, which should be 0x25, not 0x40. I will publish fix to pypi tomorrow.

arlarsonCSUF commented 7 years ago

Just updated rplidar.py and tried out the latest changes on the A2 and I'm getting the following error messages. File "/.../rplidar/examples/animate.py", line 40, in <module> run() File "/.../rplidar/examples/animate.py", line 32, in run for scan in lidar.iter_scans(): File "/Library/Python/2.7/site-packages/rplidar.py", line 311, in iter_scans for data in self.iter_measurments(max_buf_meas, force): File "/Library/Python/2.7/site-packages/rplidar.py", line 286, in iter_measurments raw = self._read_response(dsize) File "/Library/Python/2.7/site-packages/rplidar.py", line 170, in _read_response raise RPLidarException('Wrong body size') RPLidarException: Wrong body size

luckywang95 commented 7 years ago

same issue here with A2. This driver does not start the motor. I tried to connect and its fine. but when i type lidar.start_motor(). there is no error code but the motor does not rotate as well.

Dear @newpavlov , for your information, i did asked the slamtec support and it requires a different command to start the motor which is 0xA5 F0.

Reply from slamtec: The start motor command could be A5 F0 02 C4 02 91 or A5 F0 02 30 02 65.( under my calculation, the payload and checksum are optional .) And then send A5 20 or other command to test RPlidar.

However, myself is a newbie to programming so i cannot make use of it. Hope it helps!

luckywang95 commented 7 years ago

After almost 1 day of effort, i have successfully modified the start_motor() function for RPLidar A2 to rotate. Tested on animate.py and it is working! However, it did give some error after a restart of animate.py and im still troubleshooting the issue. Anyway, Thank you @newpavlov for the code!

and i have 1 question. Is it normal for the animate.py to update the plot so slow? or is it due to my added/modified code?

newpavlov commented 7 years ago

@luckywang95 Thank you for your effort! If A2 requires an explicit command to start motor, then it probably also needs an explicit command for stopping motor. It's strange that SLAMTEC forgot to mention this in the protocol specifications.

Could you please create a Pull Request with your changes? If you have any problems with git or programming feel free to contact me via email!

Regarding animate.py it was created for illustrative purposes only, so in some cases it can be quite slow.

UPD: It seems what 0xF0 command stands for controlling motor PWM, payload is u16 value which probably influences rotational speed. Also they have undocumented command 0xFF named in the SDK as GET_ACC_BOARD_FLAG.

luckywang95 commented 7 years ago

@newpavlov Hi, i have created a new pull request for my modified code. My code is modified to work on A2 but i dont know it can work for A1 as there is a need to check for the motorcontrol support if it is intended to work for both A1 and A2 models.

and I did get some response error where the length is not matched when i try to run the examples given. However, the examples did ran successfully with restarts and some luck.

For the animate.py, it is not quite slow but very slow and it will crash after around 10 seconds of running. Errors are usually incorrect response length or some error regarding the response.

For start motor command, they didnt include it in their documentation but i acquired it through their support. and for the 0xFF is for checking for the A2's motorcontrol feature. Below is the image they send to me regarding motor control.

a2

newpavlov commented 7 years ago

Thanks to @luckywang95 (PR #3) this problem should be fixed now. I've published new version 0.9.2 with the fix to the PyPI. Please report if you'll experience any issues.