-
Notifications
You must be signed in to change notification settings - Fork 19
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
Feature/add medium linear motor #105
Merged
tthiery
merged 2 commits into
sharpbrick:master
from
corneliusmunz:feature/add-medium-linear-motor
Oct 12, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
43 changes: 43 additions & 0 deletions
43
examples/SharpBrick.PoweredUp.Examples/ExampleTwoPortHubMediumLinearMotor.cs
This file contains 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,43 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using SharpBrick.PoweredUp; | ||
|
||
namespace Example | ||
{ | ||
public class ExampleTwoPortHubMediumLinearMotor : BaseExample | ||
{ | ||
public override async Task ExecuteAsync() | ||
{ | ||
using (var twoPortHub = Host.FindByType<TwoPortHub>()) | ||
{ | ||
await twoPortHub.VerifyDeploymentModelAsync(modelBuilder => modelBuilder | ||
.AddHub<TwoPortHub>(hubBuilder => hubBuilder | ||
.AddDevice<MediumLinearMotor>(twoPortHub.A) | ||
) | ||
); | ||
|
||
var motor = twoPortHub.A.GetDevice<MediumLinearMotor>(); | ||
|
||
await motor.SetAccelerationTimeAsync(3000); | ||
await motor.SetDecelerationTimeAsync(1000); | ||
await motor.StartSpeedForTimeAsync(6000, 90, 100, SpecialSpeed.Hold, SpeedProfiles.AccelerationProfile | SpeedProfiles.DecelerationProfile); | ||
|
||
await Task.Delay(10_000); | ||
|
||
await motor.StartSpeedForDegreesAsync(180, -10, 100, SpecialSpeed.Brake, SpeedProfiles.None); | ||
|
||
await Task.Delay(10_000); | ||
|
||
await motor.StartSpeedAsync(100, 90, SpeedProfiles.None); | ||
await Task.Delay(2000); | ||
await motor.StartSpeedAsync(-100, 90, SpeedProfiles.None); | ||
await Task.Delay(2000); | ||
await motor.StartSpeedAsync(0, 90, SpeedProfiles.None); | ||
|
||
await Task.Delay(10_000); | ||
|
||
await twoPortHub.SwitchOffAsync(); | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using SharpBrick.PoweredUp.Protocol; | ||
using SharpBrick.PoweredUp.Utils; | ||
|
||
namespace SharpBrick.PoweredUp | ||
{ | ||
public class MediumLinearMotor : TachoMotor, IPoweredUpDevice | ||
{ | ||
public MediumLinearMotor() | ||
: base() | ||
{ } | ||
public MediumLinearMotor(ILegoWirelessProtocol protocol, byte hubId, byte portId) | ||
: base(protocol, hubId, portId) | ||
{ } | ||
|
||
public IEnumerable<byte[]> GetStaticPortInfoMessages(Version softwareVersion, Version hardwareVersion, SystemType systemType) | ||
=> @" | ||
0B-00-43-00-01-07-03-06-00-07-00 | ||
07-00-43-00-02-06-00 | ||
12-00-44-00-00-00-50-4F-57-45-52-00-00-00-00-00-00-00 | ||
0E-00-44-00-00-01-00-00-C8-C2-00-00-C8-42 | ||
0E-00-44-00-00-02-00-00-C8-C2-00-00-C8-42 | ||
0E-00-44-00-00-03-00-00-C8-C2-00-00-C8-42 | ||
0B-00-44-00-00-04-50-43-54-00-00 | ||
08-00-44-00-00-05-00-10 | ||
0A-00-44-00-00-80-01-00-01-00 | ||
12-00-44-00-01-00-53-50-45-45-44-00-00-00-00-00-00-00 | ||
0E-00-44-00-01-01-00-00-C8-C2-00-00-C8-42 | ||
0E-00-44-00-01-02-00-00-C8-C2-00-00-C8-42 | ||
0E-00-44-00-01-03-00-00-C8-C2-00-00-C8-42 | ||
0B-00-44-00-01-04-50-43-54-00-00 | ||
08-00-44-00-01-05-10-10 | ||
0A-00-44-00-01-80-01-00-04-00 | ||
12-00-44-00-02-00-50-4F-53-00-00-00-00-00-00-00-00-00 | ||
0E-00-44-00-02-01-00-00-B4-C3-00-00-B4-43 | ||
0E-00-44-00-02-02-00-00-C8-C2-00-00-C8-42 | ||
0E-00-44-00-02-03-00-00-B4-C3-00-00-B4-43 | ||
0B-00-44-00-02-04-44-45-47-00-00 | ||
08-00-44-00-02-05-08-08 | ||
0A-00-44-00-02-80-01-02-04-00 | ||
".Trim().Split("\n").Select(s => BytesStringUtil.StringToData(s)); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -15,7 +15,7 @@ public enum DeviceType : ushort | |
ExternalTiltSensor = 0x0022, // TILT_SENSOR | ||
MotionSensor = 0x0023, // MOTION_SENSOR | ||
VisionSensor = 0x0025, // COLOR_DISTANCE_SENSOR | ||
ExternalMotorWithTacho = 0x0026, // MEDIUM_LINEAR_MOTOR | ||
MediumLinearMotor = 0x0026, // MEDIUM_LINEAR_MOTOR | ||
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. Naming choice is perfect. I copied these from poweredup-node ... but they have history. Normally, this would apply for a breaking change. But honestly, the motor is not implemented so I cannot imagine why someone would use this enum value. Therefore, fine with me! |
||
InternalMotorWithTacho = 0x0027, // MOVE_HUB_MEDIUM_LINEAR_MOTOR | ||
InternalTilt = 0x0028, // MOVE_HUB_TILT_SENSOR | ||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually add the test run to the Program.cs commented out ... like that it can be easier discovered. Fix it on the next PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, good idea! Will take care of that in the next PR