Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Scripting: mount-djirs2 script handles latest gimbal software #25692

Merged
merged 4 commits into from
Dec 13, 2023

Conversation

rmackay9
Copy link
Contributor

@rmackay9 rmackay9 commented Dec 4, 2023

This is a replacement for PR #24461

Three important fixes are included:

  1. Support for both legacy and latest gimbal firmware
  2. bug fix the reported yaw angle when the gimbal is mounted "upside down"
  3. reduce the reply timeout from 1 sec to 0.1 sec. Replies are normally received within 5ms and waiting for 1sec leads to the gimbal stopping

This has been tested on a DJIR2 running the legacy firmware. I hope that @tpwrules can check that it also works on the latest firmware.

@tpwrules
Copy link
Contributor

tpwrules commented Dec 4, 2023

I'll look into this later this week. Thanks for getting back to it.

the gimbal is mounted "upside down" which means the camera is above the gimbal.

I don't think this is true? In all the marketing material and documentation and menus, the "normal" orientation of the gimbal has the camera above the handle and control unit. In most drone applications the camera will hang below the handle and control unit, which is why we provide the upside down mode, correct?

As for the roll/pitch being reversed, I'm not sure what's up. The code to retrieve the data as it's written directly contradicts the documentation at the top of the file and the spec available here. But if it works for you there must be some gimbals which are reversed? I'll double check this too.

Might be best to just make everyone update.

@rmackay9
Copy link
Contributor Author

rmackay9 commented Dec 5, 2023

@tpwrules,

Txs for the feedback and offer of testing. You may be right about the definition of "upside-down". I'll check with another user I know about what he thinks is rightside-up vs upside-down.

@tpwrules
Copy link
Contributor

tpwrules commented Dec 7, 2023

Regarding the testing script in the branch in the old issue, I get poscontrol len: 19, att len: 26. These sound like they match expectations.

The script in this branch works fine with my gimbal. But the roll and pitch axis reports are for sure swapped. If I set DJIR_DEBUG=2 and move my controller's roll input (function 212), then the gimbal roll axis moves, but the pitch number changes in the debug output. Same thing if I move function 213, then the pitch axis moves, but the roll number is what changes. Yaw seems okay. I only did testing so far in right-side-up mode, with the camera above the handle/controller.

Again, the protocol documentation contained within the script itself and the PDF from DJI suggests the interpretation my gimbal uses is correct and the script code is wrong. You say your gimbal moves correctly, did you check that the reported data is in fact correct using the debug option? Can you remind which firmware your gimbal is on? Mine is 01.05.00.20.

tpwrules and others added 4 commits December 12, 2023 10:38
DJI R SDK version 2.2.0.5 released on October 30, 2020 added CmdSet and
CmdID bytes to reply frames before the data segment which need to be
skipped when parsing replies.

Tested with gimbal firmware 01.04.00.20 and 01.05.00.20 (latest version).
@rmackay9
Copy link
Contributor Author

@tpwrules,

Thanks for the testing and feedback. As hard as it is to believe, I think DJI had a bug in the angle reporting for roll and pitch in the legacy firmware (they were swapped). I've updated the PR so that for the "latest" DJI firmware it uses the correct order.

Maybe you could comment whether you're happy with these changes? That'll clear the way for merging I think. Txs again.

Comment on lines +663 to +664
local pitch_field = 17
local roll_field = 19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like to see a comment here that this field ordering contradicts the spec but is how an actual gimbal of version XX (whichever version yours is) is observed to behave.

@tpwrules
Copy link
Contributor

I personally would like to see support for the legacy protocol dropped completely. Updating is slow but not hard; the user has to have hooked up the app to activate the gimbal in the first place. We are also assuming whichever version updated the packet length is whichever version fixed the reporting bug, which is hard to determine.

Aside from that comment nit, I'm happy with these changes if you're happy with the additional complications of supporting multiple versions.

@rmackay9
Copy link
Contributor Author

rmackay9 commented Dec 13, 2023

@tpwrules,

I think it's so easy for us to keep supporting the old firmware that we should.

I agree re the comment but I'll do that in the future I think in order to get this in now that it's functionally correct.

@peterbarker
Copy link
Contributor

@tpwrules Randy has committed to adding coimments on the roll/pitch issue in a follow-up PR.

We discussed removing legacy protocol support but Randy made a spirited argument that in this case it's a very small amount of work to support the older firmware and there's no other drawback in doing so.

We do enforce minimum firmware version on some camera drivers, but in this case we don't need to - yet!

Thanks for looking through this PR, we do appreciate the reviews :-)

@peterbarker peterbarker merged commit 56a2474 into ArduPilot:master Dec 13, 2023
89 checks passed
@rmackay9 rmackay9 deleted the dji-mount-fix branch December 14, 2023 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants