コード例 #1
0
        /// <summary>
        /// Start or Hold the motor(s) and keeping the speed/position not using power-levels greater than maxPower.
        /// </summary>
        /// <param name="speed">
        /// - Speed Level in Percentage: 1 - 100 (CW), -1 - -100 (CCW)
        /// - Stop Motor (hold position): 0 (use StartPower for floating and braking)
        /// </param>
        /// <param name="maxPower">Maximum Power level used.</param>
        /// <param name="profile">The speed profiles used (as flags) for acceleration and deceleration. Defaults to None.</param>
        /// <returns></returns>
        public async Task <PortFeedback> StartSpeedAsync(sbyte speed, byte maxPower, SpeedProfiles profile = SpeedProfiles.None)
        {
            AssertValidSpeed(speed, nameof(speed));
            AssertValidMaxPower(maxPower, nameof(maxPower));
            AssertIsConnected();

            var response = await _protocol.SendPortOutputCommandAsync(new PortOutputCommandStartSpeedMessage(
                                                                          _portId,
                                                                          PortOutputCommandStartupInformation.ExecuteImmediately, PortOutputCommandCompletionInformation.CommandFeedback,
                                                                          speed,
                                                                          maxPower,
                                                                          profile
                                                                          )
            {
                HubId = _hubId,
            });

            return(response);
        }
コード例 #2
0
        /// <summary>
        /// Sets a deceleration profile for the motor(s)
        /// </summary>
        /// <param name="timeInMs">
        /// Time in milliseconds of the acceleration (0 - 10000).
        ///
        /// The Time is the duration time for an deceleration from 100% to 0. I.e. a Time set to 1000 ms. should give an deceleration time of 400 ms. from 80% down to 40%
        /// The selected profile will be used in all motor based commands if the profile is selected. The Time and Profile Number set for the profile is ignored if the profile is not selected.
        /// </param>
        /// <param name="profileNumber">Specify the deceleration profile used. Defaults to standard DecelerationProfile.</param>
        /// <returns></returns>
        public async Task <PortFeedback> SetDecelerationTimeAsync(ushort timeInMs, SpeedProfiles profileNumber = SpeedProfiles.DecelerationProfile)
        {
            if (timeInMs < 0 || timeInMs > 10_000)
            {
                throw new ArgumentOutOfRangeException(nameof(timeInMs));
            }
            AssertIsConnected();

            var response = await _protocol.SendPortOutputCommandAsync(new PortOutputCommandSetDecTimeMessage(
                                                                          _portId,
                                                                          PortOutputCommandStartupInformation.ExecuteImmediately, PortOutputCommandCompletionInformation.CommandFeedback,
                                                                          timeInMs,
                                                                          profileNumber
                                                                          )
            {
                HubId = _hubId,
            });

            return(response);
        }
コード例 #3
0
ファイル: AbsoluteMotor.cs プロジェクト: judavi/powered-up
        /// <summary>
        /// Start the motors with individual speeds calculated from the common given Speed using a powerlevel limited to the MaxPower value. And the GOTO the Absolute positions: AbsPos1 and AbsPos2.
        ///
        /// TachoMotor.StartSpeedForDegreesAsync support moving the motor by degrees. It operates relative of its current position.
        /// AbsoluteMotor.GotoAbsolutePositionAsync allows moving the motor to an absolute position. It operates relative to a changeable zero position.
        /// The Position(Observable) (POS) is reflecting the position relative to a changeable zero position (firmware in-memory encoded)
        /// The AbsolutePosition(Observable) (APOS) is reflecting the position relative to marked zero position (physically encoded).
        /// </summary>
        /// <param name="absolutePosition1">Absolute Position of motor 1 (0 is the position at the start of the motor)</param>
        /// <param name="absolutePosition2">Absolute Position of motor 2 (0 is the position at the start of the motor)</param>
        /// <param name="speed">The speed used to move to the absolute position.</param>
        /// <param name="maxPower">Maximum Power level used.</param>
        /// <param name="endState">After time has expired, either Float, Hold or Brake. Defaults to Brake.</param>
        /// <param name="profile">The speed profiles used (as flags) for acceleration and deceleration. Defaults to None.</param>
        /// <returns></returns>
        public async Task <PortFeedback> GotoPositionAsync(int absolutePosition1, int absolutePosition2, sbyte speed, byte maxPower, SpecialSpeed endState = SpecialSpeed.Brake, SpeedProfiles profile = SpeedProfiles.None)
        {
            AssertValidSpeed(speed, nameof(speed));
            AssertValidMaxPower(maxPower, nameof(maxPower));
            AssertIsConnected();
            AssertIsVirtualPort();

            var response = await _protocol.SendPortOutputCommandAsync(new PortOutputCommandGotoAbsolutePosition2Message()
            {
                HubId                 = _hubId,
                PortId                = _portId,
                StartupInformation    = PortOutputCommandStartupInformation.ExecuteImmediately,
                CompletionInformation = PortOutputCommandCompletionInformation.CommandFeedback,
                AbsolutePosition1     = absolutePosition1,
                AbsolutePosition2     = absolutePosition2,
                Speed                 = speed,
                MaxPower              = maxPower,
                EndState              = endState,
                Profile               = profile,
            });

            return(response);
        }
