コード例 #1
0
        /// <summary>
        /// Constructor to be called by Student Code.
        /// Creates the radio's and student code's threads.
        /// </summary>
        public Master(RobotCode s)
        {
            // Makes this robot run the student's code
            student = s;
            robot = s.getRobot();
            // Create and set radio threads
            rfPollThread = new Thread(RunRFPoll);
            rfPollThread.Priority = ThreadPriority.AboveNormal;
            rfTeleThread = new Thread(RunRFTele);
            rfTeleThread.Priority = ThreadPriority.AboveNormal;

            // Create and set student code threads
            studentCodeThread = new Thread(RunStudent);
            studentCodeThread.Priority = ThreadPriority.AboveNormal;
            autonomousThread = new Thread(RunAutono);
            autonomousThread.Priority = ThreadPriority.BelowNormal;

            // Initialize LEDs
            robot.yellowLED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.IO59, false);
            robot.redLED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.IO60, false);

            // Disable
            Debug.EnableGCMessages(false);

            // Run the robot once to initialize
            robot.Run();
        }
 public SharpDistanceTracker(Robot robo, int pin)
 {
     robot = robo;
     robot.sensors.Add(this);
     sharp = GetPort(pin);
     sharp.SetLinearScale(0, 255);
 }
        public MicroMaestro(Robot robo, string portName, int deviceNum)
        {
            robot = robo;
            deviceNumber = deviceNum;
            robot.actuators.Add(this);
            canMove = true;
            minRotation = new double[6];
            maxRotation = new double[6];
            targets = new double[6];
            speeds = new double[6];
            accelerations = new double[6];

            for (int i = 0; i < 6; i++)
            {
                minRotation[i] = 0;
                maxRotation[i] = 180;
                targets[i] = -1;
                speeds[i] = 50;
                accelerations[i] = 50;
            }

            port = new SerialPort(portName, 9600, Parity.None, 8, StopBits.One);
            port.ReadTimeout = 2;
            port.Open();
        }
コード例 #4
0
 public Program()
 {
     Robot robot = new Robot("1", "COM4");
     smc = new SimpleMotorController(robot, "COM1", 14);
     sdt = new SharpDistanceTracker(robot, 1);
     Thread.Sleep(1000);
     while (true)
     {
         if (true)//sdt.ReadSensor() > 200)
         {
             // read the values controlling the left joystick, map to values from -100 to 100
             // set the motor speed magnitude as the 100 * square root of |spd|/100, for one nonlinear joystick to motor speed mapping
             smc.motorBrake = 0;
             double spd = ((double)(robot.UIAnalogVals[1] - 128) * 100 / (double)128);
             if(spd > 0)
                 smc.motorSpeed = System.Math.Pow((spd / (double)100), .5) * 100;
             else
                 smc.motorSpeed = -1 * System.Math.Pow(((-1*spd) / (double)100), .5) * 100;
         }
         else
         {
             smc.motorBrake = 0;
             double spd = -50;
             smc.motorSpeed = System.Math.Pow((spd / (double)100), .5) * 100;
         }
         Thread.Sleep(500);
     }
 }
