Repository navigation
Control for linear actuator #8
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
Open
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
917eb66
- create stm32CubeMX .ioc file (stm32CubeMX is used to generate clock…
jacobh460 fcf3891
Control for linear actuator
anand-k185 4e5f53d
Addressed PR comments. Updated CAN parser, changed constant based on …
anand-k185 69e5ee7
Updated begin() to listen to actuators, updated parse_tvc_telemetry t…
anand-k185 445f0c8
Added messaging for actuators that did not respond
anand-k185 d2a3f84
Deleted .gitignore.swp
anand-k185 95abed0
Fixed global CAN PR
anand-k185 dd11c46
Addressed PR comments
anand-k185 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,94 @@ | ||
| #include "TVC_Actuators.h" | ||
| #include "GimbalKinematics.h" | ||
| #include "UltramotionActuator.hpp" | ||
| #include "ec_pins.h" | ||
| #include "fdcan_toad.h" | ||
| #include "toad_can_bus.h" | ||
| #include <CommsSerial.h> | ||
|
|
||
| namespace TVC_Actuators { | ||
|
|
||
| uint32_t ASSUMED_ACTUATOR_TELEMETRY_INTERVAL_MS = 1000; | ||
| uint32_t ACTUATOR_HANDSHAKE_TIMEOUT_MS = 2 * ASSUMED_ACTUATOR_TELEMETRY_INTERVAL_MS + 500; | ||
| bool tvc_debug_mode = false; | ||
|
|
||
| // TODO - PLACEHOLDER scaling. Assumes a straight linear map from physical | ||
| // actuator length (mm) to the actuator's raw target_pos range (0-65535). | ||
| // Needs the actuator's real stroke length and pMin/pMax from its | ||
| // datasheet/CONFIG.TXT before this is trustworthy. | ||
| uint16_t length_to_target_pos(float length_mm) { | ||
| constexpr float MIN_LENGTH_MM = 0.0f; // TODO | ||
| constexpr float MAX_LENGTH_MM = 100.0f; // TODO | ||
| constexpr uint16_t POS_MAX = 65535; | ||
|
|
||
| float clamped = constrain(length_mm, MIN_LENGTH_MM, MAX_LENGTH_MM); | ||
| return (uint16_t)((clamped - MIN_LENGTH_MM) / (MAX_LENGTH_MM - MIN_LENGTH_MM) * POS_MAX); | ||
| } | ||
|
|
||
| bool begin() { | ||
| return true; | ||
| bool heard_pitch = false; | ||
| bool heard_yaw = false; | ||
|
|
||
| uint32_t start_time = millis(); | ||
| while (millis() - start_time < ACTUATOR_HANDSHAKE_TIMEOUT_MS) { | ||
| while (can_tvc.available() > 0) { | ||
| arduino::CanMsg msg = can_tvc.read(); | ||
| uint32_t id = msg.isStandardId() ? msg.getStandardId() : msg.getExtendedId(); | ||
|
|
||
| if (id == CAN_ID_TVC_PITCH) { | ||
| heard_pitch = true; | ||
| } else if (id == CAN_ID_TVC_YAW) { | ||
| heard_yaw = true; | ||
| } | ||
| } | ||
|
|
||
| if (heard_pitch && heard_yaw) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| if (!heard_pitch) { | ||
| CommsSerial.println("No telemetry heard from PITCH actuator"); | ||
| } | ||
| if (!heard_yaw) { | ||
| CommsSerial.println("No telemetry heard from YAW actuator"); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| // TODO - this function | ||
| void set_angles_pitch_yaw(float pitch, float yaw) { | ||
| float pitch_len; | ||
| float yaw_len; | ||
| calc_actuator_lengths(pitch, yaw, &pitch_len, &yaw_len); | ||
| float pitch_len, yaw_len; | ||
| calc_actuator_lengths(pitch, yaw, &pitch_len, &yaw_len); // already implemented | ||
|
|
||
| send_target_pos(can_tvc, CAN_ID_TVC_PITCH, length_to_target_pos(pitch_len)); | ||
| send_target_pos(can_tvc, CAN_ID_TVC_YAW, length_to_target_pos(yaw_len)); | ||
| } | ||
|
|
||
| // Call every flight_loop() iteration - nothing currently does. Drains | ||
| // whatever arrived in the RX FIFO since the last call and decodes anything | ||
| // addressed to the TVC actuators. | ||
| void poll() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will end up being shared across the motors as well - I suspect we will drain this buffer in the main flight loop and expose a callback function filtered by ID - coordinate with jacob here... |
||
| while (can_tvc.available() > 0) { | ||
| arduino::CanMsg msg = can_tvc.read(); | ||
| uint32_t id = msg.isStandardId() ? msg.getStandardId() : msg.getExtendedId(); | ||
|
|
||
| if (id == CAN_ID_TVC_PITCH || id == CAN_ID_TVC_YAW) { | ||
| // Fixed-format decode for exactly what flight code acts on - no | ||
| // letter-code dispatch, no unused fields. | ||
| tvc_actuator_telemetry_t telem = parse_tvc_telemetry(msg.data); | ||
|
|
||
| if (tvc_debug_mode) { | ||
| // Full generic decode/print, bench debugging only - never feeds a | ||
| // flight decision. Matches "KLMGHEFY", the factory-default txData. | ||
| char decode_str[] = {'K', 'L', 'M', 'G', 'H', 'E', 'F', 'Y'}; | ||
| struct telem full_frame; | ||
| parse_CAN_frame(msg.data, msg.data_length, decode_str, sizeof(decode_str), &full_frame); | ||
| } | ||
| } | ||
| // CAN_ID_STEPPER_OX / CAN_ID_STEPPER_FU frames also arrive on this same | ||
| // bus - dispatch to ThrottleValves here too once it reads feedback this way. | ||
| } | ||
| } | ||
|
|
||
| } // namespace TVC_Actuators | ||
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.
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.