本文整理汇总了C++中AHRS类的典型用法代码示例。如果您正苦于以下问题:C++ AHRS类的具体用法?C++ AHRS怎么用?C++ AHRS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AHRS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
AHRS w;
w.show();
return a.exec();
}
示例2: main
int main(int argc, char *argv[])
{
//-------------------- IMU setup and main loop ----------------------------
imuSetup();
ros::init(argc, argv, "ros_erle_imu_euler");
ros::NodeHandle n;
ros::Publisher imu_euler_pub = n.advertise<ros_erle_imu_euler::euler>("euler", 1000);
ros::Rate loop_rate(50);
while (ros::ok()){
//----------------------- Calculate delta time ----------------------------
gettimeofday(&tv,NULL);
previoustime = currenttime;
currenttime = 1000000 * tv.tv_sec + tv.tv_usec;
dt = (currenttime - previoustime) / 1000000.0;
if(dt < 1/1300.0)
usleep((1/1300.0-dt)*1000000);
gettimeofday(&tv,NULL);
currenttime = 1000000 * tv.tv_sec + tv.tv_usec;
dt = (currenttime - previoustime) / 1000000.0;
//-------- Read raw measurements from the MPU and update AHRS --------------
// Accel + gyro.
imu.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz);
ahrs.updateIMU(ax, ay, az, gx*0.0175, gy*0.0175, gz*0.0175, dt);
//------------------------ Read Euler angles ------------------------------
ahrs.getEuler(&roll, &pitch, &yaw);
ros_erle_imu_euler::euler msg;
msg.roll = roll;
msg.pitch = pitch;
msg.yaw = yaw;
imu_euler_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
示例3: main
int main(int argc, char *argv[])
{
if (argc == 3) {
try {
AHRS *imu = new AHRS(std::string(argv[1]),getBaudrate(argv[2]));
char *buffer = NULL;
size_t bufsize;
// Connect to the AHRS.
imu->openDevice();
printf("Connected to %s.\n", (imu->getInfo()).c_str());
// Prompt the user for a new baudrate.
printf("New speed? (baud) \n");
if (getline(&buffer, &bufsize, stdin) == -1)
{
fprintf(stderr, "Unable to read in new baudrate.\n");
imu->closeDevice();
return -1;
}
// Attempt to read in a baudrate and change to it.
imu->setBaudrate(getBaudrate(buffer));
// Clean up and close resources.
free(buffer);
imu->closeDevice();
// Tell the user of the result.
fprintf(stderr, "Changed speed successfully.\n");
exit(0);
} catch (std::exception& e) {
printError(e);
}
}
printUsage();
}
示例4: RobotInit
void RobotInit() override {
lw = LiveWindow::GetInstance();
drive->SetExpiration(20000);
drive->SetSafetyEnabled(false);
//Gyroscope stuff
try {
/* Communicate w/navX-MXP via the MXP SPI Bus. */
/* Alternatively: I2C::Port::kMXP, SerialPort::Port::kMXP or SerialPort::Port::kUSB */
/* See http://navx-mxp.kauailabs.com/guidance/selecting-an-interface/ for details. */
ahrs = new AHRS(SPI::Port::kMXP);
} catch (std::exception ex) {
std::string err_string = "Error instantiating navX-MXP: ";
err_string += ex.what();
//DriverStation::ReportError(err_string.c_str());
}
if (ahrs) {
LiveWindow::GetInstance()->AddSensor("IMU", "Gyro", ahrs);
ahrs->ZeroYaw();
// Kp Ki Kd Kf PIDSource PIDoutput
turnController = new PIDController(0.015f, 0.003f, 0.100f, 0.00f,
ahrs, this);
turnController->SetInputRange(-180.0f, 180.0f);
turnController->SetOutputRange(-1.0, 1.0);
turnController->SetAbsoluteTolerance(2); //tolerance in degrees
turnController->SetContinuous(true);
}
chooser.AddDefault("No Auto", new int(0));
chooser.AddObject("GyroTest Auto", new int(1));
chooser.AddObject("Spy Auto", new int(2));
chooser.AddObject("Low Bar Auto", new int(3));
chooser.AddObject("Straight Spy Auto", new int(4));
chooser.AddObject("Adjustable Straight Auto", new int(5));
SmartDashboard::PutNumber(AUTO_LENGTH, AUTO_LENGTH_DEFAULT);
SmartDashboard::PutNumber(AUTO_SPEED, AUTO_SPEED_DEFAULT);
SmartDashboard::PutNumber(AUTO_INTAKE_SPEED, AUTO_INTAKE_SPEED_DEFAULT);
SmartDashboard::PutData("Auto Modes", &chooser);
liftdown->Set(false);
comp->Start();
}
示例5: imuLoop
void imuLoop()
{
//----------------------- Calculate delta time ----------------------------
gettimeofday(&tv,NULL);
previoustime = currenttime;
currenttime = 1000000 * tv.tv_sec + tv.tv_usec;
dt = (currenttime - previoustime) / 1000000.0;
if(dt < 1/1300.0) usleep((1/1300.0-dt)*1000000);
gettimeofday(&tv,NULL);
currenttime = 1000000 * tv.tv_sec + tv.tv_usec;
dt = (currenttime - previoustime) / 1000000.0;
//-------- Read raw measurements from the MPU and update AHRS --------------
// Accel + gyro.
/*
imu->update();
imu->read_accelerometer(&ax, &ay, &az);
imu->read_gyroscope(&gx, &gy, &gz);
ax /= G_SI;
ay /= G_SI;
az /= G_SI;
gx *= 180 / PI;
gy *= 180 / PI;
gz *= 180 / PI;
ahrs.updateIMU(ax, ay, az, gx*0.0175, gy*0.0175, gz*0.0175, dt);
*/
// Accel + gyro + mag.
// Soft and hard iron calibration required for proper function.
imu->update();
imu->read_accelerometer(&ay, &ax, &az);
imu->read_gyroscope(&gy, &gx, &gz);
imu->read_magnetometer(&my, &mx, &mz);
ax /= -G_SI;
ay /= -G_SI;
az /= G_SI;
gx *= 180 / PI;
gy *= 180 / PI;
gz *= -180 / PI;
ahrs.update(ax, ay, az, gx*0.0175, gy*0.0175, gz*0.0175, my, mx, -mz, dt);
//------------------------ Read Euler angles ------------------------------
//ahrs.getEuler(&pitch, &roll, &yaw);//roll and pitch inverted
ahrs.getEuler(&roll, &pitch, &yaw);
//------------------- Discard the time of the first cycle -----------------
if (!isFirst)
{
if (dt > maxdt) maxdt = dt;
if (dt < mindt) mindt = dt;
}
isFirst = 0;
}
示例6: imuLoop
void imuLoop()
{
float dtsum = 0.0f; //sum of delta t's
while(dtsum < 1.0f/freq) //run this loop at 1300 Hz (Max frequency gives best results for Mahony filter)
{
//----------------------- Calculate delta time ----------------------------
gettimeofday(&tv,NULL);
previoustime = currenttime;
currenttime = 1000000 * tv.tv_sec + tv.tv_usec;
dt = (currenttime - previoustime) / 1000000.0;
if(dt < 1/1300.0) usleep((1/1300.0-dt)*1000000);
gettimeofday(&tv,NULL);
currenttime = 1000000 * tv.tv_sec + tv.tv_usec;
dt = (currenttime - previoustime) / 1000000.0;
//-------- Read raw measurements from the MPU and update AHRS --------------
// Accel + gyro.
imu->update();
imu->read_accelerometer(&ax, &ay, &az);
imu->read_gyroscope(&gx, &gy, &gz);
ax /= G_SI;
ay /= G_SI;
az /= G_SI;
gx *= 180 / PI;
gy *= 180 / PI;
gz *= 180 / PI;
ahrs.updateIMU(ax, ay, az, gx*0.0175, gy*0.0175, gz*0.0175, dt);
// Accel + gyro + mag.
// Soft and hard iron calibration required for proper function.
/*
imu->update();
imu->read_accelerometer(&ay, &ax, &az);
az *= -1;
imu->read_gyroscope(&gy, &gx, &gz);
gz *= -1;
imu->read_magnetometer(&mx, &my, &mz);
ax /= G_SI;
ay /= G_SI;
az /= G_SI;
gx *= 180 / PI;
gy *= 180 / PI;
gz *= 180 / PI;
ahrs.update(-ax, -ay, -az, gx*0.0175, gy*0.0175, gz*0.0175, mx, my, mz, dt);
*/
//------------------------ Read Euler angles ------------------------------
ahrs.getEuler(&pitch, &roll, &yaw);
//------------------- Discard the time of the first cycle -----------------
if (!isFirst)
{
if (dt > maxdt) maxdt = dt;
if (dt < mindt) mindt = dt;
}
isFirst = 0;
dtsum += dt;
}
}
示例7: SetAHRSPosData
void SetAHRSPosData(AHRSProtocol::AHRSPosUpdate& ahrs_update) {
/* Update base IMU class variables */
ahrs->yaw = ahrs_update.yaw;
ahrs->pitch = ahrs_update.pitch;
ahrs->roll = ahrs_update.roll;
ahrs->compass_heading = ahrs_update.compass_heading;
ahrs->yaw_offset_tracker->UpdateHistory(ahrs_update.yaw);
/* Update AHRS class variables */
// 9-axis data
ahrs->fused_heading = ahrs_update.fused_heading;
// Gravity-corrected linear acceleration (world-frame)
ahrs->world_linear_accel_x = ahrs_update.linear_accel_x;
ahrs->world_linear_accel_y = ahrs_update.linear_accel_y;
ahrs->world_linear_accel_z = ahrs_update.linear_accel_z;
// Gyro/Accelerometer Die Temperature
ahrs->mpu_temp_c = ahrs_update.mpu_temp;
// Barometric Pressure/Altitude
ahrs->altitude = ahrs_update.altitude;
ahrs->baro_pressure = ahrs_update.barometric_pressure;
// Status/Motion Detection
ahrs->is_moving =
(((ahrs_update.sensor_status &
NAVX_SENSOR_STATUS_MOVING) != 0)
? true : false);
ahrs->is_rotating =
(((ahrs_update.sensor_status &
NAVX_SENSOR_STATUS_YAW_STABLE) != 0)
? false : true);
ahrs->altitude_valid =
(((ahrs_update.sensor_status &
NAVX_SENSOR_STATUS_ALTITUDE_VALID) != 0)
? true : false);
ahrs->is_magnetometer_calibrated =
(((ahrs_update.cal_status &
NAVX_CAL_STATUS_MAG_CAL_COMPLETE) != 0)
? true : false);
ahrs->magnetic_disturbance =
(((ahrs_update.sensor_status &
NAVX_SENSOR_STATUS_MAG_DISTURBANCE) != 0)
? true : false);
ahrs->quaternionW = ahrs_update.quat_w;
ahrs->quaternionX = ahrs_update.quat_x;
ahrs->quaternionY = ahrs_update.quat_y;
ahrs->quaternionZ = ahrs_update.quat_z;
ahrs->velocity[0] = ahrs_update.vel_x;
ahrs->velocity[1] = ahrs_update.vel_y;
ahrs->velocity[2] = ahrs_update.vel_z;
ahrs->displacement[0] = ahrs_update.disp_x;
ahrs->displacement[1] = ahrs_update.disp_y;
ahrs->displacement[2] = ahrs_update.disp_z;
ahrs->yaw_angle_tracker->NextAngle(ahrs->GetYaw());
}
示例8: imuLoop
void imuLoop ( void ) {
//Calculate delta time
gettimeofday( &tv , NULL );
previoustime = currenttime;
currenttime = 1000000 * tv.tv_sec + tv.tv_usec;
dt = ( currenttime - previoustime ) / 1000000.0;
if( dt < 1/1300.0 ) usleep( ( 1/1300.0 - dt ) * 1000000);
gettimeofday( &tv , NULL) ;
currenttime = 1000000 * tv.tv_sec + tv.tv_usec;
dt = ( currenttime - previoustime ) / 1000000.0;
//Read raw measurements from the MPU and update AHRS
// Accel + gyro + mag.
// Soft and hard iron calibration required for proper function.
imu -> update();
imu -> read_accelerometer( &ay , &ax , &az );
imu -> read_gyroscope( &gy , &gx , &gz );
imu -> read_magnetometer( &mx , &my , &mz );
ax /= G_SI;
ay /= G_SI;
az /= G_SI;
my = - my;
ahrs.update( ax , ay , az , gx , gy , gz , mx , my , mz , dt );
//Read Euler angles
ahrs.getEuler( &pitch , &roll , &yaw );
//Discard the time of the first cycle
if ( !isFirst ) {
if ( dt > maxdt ) maxdt = dt;
if ( dt < mindt ) mindt = dt;
}
isFirst = 0;
//Console and network output with a lowered rate
dtsumm += dt;
if( dtsumm > 0.05 ) {
//Console output
//printf("ROLL: %+05.2f PITCH: %+05.2f YAW: %+05.2f PERIOD %.4fs RATE %dHz \n", roll, pitch, gz/*yaw * -1*/, dt, int(1/dt));
// Network output
//sprintf( sendline , "%10f %10f %10f %10f %dHz\n" ,ahrs.getW() ,ahrs.getX() ,ahrs.getY() ,ahrs.getZ() ,int( 1/dt ) );
//sendto( sockfd , sendline , strlen( sendline ) , 0 , ( struct sockaddr * )&servaddr , sizeof( servaddr ) );
dtsumm = 0;
}
}
示例9: UpdateDashboard
void UpdateDashboard() {
float r = 0.00001 * i;
SmartDashboard::PutNumber("State", currentState + r);
SmartDashboard::PutNumber("PID Turn Error",
turnController->GetError() + r);
SmartDashboard::PutNumber("PID Target",
turnController->GetSetpoint() + r);
// SmartDashboard::PutBoolean("Straight", straight);
SmartDashboard::PutData("test", turnController);
SmartDashboard::PutNumber("Yaw:", ahrs->GetYaw() + r);
SmartDashboard::PutNumber("Roll:", ahrs->GetRoll() + r);
SmartDashboard::PutNumber("Pitch", ahrs->GetPitch() + r);
SmartDashboard::PutNumber("Scissor 1", pdp->GetCurrent(1) + r);
SmartDashboard::PutNumber("Scissor 2", pdp->GetCurrent(2) + r);
SmartDashboard::PutNumber("Left Drive 1", pdp->GetCurrent(12) + r);
SmartDashboard::PutNumber("Left Drive 2", pdp->GetCurrent(13) + r);
SmartDashboard::PutNumber("Right Drive 1", pdp->GetCurrent(14) + r);
SmartDashboard::PutNumber("Right Drive 2", pdp->GetCurrent(15) + r);
SmartDashboard::PutNumber("Constant Lift", constantLift);
SmartDashboard::PutNumber("Rotate Rate", rotateRate + r);
i = (i + 1) % 2;
printf("2.1");
// .PutLong("test1.2", 1337);
printf("2.2");
// mqServer.PutDouble("test",DriverStation::GetInstance().GetMatchTime());
printf("2.3");
// mqServer.PutString("test1.1","YOLO_SWAGINS");
printf("2.4");
// SmartDashboard::PutString("test1.2", mqServer.GetString("test1.1"));
// SmartDashboard::PutNumber("test1", mqServer.GetDouble("test"));
// SmartDashboard::PutNumber("test1.3", mqServer.GetLong("test1.2"));
// SmartDashboard::PutNumber("test2", DriverStation::GetInstance().GetMatchTime());
}
示例10: OperatorControl
/**
* Runs the motors with Mecanum drive.
*/
void OperatorControl()
{
robotDrive.SetSafetyEnabled(false);
while (IsOperatorControl() && IsEnabled())
{
bool collisionDetected = false;
double curr_world_linear_accel_x = ahrs->GetWorldLinearAccelX();
double currentJerkX = curr_world_linear_accel_x - last_world_linear_accel_x;
last_world_linear_accel_x = curr_world_linear_accel_x;
double curr_world_linear_accel_y = ahrs->GetWorldLinearAccelY();
double currentJerkY = curr_world_linear_accel_y - last_world_linear_accel_y;
last_world_linear_accel_y = curr_world_linear_accel_y;
if ( ( fabs(currentJerkX) > COLLISION_THRESHOLD_DELTA_G ) ||
( fabs(currentJerkY) > COLLISION_THRESHOLD_DELTA_G) ) {
collisionDetected = true;
}
SmartDashboard::PutBoolean( "CollisionDetected", collisionDetected);
try {
/* Use the joystick X axis for lateral movement, */
/* Y axis for forward movement, and Z axis for rotation. */
/* Use navX MXP yaw angle to define Field-centric transform */
robotDrive.MecanumDrive_Cartesian(stick.GetX(), stick.GetY(),
stick.GetZ(),ahrs->GetAngle());
} catch (std::exception ex ) {
std::string err_string = "Error communicating with Drive System: ";
err_string += ex.what();
DriverStation::ReportError(err_string.c_str());
}
Wait(0.005); // wait 5ms to avoid hogging CPU cycles
}
}
示例11: AutonomousInit
// Start auto mode
void AutonomousInit() override {
autoSelected = *((int*) chooser.GetSelected()); // autonomous mode chosen in dashboard
currentState = 1;
ahrs->ZeroYaw();
ahrs->GetFusedHeading();
autoLength = SmartDashboard::GetNumber(AUTO_LENGTH, AUTO_LENGTH_DEFAULT);
autoSpeed = SmartDashboard::GetNumber(AUTO_SPEED, AUTO_SPEED_DEFAULT);
autoIntakeSpeed = SmartDashboard::GetNumber(AUTO_INTAKE_SPEED, AUTO_INTAKE_SPEED_DEFAULT);
liftdown->Set(false);
}
示例12: OperatorControl
/**
* Drive based upon joystick inputs, and automatically control
* motors if the robot begins tipping.
*/
void OperatorControl()
{
robotDrive.SetSafetyEnabled(false);
while (IsOperatorControl() && IsEnabled()) {
double xAxisRate = stick.GetX();
double yAxisRate = stick.GetY();
double pitchAngleDegrees = ahrs->GetPitch();
double rollAngleDegrees = ahrs->GetRoll();
if ( !autoBalanceXMode &&
(fabs(pitchAngleDegrees) >=
fabs(kOffBalanceThresholdDegrees))) {
autoBalanceXMode = true;
}
else if ( autoBalanceXMode &&
(fabs(pitchAngleDegrees) <=
fabs(kOnBalanceThresholdDegrees))) {
autoBalanceXMode = false;
}
if ( !autoBalanceYMode &&
(fabs(pitchAngleDegrees) >=
fabs(kOffBalanceThresholdDegrees))) {
autoBalanceYMode = true;
}
else if ( autoBalanceYMode &&
(fabs(pitchAngleDegrees) <=
fabs(kOnBalanceThresholdDegrees))) {
autoBalanceYMode = false;
}
// Control drive system automatically,
// driving in reverse direction of pitch/roll angle,
// with a magnitude based upon the angle
if ( autoBalanceXMode ) {
double pitchAngleRadians = pitchAngleDegrees * (M_PI / 180.0);
xAxisRate = sin(pitchAngleRadians) * -1;
}
if ( autoBalanceYMode ) {
double rollAngleRadians = rollAngleDegrees * (M_PI / 180.0);
yAxisRate = sin(rollAngleRadians) * -1;
}
try {
// Use the joystick X axis for lateral movement, Y axis for forward movement, and Z axis for rotation.
robotDrive.MecanumDrive_Cartesian(xAxisRate, yAxisRate,stick.GetZ());
} catch (std::exception ex ) {
std::string err_string = "Drive system error: ";
err_string += ex.what();
DriverStation::ReportError(err_string.c_str());
}
Wait(0.005); // wait 5ms to avoid hogging CPU cycles
}
}
示例13: imuSetup
void imuSetup ( void ) {
//MPU initialization
imu->initialize();
printf( "Beginning Gyro calibration...\n" );
for( int i = 0 ; i < 100; i++ ) {
imu->update();
imu->read_gyroscope( &gx , &gy , &gz);
offset[0] += ( -gx );
offset[1] += ( -gy );
offset[2] += ( -gz );
usleep(10000);
}
offset[0] /= 100.0;
offset[1] /= 100.0;
offset[2] /= 100.0;
printf( "Offsets are: %f %f %f\n" ,offset[0] ,offset[1] ,offset[2] );
ahrs.setGyroOffset( offset[0] , offset[1] , offset[2] );
}
示例14: imuSetup
void imuSetup()
{
//----------------------- MPU initialization ------------------------------
imu->initialize();
//-------------------------------------------------------------------------
printf("Beginning Gyro calibration...\n");
for(int i = 0; i<100; i++)
{
imu->update();
imu->read_gyroscope(&gx, &gy, &gz);
gx *= 180 / PI;
gy *= 180 / PI;
gz *= 180 / PI;
offset[0] += (-gx*0.0175);
offset[1] += (-gy*0.0175);
offset[2] += (-gz*0.0175);
usleep(10000);
}
offset[0]/=100.0;
offset[1]/=100.0;
offset[2]/=100.0;
printf("Offsets are: %f %f %f\n", offset[0], offset[1], offset[2]);
ahrs.setGyroOffset(offset[0], offset[1], offset[2]);
}
示例15: OperatorControl
/**
* Runs the motors with Mecanum drive.
*/
void OperatorControl()
{
robotDrive.SetSafetyEnabled(false);
while (IsOperatorControl() && IsEnabled())
{
bool reset_yaw_button_pressed = stick.GetRawButton(1);
if ( reset_yaw_button_pressed ) {
ahrs->ZeroYaw();
}
bool rotateToAngle = false;
if ( stick.GetRawButton(2)) {
turnController->SetSetpoint(0.0f);
rotateToAngle = true;
} else if ( stick.GetRawButton(3)) {
turnController->SetSetpoint(90.0f);
rotateToAngle = true;
} else if ( stick.GetRawButton(4)) {
turnController->SetSetpoint(179.9f);
rotateToAngle = true;
} else if ( stick.GetRawButton(5)) {
turnController->SetSetpoint(-90.0f);
rotateToAngle = true;
}
double currentRotationRate;
if ( rotateToAngle ) {
turnController->Enable();
currentRotationRate = rotateToAngleRate;
} else {
turnController->Disable();
currentRotationRate = stick.GetTwist();
}
try {
/* Use the joystick X axis for lateral movement, */
/* Y axis for forward movement, and the current */
/* calculated rotation rate (or joystick Z axis), */
/* depending upon whether "rotate to angle" is active. */
robotDrive.MecanumDrive_Cartesian(stick.GetX(), stick.GetY(),
currentRotationRate ,ahrs->GetAngle());
} catch (std::exception ex ) {
std::string err_string = "Error communicating with Drive System: ";
err_string += ex.what();
DriverStation::ReportError(err_string.c_str());
}
Wait(0.005); // wait 5ms to avoid hogging CPU cycles
}
}