コード例 #5
0
        // Static initialization
        // TODO share serial port with Micro Maestro
        // The ATtiny2313A is programmed for a 38400 baud UART.
        /// <summary>
        /// Initialize a quadrature encoder on the given channel.
        /// </summary>
        /// <param name="channel">encoder channel (0-3)</param>
        public Encoder(Robot robot, byte channel)
        {
            this.channel = channel;

            //create new port or use already existing port
            foreach (SerialPort pts in robot.ports)
            {
                if (pts.PortName == "COM2")
                {
                    serial = pts;
                }
            }

            if (serial == null)
            {
                serial = new SerialPort("COM2", 38400, Parity.None, 8, StopBits.One);
                robot.ports.Add(serial);
                serial.ReadTimeout = 2;
                serial.Open();
            }

            // Initialize start byte and address in output buffer
            outBuf[0] = 0xAA;
            outBuf[1] = POLOLU_ADDRESS;

            this.Reset();
        }
 //private MicroMaestro mm;
 //private int timer;
 /// <summary>
 /// Main method which initializes the robot, and creates
 /// the radio's and student code's threads. Begins running
 /// the threads, and then runs the robot thread indefinitely.
 /// </summary>       
 public static void Main()
 {
     // Initialize robot
     Robot robot = new Robot("1", "COM4");
     robot.Auton(false);
     Master master = new Master(new StudentCode(robot));
     master.RunCode();
 }
 ///program.Run(window);
 // Constructor
 public StudentCode(Robot robot)
 {
     this.robot = robot;
     smcR = new SimpleMotorController(robot, 13); //let's say 13 is right motor on drivetrain
     smcL = new SimpleMotorController(robot, 14); //let's say 14 is left motor on drivetrain
     //mm = new MicroMaestro(robot, 12);
     timer = 0;
 }
コード例 #8
0
ファイル: AnalogSensor.cs プロジェクト: RohanR/pie-software
        private double value; /**< value of this sensor */

        #endregion Fields

        #region Constructors

        /**
         * The constructor of AnalogSensor.
         * It initiates the value scale, and add itself to the global list of sensors.
         *
         * @param PinNumber    the number of pin where this sensor is attached.
         * @param robot        the robot to which this sensor belongs.
         */
        public AnalogSensor(int PinNumber, Robot robot)
            : base(robot)
        {
            this.Analog = GetAnalogPort(PinNumber);
            this.Analog.SetLinearScale(0, 1023);
            this.value = 0.0d;
            this.addToGlobalList();
        }
コード例 #9
0
ファイル: StudentCode.cs プロジェクト: RohanR/pie-software
 /// <summary>
 /// Main method which initializes the robot, and starts
 /// it running.
 /// </summary>       
 public static void Main()
 {
     // Initialize robot
     Robot robot = new Robot("1", "COM4");
     robot.Auton(false);
     Debug.Print("Code loaded successfully!");
     Master master = new Master(new StudentCode(robot));
     master.RunCode();
 }
コード例 #10
0
        // Constructor
        public StudentCode(Robot robot)
        {
            this.robot = robot;
            //smcR = new SimpleMotorController(robot, 13); //let's say 13 is right motor on drivetrain
            //smcL = new SimpleMotorController(robot, 14); //let's say 14 is left motor on drivetrain
            //mm = new MicroMaestro(robot, 12);

            i2c1 = new I2CMotorController(robot, 0x0A);
            i2c2 = new I2CMotorController(robot, 0x0B);
               /* switchL = new DigitalSwitch(1);
            switchR = new DigitalSwitch(2);
            rfL = new SharpDistanceTracker(0);
            rfR = new SharpDistanceTracker(1);*/
            //accel = new AnalogReflectanceSensor(0);
            sensor1 = new AnalogReflectanceSensor(1);
            sensor2 = new AnalogReflectanceSensor(2);
            sensor3 = new AnalogReflectanceSensor(3);
            sensor4 = new AnalogReflectanceSensor(4);
            rfR1 = 0;
            rfR2 = 0;
            rfL1 = 0;
            rfL2 = 0;
            timer = 0;/**/
        }

        #endregion Constructors

        #region Methods

        /// <summary>
        /// The robot will call this method every time it needs to run the autonomous student code
        /// The StudentCode should basically treat this as a chance to change motors and servos based on
        /// non user-controlled input like sensors. But you don't need sensors, as this example demonstrates.
        /// </summary>
        public void AutonomousCode()
        {
            //Debug.Print("Auton");

            //always set motorBrake to 0 to move motors.
            /*smcL.motorBrake = 0;
            smcR.motorBrake = 0;

            //move one wheel full forward and one wheel full backward. Circling like a crazy person is fun.
            smcL.motorSpeed = 100;
            smcR.motorSpeed = -100;

            // But wait... there's more!
            // This will wait for 1000 milliseconds (1 second) and then reverse the direction of turning.
            // Generally *avoid* sleeping because it will add up fast and dramatically reduce responsiveness!

            Thread.Sleep(1000);
            smcL.motorSpeed = -100;
            smcR.motorSpeed = 100;
            */
        }
