Skip to content

LEGO Technic Move hub - add servo support for C channel#223

Draft
vicocz wants to merge 27 commits into
defaultfrom
local/lego-technic-move-servo
Draft

LEGO Technic Move hub - add servo support for C channel#223
vicocz wants to merge 27 commits into
defaultfrom
local/lego-technic-move-servo

Conversation

@vicocz
Copy link
Copy Markdown
Owner

@vicocz vicocz commented May 11, 2026

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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);
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants