-
Notifications
You must be signed in to change notification settings - Fork 20.7k
AP_Periph: add support for sending servo telemety #31577
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
63fd2e6
AP_Periph: enable servo telem
IamPete1 4850fd0
ChibiOS: default `AP_SERVO_TELEM_ENABLED` to 0 on periph
IamPete1 2b4071f
AP_Periph: move actator telem to use servo telem lib
IamPete1 07a3e52
ChibiOS: hwdef: VM-L431-SRV-Hub-4CHP: enable servo telem lib
IamPete1 e326a7b
AP_DroneCAN: correct one indexing done `SRV_send_actuator` so indexes…
IamPete1 b12c365
AP_Periph: correct servo telem indexing
IamPete1 1d82616
AP_Servo_Telem: allow more telem channels than outputs on periph
IamPete1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
|
|
||
| #include "AP_Periph.h" | ||
|
|
||
| #if AP_SERVO_TELEM_ENABLED | ||
|
|
||
| #include <dronecan_msgs.h> | ||
|
|
||
| // Send servo telem message occasionally | ||
| void AP_Periph_FW::servo_telem_update() | ||
| { | ||
| const uint32_t now_ms = AP_HAL::millis(); | ||
|
|
||
| // Run update function at 50hz mirroring vehicle update rate | ||
| if (now_ms - servo_telem.last_update_ms > 20) { | ||
| // Update periph only actuator telem | ||
| #if AP_PERIPH_ACTUATOR_TELEM_ENABLED | ||
| actuator_telem.update(); | ||
| #endif | ||
|
|
||
| // Update main servo telem lib | ||
| servo_telem.lib.update(); | ||
| servo_telem.last_update_ms = now_ms; | ||
| } | ||
|
|
||
| // Reporting is disabled | ||
| if (g.servo_telem_msg_rate <= 0) { | ||
| return; | ||
| } | ||
|
|
||
| // Check if its time to send the next instance | ||
| if (now_ms - servo_telem.last_send_ms < (1000U / g.servo_telem_msg_rate)) { | ||
| return; | ||
| } | ||
| servo_telem.last_send_ms = now_ms; | ||
|
|
||
| for (uint8_t i = 0; i < NUM_SERVO_CHANNELS; i++) { | ||
| // Send each servo in turn | ||
| const uint8_t index = (servo_telem.last_send_index + 1 + i) % NUM_SERVO_CHANNELS; | ||
|
|
||
| // Move on to next instance if no data is available | ||
| AP_Servo_Telem::TelemetryData data; | ||
| if (!servo_telem.lib.get_telem(index, data)) { | ||
| continue; | ||
| } | ||
|
|
||
| // Blank packet | ||
| const float nan = nanf(""); | ||
| uavcan_equipment_actuator_Status pkt { | ||
| actuator_id: (uint8_t)(index + 1), // One based indexing for DroneCAN transport | ||
| position: nan, | ||
| force: nan, | ||
| speed: nan, | ||
| power_rating_pct: UAVCAN_EQUIPMENT_ACTUATOR_STATUS_POWER_RATING_PCT_UNKNOWN | ||
| }; | ||
|
|
||
| // Fill in present data | ||
| if (data.present(AP_Servo_Telem::TelemetryData::Types::MEASURED_POSITION)) { | ||
| pkt.position = radians(data.measured_position); | ||
| } | ||
| if (data.present(AP_Servo_Telem::TelemetryData::Types::FORCE)) { | ||
| pkt.force = data.force; | ||
| } | ||
| if (data.present(AP_Servo_Telem::TelemetryData::Types::SPEED)) { | ||
| pkt.speed = data.speed; | ||
| } | ||
| if (data.present(AP_Servo_Telem::TelemetryData::Types::DUTY_CYCLE)) { | ||
| pkt.power_rating_pct = data.duty_cycle; | ||
| } | ||
|
|
||
| // Encode message into buffer | ||
| uint8_t buffer[UAVCAN_EQUIPMENT_ACTUATOR_STATUS_MAX_SIZE]; | ||
| const uint16_t total_size = uavcan_equipment_actuator_Status_encode(&pkt, buffer, !canfdout()); | ||
|
|
||
| // Send message | ||
| canard_broadcast(UAVCAN_EQUIPMENT_ACTUATOR_STATUS_SIGNATURE, | ||
| UAVCAN_EQUIPMENT_ACTUATOR_STATUS_ID, | ||
| CANARD_TRANSFER_PRIORITY_LOW, | ||
| &buffer[0], | ||
| total_size); | ||
|
|
||
| servo_telem.last_send_index = index; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| #endif // AP_SERVO_TELEM_ENABLED |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
libraries/AP_HAL_ChibiOS/hwdef/VM-L431-SRV-Hub-4CHP/defaults.parm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| ACT_TELEM_RATE 10 | ||
| SRV_TLM_MSG_RATE 40 | ||
| ACT_NUM_CHANS 4 | ||
| ACT_CURR_PIN1 9 | ||
| ACT_AMP_OFFSET 0 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.