コード例 #11
0
        // Constructor
        public StudentCode(Robot robot)
        {
            this.robot = robot;
            //            pot = new AnalogIn(AnalogIn.Pin.Ain0);
              //          IR = new AnalogIn(AnalogIn.Pin.Ain1);

            smcR = new SimpleMotorController(robot, 13); //let's say 13 is right motor on drivetrain
            smcL = new SimpleMotorController(robot, 14); //let's say 14 is left motor on drivetrain
            //            armMotor = new SimpleMotorController(robot, 15); // TODO: Port 15 is the arm motor
            distanceS = new SharpDistanceTracker(0, 2); //We are using a long distance sensor
            timer = 0;
        }
        public SimpleMotorController(Robot robot, int deviceNum)
        {
            this.robot = robot;
            this.deviceNumber = deviceNum;
            this.port = robot.motorPort;

            // Enable the motor controller (exit Safe-Start mode)
            byte[] exitSafe = new byte[3];
            exitSafe[0] = (byte)0xAA;
            exitSafe[1] = (byte)deviceNumber;
            exitSafe[2] = (byte)0x03;
            port.Write(exitSafe, 0, 3);
            //Thread.Sleep(1000);
        }
 public SimpleMotorController(Robot robo, String pt, int deviceNum)
 {
     robot = robo;
     deviceNumber = deviceNum;
     port = new SerialPort(pt, 9600, Parity.None, 8, StopBits.One);
     port.ReadTimeout = 2;
     port.Open();
     byte[] exitSafe = new byte[3];
     exitSafe[0] = (byte)0xAA;
     exitSafe[1] = (byte)0x0D;
     exitSafe[2] = (byte)0x03;
     port.Write(exitSafe, 0, 3);
     Thread.Sleep(1000);
 }
コード例 #14
0
        /* Constructor
         * Takes a robot as argument so that the code
         * knows which robot to control (the main method could
         * theoretically control multiple robots), and so that
         * the robot is accesable
         */
        public StudentCode(Robot robot)
        {
            Button = new InputPort((Cpu.Pin)FEZ_Pin.Digital.IO4, true, Port.ResistorMode.PullUp);
            lLightSens = new AnalogIn((AnalogIn.Pin) FEZ_Pin.AnalogIn.An1);
            rLightSens = new AnalogIn((AnalogIn.Pin) FEZ_Pin.AnalogIn.An0);
               // lLightSens.SetLinearScale(0, 10000);
               // rLightSens.SetLinearScale(0, 10000);
            this.robot = robot;
            leftMotor = new SimpleMotorController(robot, "COM1", 13);
            rightMotor = new SimpleMotorController(robot, "COM1", 14);  //Check
            rightMotor.motorBrake = 0;
            leftMotor.motorBrake = 0;

             //     sdt = new SharpDistanceTracker(robot, 0);
        }
コード例 #15
0
        public static void Main()
        {
            /*robot object creates its own StudentCode object
            The robot object then calls the UserControlledCode
            and the AutonomousCode methods from within threads.
            The robot object is thus able to switch between autonomous
            and teleoperated period by controlling the execution of
            these threads
             */
            Robot robot = new Robot("1", "COM4");

            while (true)
            {
                Thread.Sleep(50);
            }
        }
コード例 #16
0
        public static void Main()
        {
            Robot robot = new Robot("1");
            /*
            SimpleMotorController leftMotor = new SimpleMotorController(robot, 13),
                rightMotor = new SimpleMotorController(robot, 14);

            // Set motor brake/coast behavior (0 = full coast, 10 = full brake)
            leftMotor.motorBrake = 0;
            rightMotor.motorBrake = 0;
             */
            while (true)
            {

            }
        }
