Exemple #1
0
 private void Awake()
 {
     AgentController = GetComponentInParent <AgentController>();
     Dynamics        = GetComponentInParent <IVehicleDynamics>();
     Actions         = GetComponentInParent <VehicleActions>();
     RB = GetComponentInParent <Rigidbody>();
 }
        private void Start()
        {
            AgentController = GetComponentInParent <AgentController>();

            dynamics = GetComponentInParent <VehicleDynamics>();
            actions  = GetComponentInParent <VehicleActions>();

            Debug.Assert(dynamics != null);
            Debug.Assert(actions != null);
            Debug.Assert(SimulatorManager.Instance != null);

            controls = SimulatorManager.Instance.controls;

            if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Linux && Application.isEditor)
            {
                // empty
            }
            else
            {
                controls.Vehicle.Direction.started         += DirectionStarted;
                controls.Vehicle.Direction.performed       += DirectionPerformed;
                controls.Vehicle.Direction.canceled        += DirectionCanceled;
                controls.Vehicle.ShiftFirst.performed      += ShiftFirstPerformed;
                controls.Vehicle.ShiftReverse.performed    += ShiftReversePerformed;
                controls.Vehicle.ParkingBrake.performed    += ParkingBrakePerformed;
                controls.Vehicle.Ignition.performed        += IgnitionPerformed;
                controls.Vehicle.HeadLights.performed      += HeadLightsPerformed;
                controls.Vehicle.IndicatorLeft.performed   += IndicatorLeftPerformed;
                controls.Vehicle.IndicatorRight.performed  += IndicatorRightPerformed;
                controls.Vehicle.IndicatorHazard.performed += IndicatorHazardPerformed;
                controls.Vehicle.FogLights.performed       += FogLightsPerformed;
                controls.Vehicle.InteriorLight.performed   += InteriorLightPerformed;
            }
        }
        /// <summary>
        /// Get all Vehicles by id
        /// </summary>
        /// <param name="id">Used to get the vehicle by Id from the table</param>
        /// <returns></returns>
        public Vehicle GetVehicleById(int id)
        {
            VehicleActions v_action     = new VehicleActions();
            Vehicle        vehicleToGet = v_action.GetVehicle(id);

            return(vehicleToGet);
        }
 private void Awake()
 {
     RigidBody = GetComponentInParent <Rigidbody>();
     Actions   = GetComponentInParent <VehicleActions>();
     Dynamics  = GetComponentInParent <IVehicleDynamics>();
     MapOrigin = MapOrigin.Find();
 }
Exemple #5
0
        public void Move(VehicleActions action)
        {
            if (!Enum.IsDefined(typeof(VehicleActions), action))
            {
                throw new NotValidException($"Vehicle action is not valid ({action.ToString()})", null);
            }

            switch (action)
            {
            case VehicleActions.L:
                Vehicle.Turn(RelativeDirections.Left);
                break;

            case VehicleActions.R:
                Vehicle.Turn(RelativeDirections.Right);
                break;

            case VehicleActions.M:
                Vehicle.Forward();
                CheckPosition();
                break;

            default:
                throw new Exception($"Vehicle action is not implemented [{action.ToString()}]");
            }
        }
Exemple #6
0
        public void Move(VehicleActions vehicleAction)
        {
            if (!Enum.IsDefined(typeof(VehicleActions), vehicleAction))
            {
                throw new VehicleActionIsNotValidException(vehicleAction.ToString());
            }

            switch (vehicleAction)
            {
            case VehicleActions.L:
                Vehicle.Turn(RelativeDirections.Left);
                break;

            case VehicleActions.R:
                Vehicle.Turn(RelativeDirections.Right);
                break;

            case VehicleActions.M:
                Vehicle.GoForward();
                bool positionIsInSurface = Surface.Contains(Vehicle.CurrentPoint);
                if (!positionIsInSurface)
                {
                    throw new VehicleConnectionLostException();
                }
                break;

            default:
                throw new DevelopmentException($"There is uncovered switch-case state [{vehicleAction.ToString()}]");
            }
        }
