Exemplo n.º 1
0
 public IEnumerator <ITask> ReplaceHandler(motor.Replace replace)
 {
     _state = replace.Body;
     SaveState(_state);
     replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
     yield break;
 }
        /// <summary>
        /// Copy generic state to this state, transforming data members.
        /// </summary>
        /// <param name="genericState"></param>
        public void CopyFromGenericState(pxmotor.MotorState genericState)
        {
            if (!string.IsNullOrEmpty(genericState.Name))
            {
                this.Name = genericState.Name;
            }

            switch (genericState.HardwareIdentifier)
            {
            case 1:
                this.MotorPort = NxtMotorPort.MotorA;
                break;

            case 2:
                this.MotorPort = NxtMotorPort.MotorB;
                break;

            case 3:
                this.MotorPort = NxtMotorPort.MotorC;
                break;
            }

            this.TargetPower     = genericState.CurrentPower;
            this.ReversePolarity = genericState.ReversePolarity;
        }
        /// <summary>
        /// Transform current state to the specified generic state.
        /// </summary>
        /// <param name="genericState"></param>
        /// <returns></returns>
        public pxmotor.MotorState ToGenericState(pxmotor.MotorState genericState)
        {
            genericState.Name = this.Name;

            switch (this.MotorPort)
            {
            case NxtMotorPort.MotorA:
                genericState.HardwareIdentifier = 1;
                break;

            case NxtMotorPort.MotorB:
                genericState.HardwareIdentifier = 2;
                break;

            case NxtMotorPort.MotorC:
                genericState.HardwareIdentifier = 3;
                break;

            default:
                genericState.HardwareIdentifier = 0;
                break;
            }

            genericState.CurrentPower       = this.TargetPower;
            genericState.ReversePolarity    = this.ReversePolarity;
            genericState.PowerScalingFactor = 100.0;
            return(genericState);
        }
Exemplo n.º 4
0
 public virtual IEnumerator <ITask> ReplaceHandler(motor.Replace replace)
 {
     LogInfo(string.Format("Configuring {0} to port {1}", replace.Body.Name, replace.Body.HardwareIdentifier));
     _state = replace.Body;
     replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
     SaveState(_state);
     yield break;
 }
Exemplo n.º 5
0
        protected override void Start()
        {
            // call base Start() method that will activate operation handlers, log uri, insert to directory
            base.Start();

            // initialize default state.
            // we expect the drive to set actual state for us (in ReplaceHandler).
            if (_state == null)
            {
                _state = new pxmotor.MotorState();
                _state.PowerScalingFactor = 10.0d;                      // actually will be percent, for example 40.0d
                _state.HardwareIdentifier = 1;                          // 1=Left 2=Right
                _state.Name         = "Left";
                _state.CurrentPower = 0.0;
            }
        }
Exemplo n.º 6
0
        protected override void Start()
        {
            //configure motor
            if (_state == null)
            {
                _state = new motor.MotorState("Unconfigured Motor", 1, 100, false, new PhysicalModel.Proxy.Pose());

                SaveState(_state);
            }

            // Listen for each of my handlers
            ActivateDsspOperationHandlers();

            // Insert ourselves into the directory so that others can find us
            DirectoryInsert();

            // display HTTP service Uri
            LogInfo(LogGroups.Console, "Service uri: ");
        }
Exemplo n.º 7
0
        /// <summary>
        /// Service Start
        /// </summary>
        protected override void Start()
        {
            if (_state == null)
            {
                _state = new motor.MotorState();
                _state.Name = "LeftMotor";       
                //NOTE: name must contain either 'left' or 'right'
                //default name is 'left' for use in Tutorial 2
                //name should really be loaded by manifest
            }

            // Listen on the main port for requests and call the appropriate handler.
            ActivateDsspOperationHandlers();

            // Publish the service to the local Node Directory
            DirectoryInsert();

			// display HTTP service Uri
			LogInfo(LogGroups.Console, "Service uri: ");
        }
Exemplo n.º 8
0
        /// <summary>
        /// Service Start
        /// </summary>
        protected override void Start()
        {
            if (_state == null)
            {
                _state      = new motor.MotorState();
                _state.Name = "LeftMotor";
                //NOTE: name must contain either 'left' or 'right'
                //default name is 'left' for use in Tutorial 2
                //name should really be loaded by manifest
            }

            // Listen on the main port for requests and call the appropriate handler.
            ActivateDsspOperationHandlers();

            // Publish the service to the local Node Directory
            DirectoryInsert();

            // display HTTP service Uri
            LogInfo(LogGroups.Console, "Service uri: ");
        }