コード例 #17
0
 // Constructor
 public StudentCode(Robot robot)
 {
     this.robot = robot;
     smcR = new SimpleMotorController(robot, 13); //let's say 13 is right motor on drivetrain
     smcL = new SimpleMotorController(robot, 14); //let's say 14 is left motor on drivetrain
     mm = new MicroMaestro(robot, 12);
     encL = new Encoder(robot, 0);
     encR = new Encoder(robot, 1);
     pidL = new PIDController(KP, KI, KD);
     pidR = new PIDController(KP, KI, KD);
     sDT1 = new SharpDistanceTracker(0);
     sDT2 = new SharpDistanceTracker(1);
     sDT3 = new SharpDistanceTracker(2);
     sDT4 = new SharpDistanceTracker(3);
     sDT5 = new SharpDistanceTracker(4);
 }
        /// <summary>
        /// Ensure to instantiate the MicroMaestro with the Robot given to the student and the device num (probably 12)
        /// This will take care of connecting the MicroMaestro to the robot's system
        /// </summary>
        /// <param name="robo"></param>
        /// <param name="deviceNum"></param>
        public MicroMaestro(Robot robo, int deviceNum)
        {
            robot = robo;
            deviceNumber = deviceNum;
            robot.actuators.Add(this);
            canMove = true;
            minRotation = new float[6];
            maxRotation = new float[6];
            targets = new float[6];
            speeds = new float[6];
            prevVal = new float[6];

            // Copies of speeds and targets
            speedsCopy = new float[6];
            targetsCopy = new float[6];

            for (int i = 0; i < 6; i++)
            {
                minRotation[i] = 0;
                maxRotation[i] = 180;
                targets[i] = -1;
                speeds[i] = 20;

                speedsCopy[i] = 0;
                targetsCopy[i] = minRotation[i] - 1;
            }

            //create new port or use already existing port
            foreach (SerialPort pts in robot.ports)
            {
                if (pts.PortName == pt)
                {
                    port = pts;
                }
            }

            if (port == null)
            {
                port = new SerialPort(pt, 38400, Parity.None, 8, StopBits.One);
                robot.ports.Add(port);
                port.ReadTimeout = 2;
                port.Open();
            }

            //send autodetect baud rate
            port.Write(new byte[] { (byte)0xAA }, 0, 1);
        }
コード例 #19
0
        // Constructor
        public StudentCode(Robot robot)
        {
            this.robot = robot;
            smcR = new SimpleMotorController(robot, 13); //let's say 13 is right motor on drivetrain
            smcL = new SimpleMotorController(robot, 14); //let's say 14 is left motor on drivetrain
            //mm = new MicroMaestro(robot, 12);

            switchL = new DigitalSwitch(1);
            switchR = new DigitalSwitch(2);
            rfL = new SharpDistanceTracker(0);
            rfR = new SharpDistanceTracker(1);
            rfR1 = 0;
            rfR2 = 0;
            rfL1 = 0;
            rfL2 = 0;
            timer = 0;
        }
        /// <summary>
        /// Ensure to instantiate the MicroMaestro with the Robot given to the student and the device num (probably 13 or 14)
        /// This will take care of connecting the MicroMaestro to the robot's system
        /// </summary>
        /// <param name="robo"> The robot this Simple is connected to. </param>
        /// <param name="deviceNum"> The device number of this Simple. </param>
        public I2CMotorController(Robot robo, ushort deviceAdd)
        {
            //attach to robot, allowing itself to be updated by the Robot thread when called
            robot = robo;
            robot.actuators.Add(this);
            deviceAddress = deviceAdd;

            //initialize the motor as not turning
            canMove = true;
            motorSpeed = 0;
            motorBrake = 0;
            //create I2C Device object representing both devices on our bus
            conDeviceA = new I2CDevice.Configuration(deviceAddress, 100);

            //create I2C Bus object using one of the devices on the bus
            //I2CA = new I2CDevice(conDeviceA);
        }
