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

Generic ESC harmonic notch handling #16725

Merged
merged 20 commits into from May 12, 2021
Merged

Conversation

andyp1per
Copy link
Collaborator

@andyp1per andyp1per commented Feb 23, 2021

This is a generic abstraction for ESC telemety which I have ported all of the existing telemetry providers to.
It incorporates dynamic notch support, rpm slew, mavlink and logging support. Overall the code has got smaller.
There is also a new autotest for the dynamic notch support.

@andyp1per andyp1per changed the title Generic ESC harmoni notch handling Generic ESC harmonic notch handling Feb 23, 2021
@amilcarlucas
Copy link
Contributor

Maybe replace HAVE_AP_BLHELI_SUPPORT with HAVE_ESC_TELEM_SUPPORT in some places?

Copy link
Contributor

@amilcarlucas amilcarlucas left a comment

Choose a reason for hiding this comment

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

Nice stuff, loving it!

libraries/AP_ESC_Telem/AP_ESC_Telem_Backend.cpp Outdated Show resolved Hide resolved
libraries/AP_ESC_Telem/AP_ESC_Telem_Backend.cpp Outdated Show resolved Hide resolved
libraries/AP_MSP/AP_MSP_Telem_Backend.cpp Outdated Show resolved Hide resolved
libraries/AP_ToshibaCAN/AP_ToshibaCAN.cpp Outdated Show resolved Hide resolved
libraries/AP_ToshibaCAN/AP_ToshibaCAN.cpp Outdated Show resolved Hide resolved
libraries/AP_ToshibaCAN/AP_ToshibaCAN.cpp Outdated Show resolved Hide resolved
libraries/AP_ToshibaCAN/AP_ToshibaCAN.cpp Outdated Show resolved Hide resolved
libraries/AP_ToshibaCAN/AP_ToshibaCAN.h Outdated Show resolved Hide resolved
libraries/AP_BLHeli/AP_BLHeli.cpp Outdated Show resolved Hide resolved
@amilcarlucas
Copy link
Contributor

amilcarlucas commented Feb 25, 2021

Implements a part of #16645 together with amilcarlucas#4

libraries/AP_ESC_Telem/AP_ESC_Telem.h Outdated Show resolved Hide resolved
libraries/AP_ESC_Telem/AP_ESC_Telem.cpp Outdated Show resolved Hide resolved
libraries/AP_BLHeli/AP_BLHeli.cpp Outdated Show resolved Hide resolved
libraries/AP_BLHeli/AP_BLHeli.cpp Outdated Show resolved Hide resolved
libraries/AP_ESC_Telem/AP_ESC_Telem_Backend.h Outdated Show resolved Hide resolved
libraries/AP_ESC_Telem/AP_ESC_Telem_Backend.h Outdated Show resolved Hide resolved
libraries/AP_ESC_Telem/AP_ESC_Telem_Backend.h Outdated Show resolved Hide resolved
Copy link
Contributor

@amilcarlucas amilcarlucas left a comment

Choose a reason for hiding this comment

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

AP_PiccoloCAN and AP_KDECAN support are missing in this PR

libraries/AP_ESC_Telem/AP_ESC_Telem_Backend.cpp Outdated Show resolved Hide resolved
libraries/AP_ESC_Telem/AP_ESC_Telem_Backend.cpp Outdated Show resolved Hide resolved
libraries/AP_ESC_Telem/AP_ESC_Telem_Backend.cpp Outdated Show resolved Hide resolved
@andyp1per andyp1per marked this pull request as ready for review February 26, 2021 22:34
@andyp1per
Copy link
Collaborator Author

This is working on my 3" quad with BLHeli bi-dir dshot

@andyp1per
Copy link
Collaborator Author

Ok, PiccoloCAN, UAVCAN and KDECAN done. Will need some testing and I am not convinced about the motors API - might need to use masks instead

@andyp1per
Copy link
Collaborator Author

Tridge and I have zero'ed in on a slightly different design ...

@amilcarlucas
Copy link
Contributor

amilcarlucas commented Feb 28, 2021

I think the _telemetry and _telem_semaphore member variables should be moved to the AP_ESC_Telem_Backend base class together with the functions:

    bool get_usage_seconds(uint8_t esc_id, uint32_t& usage_sec) const override;
    bool get_temperature(uint8_t esc_id, int16_t& temp) const override;
    bool get_rpm(uint8_t esc_id, uint16_t& rpm) const override;
    bool get_current_ca(uint8_t esc_id, uint16_t& amps_ca) const override;
    uint32_t have_telem_data(uint8_t esc_id) const override;
    void send_esc_telemetry_mavlink(uint8_t mav_chan) const;
    void log_esc(uint8_t inst);

What do you think?

@andyp1per
Copy link
Collaborator Author