コード例 #4
0
        /// <summary>
        /// Start the motors for Degrees and try to keep individual speeds using Speed(X) while using a maximum power of MaxPower. After Degrees is reached stop the outputs using the EndState.
        ///
        /// TachoMotor.StartSpeedForDegreesAsync support moving the motor by degrees. It operates relative of its current position.
        /// AbsoluteMotor.GotoAbsolutePositionAsync allows moving the motor to an absolute position. It operates relative to a changeable zero position.
        /// The Position(Observable) (POS) is reflecting the position relative to a changeable zero position (firmware in-memory encoded)
        /// The AbsolutePosition(Observable) (APOS) is reflecting the position relative to marked zero position (physically encoded).
        /// </summary>
        /// <param name="degrees">The degrees each motor should run. However, the combined degrees (2 * degrees) are split propertional among the speeds.</param>
        /// <param name="speedOnMotor1"></param>
        /// <param name="speedOnMotor2"></param>
        /// <param name="maxPower">Maximum Power level used.</param>
        /// <param name="endState">After time has expired, either Float, Hold or Brake. Defaults to Brake.</param>
        /// <param name="profile">The speed profiles used (as flags) for acceleration and deceleration. Defaults to None.</param>
        /// <returns></returns>
        public async Task <PortFeedback> StartSpeedForDegreesAsync(uint degrees, sbyte speedOnMotor1, sbyte speedOnMotor2, byte maxPower, SpecialSpeed endState = SpecialSpeed.Brake, SpeedProfiles profile = SpeedProfiles.None)
        {
            AssertValidDegrees(degrees, nameof(degrees));
            AssertValidSpeed(speedOnMotor1, nameof(speedOnMotor1));
            AssertValidSpeed(speedOnMotor2, nameof(speedOnMotor2));
            AssertValidMaxPower(maxPower, nameof(maxPower));
            AssertIsConnected();
            AssertIsVirtualPort();

            var response = await _protocol.SendPortOutputCommandAsync(new PortOutputCommandStartSpeedForDegrees2Message(
                                                                          _portId,
                                                                          PortOutputCommandStartupInformation.ExecuteImmediately, PortOutputCommandCompletionInformation.CommandFeedback,
                                                                          degrees,
                                                                          speedOnMotor1, speedOnMotor2,
                                                                          maxPower,
                                                                          endState,
                                                                          profile)
            {
                HubId = _hubId,
            });

            return(response);
        }
コード例 #5
0
 public void PortOutputCommandEncoder_Encode_PortOutputCommandStartSpeedForTime2Message(string expectedData, byte port, ushort time, sbyte speed1, sbyte speed2, byte maxPower, SpecialSpeed endState, SpeedProfiles profile)
 => PortOutputCommandEncoder_Encode(expectedData, new PortOutputCommandStartSpeedForTime2Message()
 {
     PortId                = port,
     StartupInformation    = PortOutputCommandStartupInformation.ExecuteImmediately,
     CompletionInformation = PortOutputCommandCompletionInformation.CommandFeedback,
     Time     = time,
     Speed1   = speed1,
     Speed2   = speed2,
     MaxPower = maxPower,
     EndState = endState,
     Profile  = profile,
 });