コード例 #21
0
ファイル: PolarBear.cs プロジェクト: RohanR/pie-software
        public PolarBear(Robot robo, ushort deviceAdd)
            : base(robo)
        {
            //attach to robot, allowing itself to be updated by the Robot thread when called

            robot.actuators.Add(this);
            deviceAddress = deviceAdd;

            //initialize the motor as not turning
            canMove = true;
            velocity = 0;
            brakeAmount = 0;
            upperStopZone = 0;
            lowerStopZone = 0;
            minVelocity = -255;
            maxVelocity = 255;

            //create I2C Device object representing both devices on our bus
            conDeviceA = new I2CDevice.Configuration(deviceAddress, 100);
        }
        /// <summary>
        /// Ensure to instantiate the MicroMaestro with the Robot given to the student and the device num (probably 13 or 14)
        /// This will take care of connecting the MicroMaestro to the robot's system
        /// </summary>
        /// <param name="robo"> The robot this Simple is connected to. </param>
        /// <param name="deviceNum"> The device number of this Simple. </param>
        public SimpleMotorController(Robot robo, int deviceNum)
        {
            //attach to robot, allowing itself to be updated by the Robot thread when called
            robot = robo;
            robot.actuators.Add(this);
            deviceNumber = deviceNum;
            if (deviceNumber == 14)
            {
                pt = "COM3";
            }

            //initialize the motor as not turning
            canMove = true;
            motorSpeed = 0;
            motorBrake = 0;

            //create new port or use already existing port and send baud rate auto-detect byte (0xAA)
            foreach (SerialPort pts in robot.ports)
            {
                if (pts.PortName == pt)
                {
                    port = pts;
                }
            }
            if (port == null)
            {
                port = new SerialPort(pt, 9600, Parity.None, 8, StopBits.One);
                robot.ports.Add(port);
                port.ReadTimeout = 2;
                port.Open();
            }
            //send autodetect baud rate
            port.Write(new byte[] { (byte)0xAA }, 0, 1);

            //send the command to exit the SMC's safe-mode
            byte[] exitSafe = new byte[3];
            exitSafe[0] = (byte)0xAA;
            exitSafe[1] = (byte)deviceNumber;
            exitSafe[2] = (byte)0x03;
            port.Write(exitSafe, 0, 3);
        }
コード例 #23
0
        public Radio(Robot robo, string portName)
        {
            robot = robo;

            UIAnalogVals = new int[(int)INTERFACEPACKET.ANALOG_BYTES];
            UIDigitalVals = new bool[(int)INTERFACEPACKET.DIGITAL_BYTES];
            FieldAnalogVals = new int[(int)FIELDPACKET.ANALOG_BYTES];
            FieldDigitalVals = new bool[(int)FIELDPACKET.DIGITAL_BYTES];

            state = RadioState.IDLE;
            port = new SerialPort(portName, 9600, Parity.None, 8, StopBits.One);
            port.ReadTimeout = 2;

            port.Open();

            data = new InterfacePacket((byte)INTERFACEPACKET.IDENT, (int)INTERFACEPACKET.ANALOG_BYTES, (int)INTERFACEPACKET.DIGITAL_BYTES);
            telemetry = new TelemetryPacket((byte)TELEMETRYPACKET.IDENT, (int)TELEMETRYPACKET.ANALOG_BYTES, (int)TELEMETRYPACKET.DIGITAL_BYTES);
            buffer = new byte[128];

            telemetryThread = new Thread(new ThreadStart(this.Telemetry));

            receiver = new XBeeReceiver(this);
            frame = 0;
            Debug.Print(" **** Radio constructor ****");
            radioThread = new Thread(new ThreadStart(this.Poll));
            radioThread.Start();
        }
コード例 #24
0
 /// <summary>
 /// Main method which initializes the robot, and starts
 /// it running. Do not modify.
 /// </summary>
 public static void Main()
 {
     // Initialize robot
     Robot robot = new Robot("1", "COM4");
     Debug.Print("Code loaded successfully!");
     Supervisor supervisor = new Supervisor(new StudentCode(robot));
     supervisor.RunCode();
 }