The alternate design we came up with was to have an additional callback - update_esc_telemetry() that populated the frontend with the additional telemetry data together with a timestamp. Then callers only need to call the front end - no need for virtual functions at all in the main. This will also cope with multiple drivers populating the ESC data.

Copy link
Contributor

@amilcarlucas amilcarlucas left a comment

Choose a reason for hiding this comment

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

Nice, we are getting there :)

@andyp1per andyp1per force-pushed the pr-esc-notch branch 3 times, most recently from fc3ee8d to d6f657a Compare March 3, 2021 09:06
@andyp1per andyp1per requested a review from rmackay9 March 3, 2021 09:55
@amilcarlucas
Copy link
Contributor

This adds less than 90 lines of code, and reduces FW size by about 1300 bytes (ArduCopter on Durandal) 👍

@amilcarlucas
Copy link
Contributor

I do think that it needs a semaphore to ensure the consistency of the telemetry data.

@andyp1per
Copy link
Collaborator Author

andyp1per commented Mar 3, 2021

@amilcarlucas - I've deliberately not done that because I don't want timing critical code (e.g. bi-dir dshot) being required to take out the lock. If we really want a lock then I'll do a backend/frontend copy like we do for the IMUs. But at the moment I don't think its necessary. All the data types are 32bits or less (i.e. atomic) and the only coordinated update is between the timestamp and data type. We only really care about the timestamp for out of data data - at which point nothing is being written anyway so a little out of date is fine. So at the moment I don't think anything bad will happen as its stands and it avoids some contention.
Also indiviudal ESCs have their own individual slot - there is no conflict between them.

remove send_esc_telemetry_mavlink()
log telemetry data in frontend
record volts, amps and consumption as floats
…ing with other ESCs

remove send_esc_telemetry_mavlink()
log telemetry data in frontend
remove datastructures and semaphore obsoleted by AP_ESC_Telem* (<amilcar.lucas@iav.de>)
record volts, amps and consumption as floats
remove send_esc_telemetry_mavlink()
remove datastructures and semaphore obsoleted by AP_ESC_Telem* (<amilcar.lucas@iav.de>)
record volts, amps and consumption as floats
… with other ESCs

log ESC telemetry data in frontend
…ng with other ESCs

refactor to capture and output slewed rpm values
enable with HAL_WITH_ESC_TELEM
move notch calculation to front end
refactor telemetry data into frontend
cope with blended data
add mavlink send function
log telemetry data in frontend
add SITL ESC telemetry
record volts, amps and consumption as floats
report telemetry transmission errors
disable ESC Telemetry inclusion when there is no need for it
move ESC_Telem logging to the AP_ESC_Telem class (by amilcar.lucas@iav.de)
various cleanups (by amilcar.lucas@iav.de)
add support for raw ESC rpm
check RPM validity for mavlink output
Use const when applicable
rename AP_BattMonitor_BLHeliESC -> AP_BattMonitor_ESC
record volts, amps and consumption as floats
Correct ESC-telemetry-based voltage and temperature (<amilcar.lucas@iav.de>)
Correct ESC-telemetry-based voltage and temperature when less than 12 ESCs are used (<amilcar.lucas@iav.de>)
fix jumps in consumed current (<amilcar.lucas@iav.de>)
Implement temperature readings (<amilcar.lucas@iav.de>)
Fix temperature scaling (<amilcar.lucas@iav.de>)
@andyp1per
Copy link
Collaborator Author

Squashed and rebased

added Ampere hours unit in LOG_ESC_MSG
log ESC volts, amps and consumption as floats
update ESC log file structures
consumption in mAh
Correct the current_tot unit,
motor_temp unit and error_rate unit in comments (<amilcar.lucas@iav.de>)
move ESC_Telem logging to the AP_ESC_Telem class (<amilcar.lucas@iav.de>)
correct log structure (<amilcar.lucas@iav.de>)
Copy link
Contributor

@khancyr khancyr left a comment

Choose a reason for hiding this comment

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

That seems ok. I will do another pass for review later

@rmackay9
Copy link
Contributor

I've re-tested ToshibaCAN ESCs and they also seem to work. So from a basic functionality point of view I think KDECAN and ToshibaCAN telemetry continues to work.

@tridge
Copy link
Contributor

tridge commented May 11, 2021

i have UAVCAN ESCs to test

@tridge
Copy link
Contributor

tridge commented May 12, 2021

all working well on a quad with 4 UAVCAN ESCs

@tridge tridge merged commit c323ee4 into ArduPilot:master May 12, 2021
@andyp1per andyp1per added WikiNeeded needs wiki update and removed DevCallEU labels May 12, 2021
@Hwurzburg Hwurzburg removed the WikiNeeded needs wiki update label May 31, 2021
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.

None yet

9 participants