Exemple #7
0
        protected override void Initialize()
        {
            Controller = GetComponentInParent <IAgentController>();
            Dynamics   = GetComponentInParent <IVehicleDynamics>();
            Actions    = GetComponentInParent <VehicleActions>();

            Debug.Assert(Dynamics != null);
            Debug.Assert(SimulatorManager.Instance != null);

            Controls = new KeyboardControlInputs();

            Controls.VehicleKeyboard.Direction.started         += DirectionStarted;
            Controls.VehicleKeyboard.Direction.performed       += DirectionPerformed;
            Controls.VehicleKeyboard.Direction.canceled        += DirectionCanceled;
            Controls.VehicleKeyboard.ShiftFirst.performed      += ShiftFirstPerformed;
            Controls.VehicleKeyboard.ShiftReverse.performed    += ShiftReversePerformed;
            Controls.VehicleKeyboard.ParkingBrake.performed    += ParkingBrakePerformed;
            Controls.VehicleKeyboard.Ignition.performed        += IgnitionPerformed;
            Controls.VehicleKeyboard.HeadLights.performed      += HeadLightsPerformed;
            Controls.VehicleKeyboard.IndicatorLeft.performed   += IndicatorLeftPerformed;
            Controls.VehicleKeyboard.IndicatorRight.performed  += IndicatorRightPerformed;
            Controls.VehicleKeyboard.IndicatorHazard.performed += IndicatorHazardPerformed;
            Controls.VehicleKeyboard.FogLights.performed       += FogLightsPerformed;
            Controls.VehicleKeyboard.InteriorLight.performed   += InteriorLightPerformed;

            Controls.Enable();
        }
        protected override void Initialize()
        {
            Controller = GetComponentInParent <IAgentController>();
            Dynamics   = GetComponentInParent <IVehicleDynamics>();
            Actions    = GetComponentInParent <VehicleActions>();

            Debug.Assert(Dynamics != null);
            Debug.Assert(SimulatorManager.Instance != null);

            Controls = new WheelControlSensorInput();

            Controls.VehicleWheel.Accel.performed        += AccelPerformed;
            Controls.VehicleWheel.Accel.canceled         += AccelCanceled;
            Controls.VehicleWheel.Brake.performed        += BrakePerformed;
            Controls.VehicleWheel.Brake.canceled         += BrakeCanceled;
            Controls.VehicleWheel.Steer.performed        += SteerPerformed;
            Controls.VehicleWheel.ButtonA.performed      += ButtonA;
            Controls.VehicleWheel.ButtonB.performed      += ButtonB;
            Controls.VehicleWheel.ButtonX.performed      += ButtonX;
            Controls.VehicleWheel.ButtonY.performed      += ButtonY;
            Controls.VehicleWheel.ButtonRB.performed     += ButtonRB;
            Controls.VehicleWheel.ButtonLB.performed     += ButtonLB;
            Controls.VehicleWheel.ButtonSelect.performed += ButtonSelect;
            Controls.VehicleWheel.ButtonStart.performed  += ButtonStart;
            Controls.VehicleWheel.ButtonRSB.performed    += ButtonRSB;
            Controls.VehicleWheel.ButtonLSB.performed    += ButtonLSB;
            Controls.VehicleWheel.ButtonCenter.performed += ButtonCenter;
            Controls.VehicleWheel.DPad.performed         += DPad;

            Controls.Enable();
        }
Exemple #9
0
        private void Start()
        {
            AgentController = GetComponentInParent <AgentController>();

            dynamics = GetComponentInParent <VehicleDynamics>();
            actions  = GetComponentInParent <VehicleActions>();

            Debug.Assert(dynamics != null);
            Debug.Assert(actions != null);
            Debug.Assert(SimulatorManager.Instance != null);

            controls = SimulatorManager.Instance.controls;
            controls.VehicleWheel.Accel.performed        += AccelPerformed;
            controls.VehicleWheel.Accel.canceled         += AccelCanceled;
            controls.VehicleWheel.Brake.performed        += BrakePerformed;
            controls.VehicleWheel.Brake.canceled         += BrakeCanceled;
            controls.VehicleWheel.Steer.performed        += SteerPerformed;
            controls.VehicleWheel.ButtonA.performed      += ButtonA;
            controls.VehicleWheel.ButtonB.performed      += ButtonB;
            controls.VehicleWheel.ButtonX.performed      += ButtonX;
            controls.VehicleWheel.ButtonY.performed      += ButtonY;
            controls.VehicleWheel.ButtonRB.performed     += ButtonRB;
            controls.VehicleWheel.ButtonLB.performed     += ButtonLB;
            controls.VehicleWheel.ButtonSelect.performed += ButtonSelect;
            controls.VehicleWheel.ButtonStart.performed  += ButtonStart;
            controls.VehicleWheel.ButtonRSB.performed    += ButtonRSB;
            controls.VehicleWheel.ButtonLSB.performed    += ButtonLSB;
            controls.VehicleWheel.ButtonCenter.performed += ButtonCenter;
            controls.VehicleWheel.DPad.performed         += DPad;
        }