コード例 #25
0
 /// <summary>
 ///   Initializes a new instance of the
 ///   <see cref="StudentPiER.StudentCode"/> class.
 /// </summary>
 /// <param name='robot'>
 ///   The Robot to associate with this StudentCode
 /// </param>
 public StudentCode(Robot robot)
 {
     Debug.Print("hello");
     this.robot = robot;
     this.stopwatch = new Stopwatch();
     this.stopwatch.Start();
     this.useRfid = true;
     if (this.useRfid)
     {
         this.rfid = new Rfid(robot);
     }
     this.leftMotor = new GrizzlyBear(robot, Watson.Motor.M0);
     this.rightMotor = new GrizzlyBear(robot, Watson.Motor.M1);
     this.gearbox = new GrizzlyBear(robot, Watson.Motor.M2, 0, 100, true);
     this.sonar = new AnalogSonarDistanceSensor(robot, Watson.Analog.A5);
     this.doorController = new MicroMaestro(robot, 12);
     this.motorDoor = new ServoMotor(robot, doorController,0,2400,9600);
     this.leftEncoder = new GrizzlyEncoder(10, leftMotor, robot);
     this.rightEncoder = new GrizzlyEncoder(10, rightMotor, robot);
 }
コード例 #26
0
ファイル: StudentCode.cs プロジェクト: RohanR/pie-software
 // Constructor
 public StudentCode(Robot robot)
 {
     this.robot = robot;
     i2cR = new PolarBear(robot, 0x0C); //0x0A is the right motor on drivetrain by default
     i2cL = new PolarBear(robot, 0x0E); //0x0B is the left motor on drivetrain by default
 }
        public Radio_Series1(Robot robo, string portName)
        {
            robot = robo;
            UIAnalogVals = new int[(int)INTERFACEPACKET.ANALOG_BYTES];
            UIDigitalVals = new bool[(int)INTERFACEPACKET.DIGITAL_BYTES * 8];

            state = RadioState.IDLE;
            port = new SerialPort(portName, 9600, Parity.None, 8, StopBits.One);
            port.ReadTimeout = 2;
            port.Open();

            data = new InterfacePacket((byte)INTERFACEPACKET.IDENT, (int)INTERFACEPACKET.ANALOG_BYTES, (int)INTERFACEPACKET.DIGITAL_BYTES);
            telemetry = new TelemetryPacket((byte)TELEMETRYPACKET.IDENT, (int)TELEMETRYPACKET.ANALOG_BYTES, (int)TELEMETRYPACKET.DIGITAL_BYTES);
            buffer = new byte[512];
            receiver = new XBeeInterfaceReceiver(this);

            frame = 0;
        }
