Пример #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            InitalizeSerialCommunication();

            lowerLeftBumper      = new Bumper();
            upperLeftBumper      = new Bumper();
            upperRightBumper     = new Bumper();
            lowerRightBumper     = new Bumper();
            wheels               = new CoupledWheels();
            wheels.ClicksPerTurn = 3900;
            wheels.WheelDistance = 0.345f;
            wheels.WheelRadius   = 0.0467f;
            wheels.Updated      += new EventHandler(wheels_Updated);

            sonar0 = new MaxbotixSonar();
            sonar1 = new MaxbotixSonar();
            sonar2 = new MaxbotixSonar();
            sonar3 = new MaxbotixSonar();
            sonar4 = new MaxbotixSonar();

            groundSensor0 = new InfraredSensor();
            groundSensor1 = new InfraredSensor();
            groundSensor2 = new InfraredSensor();

            redLed   = new LedPwm();
            greenLed = new LedPwm();
            blueLed  = new LedPwm();

            drive     = new DifferentialDrive(wheels);
            odometry  = new DifferentialOdometry(wheels);
            proximity = new ProximityArray
            {
                { new Transform(0.15f, 0.14f, MathHelper.ToRadians(45)), sonar0 },
                { new Transform(0.165f, 0.07f, MathHelper.ToRadians(20)), sonar1 },
                { new Transform(0.18f, 0.0f, MathHelper.ToRadians(0)), sonar2 },
                { new Transform(0.165f, -0.07f, MathHelper.ToRadians(-20)), sonar3 },
                { new Transform(0.15f, -0.14f, MathHelper.ToRadians(-45)), sonar4 },
            };

            protocol = new ProtocolManager();
            protocol.SubscribeComponent(lowerLeftBumper);
            protocol.SubscribeComponent(upperLeftBumper);
            protocol.SubscribeComponent(upperRightBumper);
            protocol.SubscribeComponent(lowerRightBumper);
            protocol.SubscribeComponent(wheels);
            protocol.SubscribeComponent(sonar0);
            protocol.SubscribeComponent(sonar1);
            protocol.SubscribeComponent(sonar2);
            protocol.SubscribeComponent(sonar3);
            protocol.SubscribeComponent(sonar4);
            protocol.SubscribeComponent(groundSensor0);
            protocol.SubscribeComponent(groundSensor1);
            protocol.SubscribeComponent(groundSensor2);
            protocol.SubscribeComponent(greenLed);
            protocol.SubscribeComponent(redLed);
            protocol.SubscribeComponent(blueLed);
            transport.Protocol = protocol;

            renderer = new SpriteRenderer(this);
            renderer.PixelsPerMeter = 100;
            Components.Add(renderer);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), spriteBatch);

            base.Initialize();
        }
Пример #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            InitalizeSerialCommunication();

            lowerLeftBumper = new Bumper();
            upperLeftBumper = new Bumper();
            upperRightBumper = new Bumper();
            lowerRightBumper = new Bumper();
            wheels = new CoupledWheels();
            wheels.ClicksPerTurn = 3900;
            wheels.WheelDistance = 0.345f;
            wheels.WheelRadius = 0.0467f;
            wheels.Updated += new EventHandler(wheels_Updated);

            sonar0 = new MaxbotixSonar();
            sonar1 = new MaxbotixSonar();
            sonar2 = new MaxbotixSonar();
            sonar3 = new MaxbotixSonar();
            sonar4 = new MaxbotixSonar();

            groundSensor0 = new InfraredSensor();
            groundSensor1 = new InfraredSensor();
            groundSensor2 = new InfraredSensor();

            redLed = new LedPwm();
            greenLed = new LedPwm();
            blueLed = new LedPwm();

            drive = new DifferentialDrive(wheels);
            odometry = new DifferentialOdometry(wheels);
            proximity = new ProximityArray
            {
                { new Transform(0.15f, 0.14f, MathHelper.ToRadians(45)), sonar0 },
                { new Transform(0.165f, 0.07f, MathHelper.ToRadians(20)), sonar1 },
                { new Transform(0.18f, 0.0f, MathHelper.ToRadians(0)), sonar2 },
                { new Transform(0.165f, -0.07f, MathHelper.ToRadians(-20)), sonar3 },
                { new Transform(0.15f, -0.14f, MathHelper.ToRadians(-45)), sonar4 },
            };

            protocol = new ProtocolManager();
            protocol.SubscribeComponent(lowerLeftBumper);
            protocol.SubscribeComponent(upperLeftBumper);
            protocol.SubscribeComponent(upperRightBumper);
            protocol.SubscribeComponent(lowerRightBumper);
            protocol.SubscribeComponent(wheels);
            protocol.SubscribeComponent(sonar0);
            protocol.SubscribeComponent(sonar1);
            protocol.SubscribeComponent(sonar2);
            protocol.SubscribeComponent(sonar3);
            protocol.SubscribeComponent(sonar4);
            protocol.SubscribeComponent(groundSensor0);
            protocol.SubscribeComponent(groundSensor1);
            protocol.SubscribeComponent(groundSensor2);
            protocol.SubscribeComponent(greenLed);
            protocol.SubscribeComponent(redLed);
            protocol.SubscribeComponent(blueLed);
            transport.Protocol = protocol;

            renderer = new SpriteRenderer(this);
            renderer.PixelsPerMeter = 100;
            Components.Add(renderer);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), spriteBatch);

            base.Initialize();
        }