Gyro in Motor and Sensor Setup

  1. 4 months ago

    Hello,

    As I understand it, in order to program the VEX gyro sensor in RobotC, you first need to clear out previous sensor readings and then assign the port (which kicks off calibration) using the lines of code below:

     //Completely clear out any previous sensor readings by setting the port to "sensorNone"
     SensorType[in8] = sensorNone;
     wait1Msec(1000);
     //Reconfigure Analog Port 8 as a Gyro sensor and allow time for ROBOTC to calibrate it
     SensorType[in8] = sensorGyro;
     wait1Msec(2000);

    If I set up the gyro in the Motor and Sensor Setup tool (name it and assign the port) instead of using the lines of code above, would it still clear readings and/or calibrate as soon as the code is run on the robot? Or would you still need to include these lines of code?

    Thanks!

    The gyroscope needs to be turned on and calibrated. That doesn't just happen because you inform the system there will be a gyroscope. Simplifying things, the #pragma statements just communicate where things are, what they're named, etc. so that code from the program can be properly understood by the Cortex. At some point you actually have to tell the Cortex when you want it to get the gyroscope started.

  2. callen

    Jun 11 Answer Braintree, MA, USA

    The gyroscope needs to be turned on and calibrated. That doesn't just happen because you inform the system there will be a gyroscope. Simplifying things, the #pragma statements just communicate where things are, what they're named, etc. so that code from the program can be properly understood by the Cortex. At some point you actually have to tell the Cortex when you want it to get the gyroscope started.

  3. That makes sense. Thanks. As a follow up, if I set up the gyro in Motor and Sensor Setup and name it, would I be able to refer to it by that name when turning on and calibrating, as opposed to the port number (in8)? For example, if I named it gyroSensor...

    //Completely clear out any previous sensor readings by setting the port to "sensorNone" SensorType[gyroSensor] = sensorNone; wait1Msec(1000); //Reconfigure Analog Port 8 as a Gyro sensor and allow time for ROBOTC to calibrate it SensorType[gyroSensor] = sensorGyro; wait1Msec(2000);

  4. DarkMatterMatt

    Jun 12 Auckland, New Zealand 2900C

    Have you tried it? Yes you can :)

    Also, the Vex gyro can initialize correctly in about 1250ms after removing it for 250ms (haven't tried clearing it for a shorter time). This means you can halve the start-up time. Someone on the forum (forgot who) experimented to determine that 1118ms is the minimum time to correctly initialize the gyro.

    As always, Renegade Robotics has an awesome article on the sensor (https://renegaderobotics.org/getting-started-with-the-vex-gyro-sensor/ )

  5. Thanks for the help! I did test it, and while I got no errors, I wanted to make sure that this method is both straightforward and complies with best practices. I'm trying to find the best way to teach VEX EDR sensor code to a group of young kids.

 

or Sign Up to reply!