コード例 #6
0
 public void PortOutputCommandEncoder_Encode_PortOutputCommandSetDecTimeMessage(string expectedData, byte port, ushort time, SpeedProfiles profile)
 => PortOutputCommandEncoder_Encode(expectedData, new PortOutputCommandSetDecTimeMessage()
 {
     PortId                = port,
     StartupInformation    = PortOutputCommandStartupInformation.ExecuteImmediately,
     CompletionInformation = PortOutputCommandCompletionInformation.CommandFeedback,
     Time    = time,
     Profile = profile,
 });
コード例 #7
0
 public void PortOutputCommandEncoder_Encode_PortOutputCommandStartSpeedMessage(string expectedData, byte port, sbyte speed, byte maxPower, SpeedProfiles profile)
 => PortOutputCommandEncoder_Encode(expectedData, new PortOutputCommandStartSpeedMessage()
 {
     PortId                = port,
     StartupInformation    = PortOutputCommandStartupInformation.ExecuteImmediately,
     CompletionInformation = PortOutputCommandCompletionInformation.CommandFeedback,
     Speed    = speed,
     MaxPower = maxPower,
     Profile  = profile,
 });
コード例 #8
0
        /// <summary>
        /// Start the motors for Degrees and try to keep individual speeds using Speed(X) while using a maximum power of MaxPower. After Degrees is reached stop the outputs using the EndState.
        ///
        /// TachoMotor.StartSpeedForDegreesAsync support moving the motor by degrees. It operates relative of its current position.
        /// AbsoluteMotor.GotoAbsolutePositionAsync allows moving the motor to an absolute position. It operates relative to a changeable zero position.
        /// The Position(Observable) (POS) is reflecting the position relative to a changeable zero position (firmware in-memory encoded)
        /// The AbsolutePosition(Observable) (APOS) is reflecting the position relative to marked zero position (physically encoded).
        /// </summary>
        /// <param name="degrees"></param>
        /// <param name="speed"></param>
        /// <param name="maxPower">Maximum Power level used.</param>
        /// <param name="endState">After time has expired, either Float, Hold or Brake.</param>
        /// <param name="profile">The speed profiles used (as flags) for acceleration and deceleration</param>
        /// <returns></returns>
        public async Task <PortFeedback> StartSpeedForDegreesAsync(uint degrees, sbyte speed, byte maxPower, SpecialSpeed endState, SpeedProfiles profile)
        {
            AssertValidDegrees(degrees, nameof(degrees));
            AssertValidSpeed(speed, nameof(speed));
            AssertValidMaxPower(maxPower, nameof(maxPower));
            AssertIsConnected();

            var response = await _protocol.SendPortOutputCommandAsync(new PortOutputCommandStartSpeedForDegreesMessage()
            {
                HubId                 = _hubId,
                PortId                = _portId,
                StartupInformation    = PortOutputCommandStartupInformation.ExecuteImmediately,
                CompletionInformation = PortOutputCommandCompletionInformation.CommandFeedback,
                Degrees               = degrees,
                Speed                 = speed,
                MaxPower              = maxPower,
                EndState              = endState,
                Profile               = profile,
            });

            return(response);
        }
コード例 #9
0
 public void PortOutputCommandEncoder_Encode_PortOutputCommandGotoAbsolutePosition2Message(string expectedData, byte port, int absPos1, int absPos2, sbyte speed, byte maxPower, SpecialSpeed endState, SpeedProfiles profile)
 => PortOutputCommandEncoder_Encode(expectedData, new PortOutputCommandGotoAbsolutePosition2Message()
 {
     PortId                = port,
     StartupInformation    = PortOutputCommandStartupInformation.ExecuteImmediately,
     CompletionInformation = PortOutputCommandCompletionInformation.CommandFeedback,
     AbsolutePosition1     = absPos1,
     AbsolutePosition2     = absPos2,
     Speed    = speed,
     MaxPower = maxPower,
     EndState = endState,
     Profile  = profile,
 });