Exemple #10
0
 public override void Init()
 {
     Dynamics   = GetComponent <IVehicleDynamics>();
     Actions    = GetComponent <VehicleActions>();
     Controller = GetComponent <IAgentController>();
     Inputs.AddRange(GetComponentsInChildren <IVehicleInputs>());
     InitialPosition = transform.position;
     InitialRotation = transform.rotation;
 }
Exemple #11
0
 public override void Init()
 {
     startTime   = SimulatorManager.Instance.CurrentTime;
     vehicleName = transform.root.name;
     dynamics    = GetComponent <VehicleDynamics>();
     actions     = GetComponent <VehicleActions>();
     inputs.AddRange(GetComponentsInChildren <IVehicleInputs>());
     initialPosition = transform.position;
     initialRotation = transform.rotation;
 }
Exemple #12
0
        public override void OnBridgeSetup(IBridge bridge)
        {
            Bridge = bridge;
            Writer = bridge.AddWriter <CanBusData>(Topic);

            RigidBody = GetComponentInParent <Rigidbody>();
            Actions   = GetComponentInParent <VehicleActions>();
            Dynamics  = GetComponentInParent <VehicleDynamics>();
            MapOrigin = MapOrigin.Find();
        }
Exemple #13
0
        public void Test_IncorrectDelete()
        {
            Vehicle prius = new Vehicle
            {
                Id    = 60,
                Make  = "Honda",
                Model = "Civic",
                Year  = 1900
            };

            var vp = new VehicleActions();

            vp.SaveVehicle(prius);
        }
Exemple #14
0
        public void ActionIsTurn__VehicleTurnMethodWillBeInvoked(VehicleActions vehicleAction, CompassDirections expectedDirection)
        {
            const int x = 0;
            const int y = 0;
            const CompassDirections direction = CompassDirections.N;

            var rover = new Rover(x, y, direction);
            var sut   = new RoverContext(_surfaceMock.Object,
                                         rover);

            sut.Move(vehicleAction);

            Assert.Equal(x, sut.Vehicle.CurrentPoint.X);
            Assert.Equal(y, sut.Vehicle.CurrentPoint.Y);
            Assert.Equal(expectedDirection, sut.Vehicle.Facade);
        }
        /// <summary>
        /// Save the vehicle to the database
        /// </summary>
        /// <param name="vehicleToSave">The vehicle that is going to be save to the databse</param>
        /// <returns></returns>
        public HttpResponseMessage Post_Save_Vehicle([FromBody] Vehicle vehicleToSave)
        {
            VehicleActions      v_action = new VehicleActions();
            HttpResponseMessage response;
            int id = v_action.SaveVehicle(vehicleToSave);

            //Check that values for year, make and model are valid
            if (id == -1)
            {
                response = Request.CreateResponse(HttpStatusCode.NotAcceptable);
                return(response);
            }

            vehicleToSave.Id          = id;
            response                  = Request.CreateResponse(HttpStatusCode.Created);
            response.Headers.Location = new Uri(Request.RequestUri, String.Format("/{0}", id));
            return(response);
        }
        /// <summary>
        /// Delete a vehicle by id
        /// </summary>
        /// <param name="id">Used to specify which vehicle to delete from the database</param>
        /// <returns></returns>
        public HttpResponseMessage DeleteVehicle(int id)
        {
            VehicleActions pp            = new VehicleActions();
            bool           recordExisted = false;

            recordExisted = pp.DeleteVehicle(id);

            HttpResponseMessage response;

            if (recordExisted)
            {
                response = Request.CreateResponse(HttpStatusCode.NoContent);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound);
            }
            return(response);
        }
        public HttpResponseMessage PUT(int id, [FromBody] Vehicle vehicleToUpdate)
        {
            VehicleActions pp = new VehicleActions();

            vehicleToUpdate.Id = id;
            bool recordExisted = false;

            recordExisted = pp.UpdateVehicle(id, vehicleToUpdate);

            HttpResponseMessage response;

            if (recordExisted)
            {
                response = Request.CreateResponse(HttpStatusCode.NoContent);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound);
            }

            return(response);
        }
 protected override void Initialize()
 {
     Actions   = GetComponentInParent <VehicleActions>();
     Dynamics  = GetComponentInParent <IVehicleDynamics>();
     StateData = new VehicleStateData();
 }
Exemple #19
0
 void Start()
 {
     Actions   = GetComponentInParent <VehicleActions>();
     Dynamics  = GetComponentInParent <VehicleDynamics>();
     StateData = new VehicleStateData();
 }