コード例 #28
0
        /// <summary>
        /// Main method which initializes the robot, and creates
        /// the radio's and student code's threads. Begins running
        /// the threads, and then runs the robot thread indefinitely.
        /// </summary>       
        public static void Main()
        {
            /*AnalogIn GyroX = new AnalogIn(AnalogIn.Pin.Ain0);
            AnalogIn GyroZ = new AnalogIn(AnalogIn.Pin.Ain1);
            AnalogIn AccelerometerX = new AnalogIn(AnalogIn.Pin.Ain2);
            AnalogIn AccelerometerY = new AnalogIn(AnalogIn.Pin.Ain3);
            AnalogIn AccelerometerZ = new AnalogIn(AnalogIn.Pin.Ain4);
            while (true)
            {
                Thread.Sleep(250);
                Debug.Print("GyroX: " + GyroX.Read());
                Debug.Print("GyroZ: " + GyroZ.Read());
                Debug.Print("AccelerometerX: " + AccelerometerX.Read());
                Debug.Print("AccelerometerY: " + AccelerometerY.Read());
                Debug.Print("AccelerometerZ: " + AccelerometerZ.Read());
            }*/

            // Initialize robot
            Robot robot = new Robot("1", "COM4");//com 4 orig. com 3 bec    ause of problem on top board.
            robot.Auton(false);
            robot.student = new StudentCode(robot);

            // Create and set radio threads
            robot.rfPollThread = new Thread(robot.RunRFPoll);
            robot.rfPollThread.Priority = ThreadPriority.AboveNormal;
            robot.rfTeleThread = new Thread(robot.RunRFTele);
            robot.rfTeleThread.Priority = ThreadPriority.AboveNormal;

            // Create and set student code threads
            robot.studentCodeThread = new Thread(robot.RunStudent);
            robot.studentCodeThread.Priority = ThreadPriority.AboveNormal;
            robot.autonomousThread = new Thread(robot.RunAutono);
            robot.autonomousThread.Priority = ThreadPriority.BelowNormal;

            // Initialize LEDs
            robot.yellowLED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.IO59, false);
            robot.redLED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.IO60, false);

            // Disable
            Debug.EnableGCMessages(false);

            // Run the robot once to initialize
            robot.Run();

            // Set robot thread priority to AboveNormal
            Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;

            // Start running all the threads
            robot.rfPollThread.Start();
            robot.rfTeleThread.Start();
            robot.studentCodeThread.Start();
            robot.autonomousThread.Start();

            // Run robot supervisor code
            while (true)
            {
                robot.Run();
                Thread.Sleep(ROBOT_SLEEP_TIME);
            }
        }
コード例 #29
0
 /// <summary>
 /// Initialize a quadrature encoder on the given channel
 /// in the given resolution mode.
 /// 
 /// In double-resolution mode, both rising and falling edges on pin A
 /// are counted.
 /// In single-resolution mode, only rising edges on pin A are counted.
 /// </summary>
 /// <param name="channel">encoder channel (0-3)</param>
 /// <param name="doubleResolution">true for double resolution, 
 ///     false for single resolution</param>
 public Encoder(Robot robot, byte channel, bool doubleResolution)
     : this(robot, channel)
 {
     // Set resolution mode (defaults to double resolution)
     if (!doubleResolution)
     {
         outBuf[2] = (byte)((CMD_SET_SINGLE_RESOLUTION << 2) |
             (channel & 0x3));
         serial.Write(outBuf, 0, outBuf.Length);
     }
 }
コード例 #30
0
        /// <summary>
        /// Main method which initializes the robot, and creates
        /// the radio's and student code's threads. Begins running
        /// the threads, and then runs the robot thread indefinitely.
        /// </summary>       
        public static void Main()
        {
            // Initialize robot
            Robot robot = new Robot("1", "COM4");
            robot.Auton(false);
            robot.student = new StudentCode(robot);

            // Create and set radio threads
            robot.rfPollThread = new Thread(robot.RunRFPoll);
            robot.rfPollThread.Priority = ThreadPriority.AboveNormal;
            robot.rfTeleThread = new Thread(robot.RunRFTele);
            robot.rfTeleThread.Priority = ThreadPriority.AboveNormal;

            // Create and set student code threads
            robot.studentCodeThread = new Thread(robot.RunStudent);
            robot.studentCodeThread.Priority = ThreadPriority.BelowNormal;
            robot.autonomousThread = new Thread(robot.RunAutono);
            robot.autonomousThread.Priority = ThreadPriority.BelowNormal;

            // Initialize LEDs
            robot.yellowLED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.IO59, false);
            robot.redLED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.IO60, false);

            // Disable
            Debug.EnableGCMessages(false);

            // Run the robot once to initialize
            robot.Run();

            // Set robot thread priority to AboveNormal
            Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;

            // Start running all the threads
            robot.studentCodeThread.Start();
            robot.autonomousThread.Start();
            robot.rfPollThread.Start();
            robot.rfTeleThread.Start();

            // Run robot supervisor code
            while (true)
            {
                robot.Run();
                Thread.Sleep(ROBOT_SLEEP_TIME);
            }
        }