LEGO Technic Move hub - add servo support for C channel#223
Draft
vicocz wants to merge 27 commits into
Draft
Conversation
Agent-Logs-Url: https://github.com/vicocz/brickcontroller2/sessions/391dbddf-e12f-4d5f-bf17-72fec9d7ff6b Co-authored-by: vicocz <11756608+vicocz@users.noreply.github.com>
…com/vicocz/brickcontroller2 into local/tehnice-move-hub-improvements
There was a problem hiding this comment.
Pull request overview
Adds non-PLAYVM servo support (and introduces stepper handling) for the LEGO Technic Move Hub’s C channel by switching to absolute-position commands when the channel is configured as a servo/stepper.
Changes:
- Allow C channel to be configured as a servo in both PLAYVM and non-PLAYVM modes, and as a stepper in non-PLAYVM mode.
- Configure port position reporting for stepper channels during connect setup.
- Add dedicated output send paths for servo (
GotoAbsPosition) and stepper (relative target based on current position) on channel C.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // stepper for normal mode but C channel only | ||
| ChannelOutputType.StepperMotor => !EnablePlayVmMode && channel == CHANNEL_C, | ||
|
|
||
| // other types (such as stepper) are not supported at all |
Comment on lines
+448
to
+454
| var position = ChannelRelativePositions.Get(channel); | ||
|
|
||
| if (value == Half.Zero || position.UpdateTime.AddMilliseconds(250) > DateTime.Now) | ||
| { | ||
| // if value is zero or position was updated recently, skip to avoid flooding the hub with commands when the slider is not yet stabilized | ||
| return new ValueTask<bool>(true); | ||
| } |
|
|
||
| var portId = GetPortId(channel); | ||
|
|
||
| // in non PLAYVM mode, need to apply calibrated base angle as offset to reach correct position |
Comment on lines
+435
to
+442
| private async ValueTask<bool> SendPortOutput_ServoAsync(int channel, Half value, CancellationToken token) | ||
| { | ||
| var portId = GetPortId(channel); | ||
| // in non PLAYVM mode, need to apply calibrated base angle as offset to reach correct position | ||
| var servoAngle = (int)value * GetMaxServoAngle(channel) / 100; | ||
| var absPosition = _calibratedZeroAngle + ChannelConfigs.Get(channel).ServoBaseAngle + servoAngle; | ||
| var cmd = BuildPortOutput_GotoAbsPosition(portId, absPosition, servoSpeed: 50); | ||
| return await WriteAsync(cmd, token); |
Comment on lines
228
to
233
| foreach (KeyValuePair<int, Half> change in changes) | ||
| { | ||
| var value = ToByte(change.Value); | ||
| var channelOutputType = GetOutputType(change.Key); | ||
|
|
||
| result = change.Key switch |
Comment on lines
+66
to
+72
| // servo for - PLAYVM and C channel only | ||
| // - standard mode but A,B,C channels only | ||
| ChannelOutputType.ServoMotor => | ||
| (EnablePlayVmMode && channel == CHANNEL_C) || | ||
| (!EnablePlayVmMode && channel == CHANNEL_C), | ||
| // stepper for standard mode but A,B,C channels only | ||
| ChannelOutputType.StepperMotor => !EnablePlayVmMode && channel <= CHANNEL_C, |
Comment on lines
+54
to
+56
| public override bool CanResetOutput(int channel) => | ||
| (EnablePlayVmMode && channel == CHANNEL_C) || // PLAYVM - only C channel supports reset | ||
| (!EnablePlayVmMode && channel == CHANNEL_C); // TODO standard mode - all A, B and C channels |
|
|
||
| var portId = GetPortId(channel); | ||
|
|
||
| // in non PLAYVM mode, need to apply calibrated base angle as offset to reach correct position |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.