コード例 #10
0
        /// <summary>
        /// Start the motors for Time ms. And try to keep individual speeds using Speed(X) while using a maximum power of MaxPower. After Time stopping the outputs using the EndState.
        /// </summary>
        /// <param name="timeInMs"></param>
        /// <param name="speedOnMotor1">
        /// - Speed Level in Percentage: 1 - 100 (CW), -1 - -100 (CCW)
        /// - Stop Motor (hold position): 0 (use StartPower for floating and braking)
        /// </param>
        /// <param name="speedOnMotor2">
        /// - Speed Level in Percentage: 1 - 100 (CW), -1 - -100 (CCW)
        /// - Stop Motor (hold position): 0 (use StartPower for floating and braking)
        /// </param>
        /// <param name="maxPower">Maximum Power level used.</param>
        /// <param name="endState">After time has expired, either Float, Hold or Brake.</param>
        /// <param name="profile">The speed profiles used (as flags) for acceleration and deceleration</param>
        /// <returns></returns>
        public async Task <PortFeedback> StartSpeedForTimeAsync(ushort timeInMs, sbyte speedOnMotor1, sbyte speedOnMotor2, byte maxPower, SpecialSpeed endState, SpeedProfiles profile)
        {
            AssertValidSpeed(speedOnMotor1, nameof(speedOnMotor1));
            AssertValidSpeed(speedOnMotor2, nameof(speedOnMotor2));
            AssertValidMaxPower(maxPower, nameof(maxPower));
            AssertIsConnected();
            AssertIsVirtualPort();

            var response = await _protocol.SendPortOutputCommandAsync(new PortOutputCommandStartSpeedForTime2Message()
            {
                HubId                 = _hubId,
                PortId                = _portId,
                StartupInformation    = PortOutputCommandStartupInformation.ExecuteImmediately,
                CompletionInformation = PortOutputCommandCompletionInformation.CommandFeedback,
                Time     = timeInMs,
                Speed1   = speedOnMotor1,
                Speed2   = speedOnMotor2,
                MaxPower = maxPower,
                EndState = endState,
                Profile  = profile,
            });

            return(response);
        }
コード例 #11
0
 public void PortOutputCommandEncoder_Encode_PortOutputCommandStartSpeedForDegrees2Message(string expectedData, byte port, uint degrees, sbyte speed1, sbyte speed2, byte maxPower, SpecialSpeed endState, SpeedProfiles profile)
 => PortOutputCommandEncoder_Encode(expectedData, new PortOutputCommandStartSpeedForDegrees2Message(
                                        port,
                                        PortOutputCommandStartupInformation.ExecuteImmediately, PortOutputCommandCompletionInformation.CommandFeedback,
                                        Degrees: degrees,
                                        Speed1: speed1,
                                        Speed2: speed2,
                                        MaxPower: maxPower,
                                        EndState: endState,
                                        Profile: profile
                                        ));
コード例 #12
0
 public void PortOutputCommandEncoder_Encode_PortOutputCommandStartSpeedForTimeMessage(string expectedData, byte port, ushort time, sbyte speed, byte maxPower, SpecialSpeed endState, SpeedProfiles profile)
 => PortOutputCommandEncoder_Encode(expectedData, new PortOutputCommandStartSpeedForTimeMessage(
                                        port,
                                        PortOutputCommandStartupInformation.ExecuteImmediately, PortOutputCommandCompletionInformation.CommandFeedback,
                                        Time: time,
                                        Speed: speed,
                                        MaxPower: maxPower,
                                        EndState: endState,
                                        Profile: profile
                                        ));
コード例 #13
0
 public void PortOutputCommandEncoder_Encode_PortOutputCommandGotoAbsolutePosition2Message(string expectedData, byte port, int absPos1, int absPos2, sbyte speed, byte maxPower, SpecialSpeed endState, SpeedProfiles profile)
 => PortOutputCommandEncoder_Encode(expectedData, new PortOutputCommandGotoAbsolutePosition2Message(
                                        port,
                                        PortOutputCommandStartupInformation.ExecuteImmediately, PortOutputCommandCompletionInformation.CommandFeedback,
                                        AbsolutePosition1: absPos1,
                                        AbsolutePosition2: absPos2,
                                        Speed: speed,
                                        MaxPower: maxPower,
                                        EndState: endState,
                                        Profile: profile
                                        ));
コード例 #14
0
 public void PortOutputCommandEncoder_Encode_PortOutputCommandSetAccTimeMessage(string expectedData, byte port, ushort time, SpeedProfiles profile)
 => PortOutputCommandEncoder_Encode(expectedData, new PortOutputCommandSetAccTimeMessage(
                                        port,
                                        PortOutputCommandStartupInformation.ExecuteImmediately, PortOutputCommandCompletionInformation.CommandFeedback,
                                        Time: time,
                                        Profile: profile
                                        ));