Where can I find sample code for the new V5 internal sensor?
Itās an āinertialā sensor (not internal)
Thereās a example with VEXcode, but the simplest use is to replace a gyro, in which case you would use Inertial.heading( degrees ); or Inertial.rotation( degrees ); to get the amount of rotation around the Z axis.
Iāll post something more complicated next week.
Hereās something a little more comprehensive that would print more information
imu example
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: james */
/* Created: Fri Nov 01 2019 */
/* Description: V5 project */
/* */
/*----------------------------------------------------------------------------*/
#include "vex.h"
using namespace vex;
/*----------------------------------------------------------------------------*/
// This would need moving to robot-config.cpp if using graphical configuration
//
// A global instance of vex::brain used for printing to the V5 brain screen
vex::brain Brain;
// define your global instances of motors and other devices here
vex::inertial Inertial( vex::PORT2 );
vex::limit sw1( Brain.ThreeWirePort.A );
/*----------------------------------------------------------------------------*/
void InertialStartCal() {
Inertial.calibrate();
}
int main() {
inertial::quaternion Inertial_quaternion;
sw1.pressed(InertialStartCal);
while(1) {
// get the quaternion data
Inertial_quaternion = Inertial.orientation();
Brain.Screen.clearScreen();
Brain.Screen.setFont( mono15 );
Brain.Screen.setPenColor( white );
Brain.Screen.setFillColor( black );
Brain.Screen.printAt( 20, 30, "GX %8.3f", Inertial.gyroRate( xaxis, dps ) );
Brain.Screen.printAt( 20, 45, "GY %8.3f", Inertial.gyroRate( yaxis, dps ) );
Brain.Screen.printAt( 20, 60, "GZ %8.3f", Inertial.gyroRate( zaxis, dps ) );
Brain.Screen.printAt( 20, 90, "AX %8.3f", Inertial.acceleration( xaxis ) );
Brain.Screen.printAt( 20, 105, "AY %8.3f", Inertial.acceleration( yaxis ) );
Brain.Screen.printAt( 20, 120, "AZ %8.3f", Inertial.acceleration( zaxis ) );
Brain.Screen.printAt( 20, 150, "A %8.3f", Inertial_quaternion.a );
Brain.Screen.printAt( 20, 165, "B %8.3f", Inertial_quaternion.b );
Brain.Screen.printAt( 20, 180, "C %8.3f", Inertial_quaternion.c );
Brain.Screen.printAt( 20, 195, "D %8.3f", Inertial_quaternion.d );
Brain.Screen.printAt( 150, 30, "Roll %7.2f", Inertial.roll() );
Brain.Screen.printAt( 150, 45, "Pitch %7.2f", Inertial.pitch() );
Brain.Screen.printAt( 150, 60, "Yaw %7.2f", Inertial.yaw() );
Brain.Screen.printAt( 150, 90, "Heading %7.2f", Inertial.heading() );
Brain.Screen.printAt( 150,105, "Rotation %7.2f", Inertial.rotation() );
if( Inertial.isCalibrating() )
Brain.Screen.printAt( 20,225, "Calibration In Progress" );
else
Brain.Screen.printAt( 20,225, "Calibration Done" );
Brain.Screen.render();
// Allow other tasks to run
this_thread::sleep_for(10);
}
}
Question: my team wanted to incorporate the intertial sensor this weekend but when looking at the drivetrains in version 1.0.1 only got an option for a 3-wire gyro. They were at a tournament and didnāt want to update the code to the latest version at the time. In the latest version, 1.0.2, are there options for the new inertial sensor?
Would love to see more details before the holiday break so students that want to master this during the break have something to work with. As always, your assistance and input is much appreciated!
https://api.vexcode.cloud/v5/html/classvex_1_1inertial.html
The āadvanced APIā has some more details on the command available.
I just found some code in the Examples in the latest VexCode update.
āinertialā sensor makes more sense than what I typed.
Question about the api. What are acceptable VelocityUnits (for example, other units are degrees, seconds, etc) - what can be used for velocityUnits ? And, besides asking here, how can I figure out other units and what can be used in the future.
https://api.vexcode.cloud/v5/html/namespacevex.html#a7a28a59c1cc0bc88387a6316c4b59847
pct, percent
rpm, rounder per minute
dps, degrees per second
This is the example code given.
#include āvex.hā
using namespace vex;
int main() {
vexcodeInit();
Inertial20.calibrate();while (Inertial20.isCalibrating()) {
wait(100, msec);
}LeftMotor.spin(forward);
RightMotor.spin(reverse);waitUntil((Inertial20.rotation(degrees) >= 90.0));
LeftMotor.stop();
RightMotor.stop();
wait(1, seconds);
}
I loaded the example Accurate Turns(Inertial Sensor) with VexCode 1.0.3 19.121916 into a B1(VEXos 1ā¦0.7) and get thevJump Table Error 03800EE8. I tried a second B1 and second sensor and got the same Error. I tried the sensor code lines in another program and got another Jump Code Error 038019F8.
I must be missing something simple.
vexos 1.0.7 is not compatible with the Inertial sensor, update to 1.0.9, VEXcode should have prompted you to do that, click on the green brain icon when the V5 is connected via USB.
Thank you. It works. I appreciate your quick response, especially on a holiday.
when I copy and past the config code ( vex::inertial Inertial( vex::PORT2 ); ) it gives me the error:
[clang] No type named āinertialā in namespace āvexā
Iām running the most updated version of vexcode, what can I do to fix this?
Which version is that ? you need the 1.0.3 version released in December.
1.0.3 is working for me on PC but not on Mac
you could check the sdk version, but inertial sensor is working on both Mac and PC in 1.0.3
Anything unusual about the installation ? perhaps reinstall, I donāt know.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.