Exemplo n.º 9
0
        protected override void Start()
        {
            // Motor is uninitialized
            if (_state == null)
            {
                _state = new motor.MotorState();
                _state.HardwareIdentifier = 1;
                _state.Name               = "Default Surveyor SRV-1 Motor on Port 1";
                _state.CurrentPower       = 0.0;
                _state.PowerScalingFactor = 1.0;
                SaveState(_state);
            }

            // Listen on the main port for requests and call the appropriate handler.
            ActivateDsspOperationHandlers();

            // Publish the service to the local Node Directory
            DirectoryInsert();

            // display HTTP service Uri
            LogInfo(LogGroups.Console, "Service uri: ");
        }
Exemplo n.º 10
0
 public virtual IEnumerator<ITask> ReplaceHandler(motor.Replace replace)
 {
     _state = replace.Body;
     replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
     yield break;
 }
Exemplo n.º 11
0
        protected override void Start()
        {
            // call base Start() method that will activate operation handlers, log uri, insert to directory
            base.Start();

            // initialize default state.
            // we expect the drive to set actual state for us (in ReplaceHandler).
            if (_state == null)
            {
                _state = new pxmotor.MotorState();
                _state.PowerScalingFactor = 10.0d;      // actually will be percent, for example 40.0d
                _state.HardwareIdentifier = 1;			// 1=Left 2=Right
                _state.Name = "Left";
                _state.CurrentPower = 0.0;
            }
        }
Exemplo n.º 12
0
 public virtual IEnumerator <ITask> ReplaceHandler(pxmotor.Replace replace)
 {
     _state = replace.Body;
     replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
     yield break;
 }
Exemplo n.º 13
0
        public IEnumerator <ITask> ConfigureDrive(DriveState state)
        {
            PartnerType leftMotorPartner  = this.ServiceInfo.PartnerList.Find(delegate(PartnerType partner) { return(partner.Name.Name == "LeftMotor"); });
            PartnerType rightMotorPartner = this.ServiceInfo.PartnerList.Find(delegate(PartnerType partner) { return(partner.Name.Name == "RightMotor"); });

            // Configure the left motor connection
            motorbase.MotorState Lconfigure = new motorbase.MotorState();
            Lconfigure.HardwareIdentifier = _state.LeftMotorPortNumber;
            Lconfigure.Name = "Left Motor";
            Lconfigure.PowerScalingFactor = 1;
            yield return(Arbiter.Choice(_leftMotorPort.Replace(Lconfigure),
                                        delegate(DefaultReplaceResponseType success)
            {
                LogInfo("Left Motor Port set");
            },
                                        delegate(Fault fault)
            {
                LogError(fault);
                _initFault = true;
            }));

            if (_initFault)
            {
                yield break;
            }

            // Configure the right motor connection
            motorbase.MotorState Rconfigure = new motorbase.MotorState();
            Rconfigure.HardwareIdentifier = _state.RightMotorPortNumber;
            Rconfigure.Name = "Right Motor";
            Rconfigure.PowerScalingFactor = 1;
            yield return(Arbiter.Choice(_rightMotorPort.Replace(Rconfigure),
                                        delegate(DefaultReplaceResponseType success)
            {
                LogInfo("Right Motor Port set");
            },
                                        delegate(Fault fault)
            {
                LogError(fault);
                _initFault = true;
            }));

            if (_initFault)
            {
                yield break;
            }

            // Configure the drive service
            drivesrv.DriveDifferentialTwoWheelState driveState = new drivesrv.DriveDifferentialTwoWheelState();
            driveState.DistanceBetweenWheels  = state.DistanceBetweenWheels;
            driveState.TimeStamp              = DateTime.Now;
            driveState.LeftWheel              = new motorbase.WheeledMotorState();
            driveState.LeftWheel.Radius       = _state.WheelRadius;
            driveState.LeftWheel.Name         = "Left Wheel";
            driveState.LeftWheel.MotorState   = new motorbase.MotorState();
            driveState.LeftWheel.GearRatio    = 1.0;
            driveState.LeftWheel.EncoderState = new encoderbase.EncoderState();

            driveState.RightWheel              = new motorbase.WheeledMotorState();
            driveState.RightWheel.Radius       = _state.WheelRadius;
            driveState.RightWheel.Name         = "Right Wheel";
            driveState.RightWheel.MotorState   = new motorbase.MotorState();
            driveState.RightWheel.GearRatio    = 1.0;
            driveState.RightWheel.EncoderState = new encoderbase.EncoderState();

            driveState.IsEnabled = true;

            yield return(Arbiter.Choice(_drivePort.Update(driveState),
                                        delegate(DefaultUpdateResponseType success)
            {
                LogInfo("Drive configuration updated");
            },
                                        delegate(Fault f)
            {
                LogError(f);
                _initFault = true;
            }));

            if (_initFault)
            {
                yield break;
            }


            drivesrv.EnableDriveRequest en = new drivesrv.EnableDriveRequest();
            en.Enable = true;
            yield return(Arbiter.Receive <DefaultUpdateResponseType>(false, _drivePort.EnableDrive(en),
                                                                     delegate(DefaultUpdateResponseType response){}));

            yield break;
        }