Hi again. Our team is doing a lot of new things this year, and an inertial sensor is one of them. I am our programmer and I have no clue what I’m doing when it comes to inertial sensing. Can anybody help me out? I am using VexCode V5 pro btw.
What application do you want to use the inertial sensor for? One common application is PID turns using the inertial sensor during auton.
I am using Vexcode v5 pro.
I meant like what do you want to use the inertial sensor for
If you are using the inertial sensor for navigation, you can use the built in Drivetrain
function with an example below. Similar code can be found in the VEXcode Pro V5 Examples.
For more complex navigation systems you will want to search on PID and Odometry.
motor leftMotorA = motor(PORT1, ratio18_1, false);
motor leftMotorB = motor(PORT10, ratio18_1, false);
motor_group leftDriveGroup = motor_group(leftMotorA, leftMotorB);
motor rightMotorA = motor(PORT11, ratio18_1, true);
motor rightMotorB = motor(PORT20, ratio18_1, true);
motor_group rightDriveGroup = motor_group(rightMotorA, rightMotorB);
distanceUnits units = distanceUnits::in; //Imperial measurements - inches.
double wheelTravel = 4 * M_PI; //Circumference of the drive wheels (4" x PI)
double trackWidth = 18; //Distance between the left and right center of wheel.
double wheelBase = 15; //Distince between the center of the front and back axle.
double gearRatio = 1; //Ratio of motor rotations to wheel rotations if using gears.
inertial drivetrainInertial = inertial(PORT21);
smartdrive Drivetrain= smartdrive(leftDriveGroup, rightDriveGroup, drivetrainInertial, wheelTravel, trackWidth, wheelBase, units, gearRatio);
void vexcodeInit( void ) {
drivetrainInertial.calibrate();
Brain.Screen.print("Calibrating Gyro for Drivetrain");
while (drivetrainInertial.isCalibrating()) {
wait(25, msec);
}
wait(50, msec);
Brain.Screen.clearScreen();
}
void autonomous(void) {
Drivetrain.driveFor(forward, 10, inches);
Drivetrain.turnToHeading(45, degrees);
}
We are using it for direction during autonomous. We are using x-drive this year and are unsure how to code the autonomous to turn without them.
Thank you, but unless this works with x-drive its slightly pointless.
I’m not too sure as to what kind of help you want, but a good place to start might be here: https://kb.vex.com/hc/en-us/articles/360037382272-Using-the-V5-Inertial-Sensor. After reading this article, to use the inertial sensor, this page should be helpful since you are using VexCode: VEX V5 C++ API: vex::inertial Class Reference. You can use the heading() method or the rotation() method to get the angle of the robot, as long as the inertial sensor is mounted correctly. Note that the heading() method will wrap around 360 degrees, meaning that the angle is not accumulative and will reset after a full rotation. The rotation() method is generally more useful, but nice to know.
Personally, I am not too familiar with VexCode, so I am not sure if they have any examples for X-drive code, but the math should be
frontLeft = forward + strafe + turn
frontRight = forward - strafe - turn
backLeft = forward - strafe + turn
backRight = forward + strafe - turn
There are some problems with this, but for basic applications, it should be good enough. If you want to learn about the more advanced version, this video explains it very well: How to Use Mecanum Wheels in 200 Seconds - YouTube. It is a video about mecanum drives, but they work on the same principle, so it should be applicable to both.
Without knowing you are using an x-drive, how is one to know what is useful.
Here’s an example for implementing Field Centric holonomic drive in VexCode which includes the use of an Inertial sensor:
Thank you. I understand that without prior knowledge, it may be difficult to help.