001/* 002 * Software License Agreement 003 * 004 * Copyright (C) Cross The Road Electronics. All rights 005 * reserved. 006 * 007 * Cross The Road Electronics (CTRE) licenses to you the right to 008 * use, publish, and distribute copies of CRF (Cross The Road) firmware files (*.crf) and Software 009 * API Libraries ONLY when in use with Cross The Road Electronics hardware products. 010 * 011 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT 012 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT 013 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A 014 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL 015 * CROSS THE ROAD ELECTRONICS BE LIABLE FOR ANY INCIDENTAL, SPECIAL, 016 * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF 017 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS 018 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE 019 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER 020 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT 021 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE 022 */ 023package com.ctre.phoenix.sensors; 024import com.ctre.phoenix.ErrorCode; 025import com.ctre.phoenix.ParamEnum; 026import com.ctre.phoenix.ErrorCollection; 027import com.ctre.phoenix.CustomParamConfigUtil; 028 029//import edu.wpi.first.wpilibj.hal.FRCNetComm.tResourceType; 030//import edu.wpi.first.wpilibj.hal.HAL; 031 032/** 033 * Pigeon IMU Class. Class supports communicating over CANbus and over 034 * ribbon-cable (CAN Talon SRX). 035 */ 036public class BasePigeon { 037 private long m_handle; 038 private BasePigeonSimCollection m_simCollection; 039 040 private int m_deviceNumber = 0; 041 042 /** 043 * Create a Pigeon object that communicates with Pigeon on CAN Bus. 044 * 045 * @param deviceNumber 046 * CAN Device Id of Pigeon [0,62] 047 * @param version Version of the PigeonIMU 048 * @param canbus Name of the CANbus; can be a SocketCAN interface (on Linux), 049 * or a CANivore device name or serial number 050 */ 051 public BasePigeon(int deviceNumber, String version, String canbus) { 052 m_handle = PigeonImuJNI.JNI_new_PigeonImu(deviceNumber, version, canbus); 053 m_deviceNumber = deviceNumber; 054 m_simCollection = new BasePigeonSimCollection(this, false); 055 } 056 057 /** 058 * Create a Pigeon object that communicates with Pigeon on CAN Bus. 059 * 060 * @param deviceNumber 061 * CAN Device Id of Pigeon [0,62] 062 * @param version Version of the PigeonIMU 063 */ 064 public BasePigeon(int deviceNumber, String version) { 065 this(deviceNumber, version, ""); 066 } 067 068 protected BasePigeon(long handle) { 069 m_handle = handle; 070 m_simCollection = new BasePigeonSimCollection(this, false); 071 } 072 073 /** 074 * Destructor for Pigeon 075 * @return Error Code generated by function. 0 indicates no error. 076 */ 077 public ErrorCode DestroyObject() { 078 return ErrorCode.valueOf(PigeonImuJNI.JNI_destroy_PigeonImu(m_handle)); 079 } 080 081 //public static void DestroyAllBasePigeons() { 082 // PigeonImuJNI.JNI_destroy_AllBasePigeons(); 083 //} 084 085 /** 086 * @return object that can set simulation inputs. 087 */ 088 public BasePigeonSimCollection getSimCollection(){ return m_simCollection;} 089 090 /** 091 * Sets the Yaw register to the specified value. 092 * 093 * @param angleDeg New yaw in degrees [+/- 368,640 degrees] 094 * @param timeoutMs 095 * Timeout value in ms. If nonzero, function will wait for 096 * config success and report an error if it times out. 097 * If zero, no blocking or checking is performed. 098 * @return Error Code generated by function. 0 indicates no error. 099 */ 100 public ErrorCode setYaw(double angleDeg, int timeoutMs) { 101 int retval = PigeonImuJNI.JNI_SetYaw(m_handle, angleDeg, timeoutMs); 102 return ErrorCode.valueOf(retval); 103 } 104 /** 105 * Sets the Yaw register to the specified value. 106 * 107 * @param angleDeg New yaw in degrees [+/- 368,640 degrees] 108 * @return Error Code generated by function. 0 indicates no error. 109 */ 110 public ErrorCode setYaw(double angleDeg) { 111 int timeoutMs = 0; 112 return setYaw( angleDeg, timeoutMs); 113 } 114 /** 115 * Atomically add to the Yaw register. 116 * 117 * @param angleDeg Degrees to add to the Yaw register. 118 * @param timeoutMs 119 * Timeout value in ms. If nonzero, function will wait for 120 * config success and report an error if it times out. 121 * If zero, no blocking or checking is performed. 122 * @return Error Code generated by function. 0 indicates no error. 123 */ 124 public ErrorCode addYaw(double angleDeg, int timeoutMs) { 125 int retval = PigeonImuJNI.JNI_AddYaw(m_handle, angleDeg, timeoutMs); 126 return ErrorCode.valueOf(retval); 127 } 128 /** 129 * Atomically add to the Yaw register. 130 * 131 * @param angleDeg Degrees to add to the Yaw register. 132 * @return Error Code generated by function. 0 indicates no error. 133 */ 134 public ErrorCode addYaw(double angleDeg) { 135 int timeoutMs = 0; 136 return addYaw( angleDeg, timeoutMs); 137 } 138 /** 139 * Sets the Yaw register to match the current compass value. 140 * 141 * @param timeoutMs 142 * Timeout value in ms. If nonzero, function will wait for 143 * config success and report an error if it times out. 144 * If zero, no blocking or checking is performed. 145 * @return Error Code generated by function. 0 indicates no error. 146 */ 147 public ErrorCode setYawToCompass(int timeoutMs) { 148 int retval = PigeonImuJNI.JNI_SetYawToCompass(m_handle, timeoutMs); 149 return ErrorCode.valueOf(retval); 150 } 151 /** 152 * Sets the Yaw register to match the current compass value. 153 * 154 * @return Error Code generated by function. 0 indicates no error. 155 */ 156 public ErrorCode setYawToCompass() { 157 int timeoutMs = 0; 158 return setYawToCompass(timeoutMs); 159 } 160 /** 161 * Sets the AccumZAngle. 162 * 163 * @param angleDeg Degrees to set AccumZAngle to. 164 * @param timeoutMs 165 * Timeout value in ms. If nonzero, function will wait for 166 * config success and report an error if it times out. 167 * If zero, no blocking or checking is performed. 168 * @return Error Code generated by function. 0 indicates no error. 169 */ 170 public ErrorCode setAccumZAngle(double angleDeg, int timeoutMs) { 171 int retval = PigeonImuJNI.JNI_SetAccumZAngle(m_handle, angleDeg, timeoutMs); 172 return ErrorCode.valueOf(retval); 173 } 174 /** 175 * Sets the AccumZAngle. 176 * 177 * @param angleDeg Degrees to set AccumZAngle to. 178 * @return Error Code generated by function. 0 indicates no error. 179 */ 180 public ErrorCode setAccumZAngle(double angleDeg) { 181 int timeoutMs = 0; 182 return setAccumZAngle(angleDeg, timeoutMs); 183 } 184 185 // ----------------------- General Error status -----------------------// 186 /** 187 * Call GetLastError() generated by this object. 188 * Not all functions return an error code but can 189 * potentially report errors. 190 * 191 * This function can be used to retrieve those error codes. 192 * 193 * @return The last ErrorCode generated. 194 */ 195 public ErrorCode getLastError() { 196 int retval = PigeonImuJNI.JNI_GetLastError(m_handle); 197 return ErrorCode.valueOf(retval); 198 } 199 200 // ----------------------- Strongly typed Signal decoders 201 // -----------------------// 202 /** 203 * Get 6d Quaternion data. 204 * 205 * @param wxyz Array to fill with quaternion data w[0], x[1], y[2], z[3] 206 * @return The last ErrorCode generated. 207 */ 208 public ErrorCode get6dQuaternion(double[] wxyz) { 209 int retval = PigeonImuJNI.JNI_Get6dQuaternion(m_handle, wxyz); 210 return ErrorCode.valueOf(retval); 211 } 212 /** 213 * Get Yaw, Pitch, and Roll data. 214 * 215 * @param ypr_deg Array to fill with yaw[0], pitch[1], and roll[2] data. 216 * Yaw is within [-368,640, +368,640] degrees. 217 * Pitch is within [-90,+90] degrees. 218 * Roll is within [-90,+90] degrees. 219 * @return The last ErrorCode generated. 220 */ 221 public ErrorCode getYawPitchRoll(double[] ypr_deg) { 222 int retval = PigeonImuJNI.JNI_GetYawPitchRoll(m_handle, ypr_deg); 223 return ErrorCode.valueOf(retval); 224 } 225 226 /** 227 * Get the yaw from the Pigeon 228 * @return Yaw 229 */ 230 public double getYaw() { 231 return PigeonImuJNI.JNI_GetYaw(m_handle); 232 } 233 /** 234 * Get the pitch from the Pigeon 235 * @return Pitch 236 */ 237 public double getPitch() { 238 return PigeonImuJNI.JNI_GetPitch(m_handle); 239 } 240 /** 241 * Get the roll from the Pigeon 242 * @return Roll 243 */ 244 public double getRoll() { 245 return PigeonImuJNI.JNI_GetRoll(m_handle); 246 } 247 /** 248 * Get AccumGyro data. 249 * AccumGyro is the integrated gyro value on each axis. 250 * 251 * @param xyz_deg Array to fill with x[0], y[1], and z[2] AccumGyro data 252 * @return The last ErrorCode generated. 253 */ 254 public ErrorCode getAccumGyro(double[] xyz_deg) { 255 int retval = PigeonImuJNI.JNI_GetAccumGyro(m_handle, xyz_deg); 256 return ErrorCode.valueOf(retval); 257 } 258 259 /** 260 * Get the absolute compass heading. 261 * @return compass heading [0,360) degrees. 262 */ 263 public double getAbsoluteCompassHeading() { 264 double retval = PigeonImuJNI.JNI_GetAbsoluteCompassHeading(m_handle); 265 return retval; 266 } 267 268 /** 269 * Get the continuous compass heading. 270 * @return continuous compass heading [-23040, 23040) degrees. Use 271 * SetCompassHeading to modify the wrap-around portion. 272 */ 273 public double getCompassHeading() { 274 double retval = PigeonImuJNI.JNI_GetCompassHeading(m_handle); 275 return retval; 276 } 277 278 /** 279 * Gets the compass' measured magnetic field strength. 280 * @return field strength in Microteslas (uT). 281 */ 282 public double getCompassFieldStrength() { 283 double retval = PigeonImuJNI.JNI_GetCompassFieldStrength(m_handle); 284 return retval; 285 } 286 /** 287 * Gets the temperature of the pigeon. 288 * 289 * @return Temperature in ('C) 290 */ 291 public double getTemp() { 292 double retval = PigeonImuJNI.JNI_GetTemp(m_handle); 293 return retval; 294 } 295 296 /** 297 * Gets the current Pigeon uptime. 298 * 299 * @return How long has Pigeon been running in whole seconds. Value caps at 300 * 255. 301 */ 302 public int getUpTime() { 303 int retval = PigeonImuJNI.JNI_GetUpTime(m_handle); 304 return retval; 305 } 306 /** 307 * Get Raw Magnetometer data. 308 * 309 * @param rm_xyz Array to fill with x[0], y[1], and z[2] data 310 * Number is equal to 0.6 microTeslas per unit. 311 * @return The last ErrorCode generated. 312 */ 313 public ErrorCode getRawMagnetometer(short[] rm_xyz) { 314 int retval = PigeonImuJNI.JNI_GetRawMagnetometer(m_handle, rm_xyz); 315 return ErrorCode.valueOf(retval); 316 } 317 /** 318 * Get Biased Magnetometer data. 319 * 320 * @param bm_xyz Array to fill with x[0], y[1], and z[2] data 321 * Number is equal to 0.6 microTeslas per unit. 322 * @return The last ErrorCode generated. 323 */ 324 public ErrorCode getBiasedMagnetometer(short[] bm_xyz) { 325 int retval = PigeonImuJNI.JNI_GetBiasedMagnetometer(m_handle, bm_xyz); 326 return ErrorCode.valueOf(retval); 327 } 328 /** 329 * Get Biased Accelerometer data. 330 * 331 * @param ba_xyz Array to fill with x[0], y[1], and z[2] data. 332 * These are in fixed point notation Q2.14. eg. 16384 = 1G 333 * @return The last ErrorCode generated. 334 */ 335 public ErrorCode getBiasedAccelerometer(short[] ba_xyz) { 336 int retval = PigeonImuJNI.JNI_GetBiasedAccelerometer(m_handle, ba_xyz); 337 return ErrorCode.valueOf(retval); 338 } 339 /** 340 * Get Raw Gyro data. 341 * 342 * @param xyz_dps Array to fill with x[0], y[1], and z[2] data in degrees per second. 343 * @return The last ErrorCode generated. 344 */ 345 public ErrorCode getRawGyro(double[] xyz_dps) { 346 int retval = PigeonImuJNI.JNI_GetRawGyro(m_handle, xyz_dps); 347 return ErrorCode.valueOf(retval); 348 } 349 350 /** 351 * @return number of times Pigeon Reset 352 */ 353 public int getResetCount() { 354 int k = PigeonImuJNI.JNI_GetResetCount(m_handle); 355 return k; 356 } 357 /** 358 * @return Reset flags for Pigeon 359 */ 360 public int getResetFlags() { 361 int k = PigeonImuJNI.JNI_GetResetFlags(m_handle); 362 return k; 363 } 364 /** 365 * Gets the firmware version of the device. 366 * 367 * @return param holds the firmware version of the device. Device must be powered 368 * cycled at least once. 369 */ 370 public int getFirmwareVersion() { 371 int k = PigeonImuJNI.JNI_GetFirmwareVersion(m_handle); 372 return k; 373 } 374 375 /** 376 * @return true iff a reset has occurred since last call. 377 */ 378 public boolean hasResetOccurred() { 379 boolean k = PigeonImuJNI.JNI_HasResetOccurred(m_handle); 380 return k; 381 } 382 383 /** 384 * Sets the value of a custom parameter. This is for arbitrary use. 385 * 386 * Sometimes it is necessary to save calibration/declination/offset 387 * information in the device. Particularly if the 388 * device is part of a subsystem that can be replaced. 389 * 390 * @param newValue 391 * Value for custom parameter. 392 * @param paramIndex 393 * Index of custom parameter. [0-1] 394 * @param timeoutMs 395 * Timeout value in ms. If nonzero, function will wait for 396 * config success and report an error if it times out. 397 * If zero, no blocking or checking is performed. 398 * @return Error Code generated by function. 0 indicates no error. 399 */ 400 public ErrorCode configSetCustomParam(int newValue, int paramIndex, int timeoutMs) { 401 int retval = PigeonImuJNI.JNI_ConfigSetCustomParam(m_handle, newValue, paramIndex, timeoutMs); 402 return ErrorCode.valueOf(retval); 403 } 404 /** 405 * Sets the value of a custom parameter. This is for arbitrary use. 406 * 407 * Sometimes it is necessary to save calibration/declination/offset 408 * information in the device. Particularly if the 409 * device is part of a subsystem that can be replaced. 410 * 411 * @param newValue 412 * Value for custom parameter. 413 * @param paramIndex 414 * Index of custom parameter. [0-1] 415 * @return Error Code generated by function. 0 indicates no error. 416 */ 417 public ErrorCode configSetCustomParam(int newValue, int paramIndex ) { 418 int timeoutMs = 0; 419 return configSetCustomParam( newValue, paramIndex, timeoutMs); 420 } 421 422 /** 423 * Gets the value of a custom parameter. This is for arbitrary use. 424 * 425 * Sometimes it is necessary to save calibration/declination/offset 426 * information in the device. Particularly if the 427 * device is part of a subsystem that can be replaced. 428 * 429 * @param paramIndex 430 * Index of custom parameter. [0-1] 431 * @param timoutMs 432 * Timeout value in ms. If nonzero, function will wait for 433 * config success and report an error if it times out. 434 * If zero, no blocking or checking is performed. 435 * @return Value of the custom param. 436 */ 437 public int configGetCustomParam(int paramIndex, int timoutMs) { 438 int retval = PigeonImuJNI.JNI_ConfigGetCustomParam(m_handle, paramIndex, timoutMs); 439 return retval; 440 } 441 /** 442 * Gets the value of a custom parameter. This is for arbitrary use. 443 * 444 * Sometimes it is necessary to save calibration/declination/offset 445 * information in the device. Particularly if the 446 * device is part of a subsystem that can be replaced. 447 * 448 * @param paramIndex 449 * Index of custom parameter. [0-1] 450 * @return Value of the custom param. 451 */ 452 public int configGetCustomParam(int paramIndex) { 453 int timeoutMs = 0; 454 return configGetCustomParam(paramIndex,timeoutMs); 455 } 456 457 /** 458 * Sets a parameter. Generally this is not used. 459 * This can be utilized in 460 * - Using new features without updating API installation. 461 * - Errata workarounds to circumvent API implementation. 462 * - Allows for rapid testing / unit testing of firmware. 463 * 464 * @param param 465 * Parameter enumeration. 466 * @param value 467 * Value of parameter. 468 * @param subValue 469 * Subvalue for parameter. Maximum value of 255. 470 * @param ordinal 471 * Ordinal of parameter. 472 * @param timeoutMs 473 * Timeout value in ms. If nonzero, function will wait for 474 * config success and report an error if it times out. 475 * If zero, no blocking or checking is performed. 476 * @return Error Code generated by function. 0 indicates no error. 477 */ 478 public ErrorCode configSetParameter(ParamEnum param, double value, int subValue, int ordinal, int timeoutMs) { 479 return configSetParameter(param.value, value, subValue, ordinal, timeoutMs); 480 } 481 /** 482 * Sets a parameter. Generally this is not used. 483 * This can be utilized in 484 * - Using new features without updating API installation. 485 * - Errata workarounds to circumvent API implementation. 486 * - Allows for rapid testing / unit testing of firmware. 487 * 488 * @param param 489 * Parameter enumeration. 490 * @param value 491 * Value of parameter. 492 * @param subValue 493 * Subvalue for parameter. Maximum value of 255. 494 * @param ordinal 495 * Ordinal of parameter. 496 * @return Error Code generated by function. 0 indicates no error. 497 */ 498 public ErrorCode configSetParameter(ParamEnum param, double value, int subValue, int ordinal) { 499 int timeoutMs = 0; 500 return configSetParameter(param, value, subValue, ordinal, timeoutMs); 501 } 502 /** 503 * Sets a parameter. Generally this is not used. 504 * This can be utilized in 505 * - Using new features without updating API installation. 506 * - Errata workarounds to circumvent API implementation. 507 * - Allows for rapid testing / unit testing of firmware. 508 * 509 * @param param 510 * Parameter enumeration. 511 * @param value 512 * Value of parameter. 513 * @param subValue 514 * Subvalue for parameter. Maximum value of 255. 515 * @param ordinal 516 * Ordinal of parameter. 517 * @param timeoutMs 518 * Timeout value in ms. If nonzero, function will wait for 519 * config success and report an error if it times out. 520 * If zero, no blocking or checking is performed. 521 * @return Error Code generated by function. 0 indicates no error. 522 */ 523 public ErrorCode configSetParameter(int param, double value, int subValue, int ordinal, int timeoutMs) { 524 int retval = PigeonImuJNI.JNI_ConfigSetParameter(m_handle, param, value, subValue, ordinal, 525 timeoutMs); 526 return ErrorCode.valueOf(retval); 527 } 528 /** 529 * Sets a parameter. Generally this is not used. 530 * This can be utilized in 531 * - Using new features without updating API installation. 532 * - Errata workarounds to circumvent API implementation. 533 * - Allows for rapid testing / unit testing of firmware. 534 * 535 * @param param 536 * Parameter enumeration. 537 * @param value 538 * Value of parameter. 539 * @param subValue 540 * Subvalue for parameter. Maximum value of 255. 541 * @param ordinal 542 * Ordinal of parameter. 543 * @return Error Code generated by function. 0 indicates no error. 544 */ 545 public ErrorCode configSetParameter(int param, double value, int subValue, int ordinal) { 546 int timeoutMs = 0; 547 return configSetParameter( param, value, subValue, ordinal, timeoutMs); 548 } 549 /** 550 * Gets a parameter. Generally this is not used. 551 * This can be utilized in 552 * - Using new features without updating API installation. 553 * - Errata workarounds to circumvent API implementation. 554 * - Allows for rapid testing / unit testing of firmware. 555 * 556 * @param param 557 * Parameter enumeration. 558 * @param ordinal 559 * Ordinal of parameter. 560 * @param timeoutMs 561 * Timeout value in ms. If nonzero, function will wait for 562 * config success and report an error if it times out. 563 * If zero, no blocking or checking is performed. 564 * @return Value of parameter. 565 */ 566 public double configGetParameter(ParamEnum param, int ordinal, int timeoutMs) { 567 return configGetParameter(param.value, ordinal, timeoutMs); 568 } 569 /** 570 * Gets a parameter. Generally this is not used. 571 * This can be utilized in 572 * - Using new features without updating API installation. 573 * - Errata workarounds to circumvent API implementation. 574 * - Allows for rapid testing / unit testing of firmware. 575 * 576 * @param param 577 * Parameter enumeration. 578 * @param ordinal 579 * Ordinal of parameter. 580 * @return Value of parameter. 581 */ 582 public double configGetParameter(ParamEnum param, int ordinal ) { 583 int timeoutMs = 0; 584 return configGetParameter(param, ordinal, timeoutMs); 585 } 586 /** 587 * Gets a parameter. 588 * 589 * @param param 590 * Parameter enumeration. 591 * @param ordinal 592 * Ordinal of parameter. 593 * @param timeoutMs 594 * Timeout value in ms. If nonzero, function will wait for 595 * config success and report an error if it times out. 596 * If zero, no blocking or checking is performed. 597 * @return Value of parameter. 598 */ 599 public double configGetParameter(int param, int ordinal, int timeoutMs) { 600 return PigeonImuJNI.JNI_ConfigGetParameter(m_handle, param, ordinal, timeoutMs); 601 } 602 /** 603 * Gets a parameter. 604 * 605 * @param param 606 * Parameter enumeration. 607 * @param ordinal 608 * Ordinal of parameter. 609 * @return Value of parameter. 610 */ 611 public double configGetParameter(int param, int ordinal) { 612 int timeoutMs = 0; 613 return configGetParameter( param, ordinal, timeoutMs); 614 } 615 /** 616 * Sets the period of the given status frame. 617 * 618 * @param statusFrame 619 * Frame whose period is to be changed. 620 * @param periodMs 621 * Period in ms for the given frame. 622 * @param timeoutMs 623 * Timeout value in ms. If nonzero, function will wait for 624 * config success and report an error if it times out. 625 * If zero, no blocking or checking is performed. 626 * @return Error Code generated by function. 0 indicates no error. 627 */ 628 public ErrorCode setStatusFramePeriod(PigeonIMU_StatusFrame statusFrame, int periodMs, int timeoutMs) { 629 int retval = PigeonImuJNI.JNI_SetStatusFramePeriod(m_handle, statusFrame.value, periodMs, timeoutMs); 630 return ErrorCode.valueOf(retval); 631 } 632 /** 633 * Sets the period of the given status frame. 634 * 635 * @param statusFrame 636 * Frame whose period is to be changed. 637 * @param periodMs 638 * Period in ms for the given frame. 639 * @return Error Code generated by function. 0 indicates no error. 640 */ 641 public ErrorCode setStatusFramePeriod(PigeonIMU_StatusFrame statusFrame, int periodMs) { 642 int timeoutMs = 0; 643 return setStatusFramePeriod( statusFrame, periodMs, timeoutMs); 644 } 645 /** 646 * Sets the period of the given status frame. 647 * 648 * @param statusFrame 649 * Frame whose period is to be changed. 650 * @param periodMs 651 * Period in ms for the given frame. 652 * @param timeoutMs 653 * Timeout value in ms. If nonzero, function will wait for 654 * config success and report an error if it times out. 655 * If zero, no blocking or checking is performed. 656 * @return Error Code generated by function. 0 indicates no error. 657 */ 658 public ErrorCode setStatusFramePeriod(int statusFrame, int periodMs, int timeoutMs) { 659 int retval = PigeonImuJNI.JNI_SetStatusFramePeriod(m_handle, statusFrame, periodMs, timeoutMs); 660 return ErrorCode.valueOf(retval); 661 } 662 /** 663 * Sets the period of the given status frame. 664 * 665 * @param statusFrame 666 * Frame whose period is to be changed. 667 * @param periodMs 668 * Period in ms for the given frame. 669 * @return Error Code generated by function. 0 indicates no error. 670 */ 671 public ErrorCode setStatusFramePeriod(int statusFrame, int periodMs) { 672 int timeoutMs = 0; 673 return setStatusFramePeriod( statusFrame, periodMs, timeoutMs); 674 } 675 676 /** 677 * Gets the period of the given status frame. 678 * 679 * @param frame 680 * Frame to get the period of. 681 * @param timeoutMs 682 * Timeout value in ms. If nonzero, function will wait for 683 * config success and report an error if it times out. 684 * If zero, no blocking or checking is performed. 685 * @return Period of the given status frame. 686 */ 687 public int getStatusFramePeriod(PigeonIMU_StatusFrame frame, int timeoutMs) { 688 return PigeonImuJNI.JNI_GetStatusFramePeriod(m_handle, frame.value, timeoutMs); 689 } 690 /** 691 * Gets the period of the given status frame. 692 * 693 * @param frame 694 * Frame to get the period of. 695 * @return Period of the given status frame. 696 */ 697 public int getStatusFramePeriod(PigeonIMU_StatusFrame frame) { 698 int timeoutMs = 0; 699 return getStatusFramePeriod(frame, timeoutMs); 700 } 701 /** 702 * Sets the period of the given control frame. 703 * 704 * @param frame 705 * Frame whose period is to be changed. 706 * @param periodMs 707 * Period in ms for the given frame. 708 * @return Error Code generated by function. 0 indicates no error. 709 */ 710 public ErrorCode setControlFramePeriod(PigeonIMU_ControlFrame frame, int periodMs) { 711 int retval = PigeonImuJNI.JNI_SetControlFramePeriod(m_handle, frame.value, periodMs); 712 return ErrorCode.valueOf(retval); 713 } 714 /** 715 * Sets the period of the given control frame. 716 * 717 * @param frame 718 * Frame whose period is to be changed. 719 * @param periodMs 720 * Period in ms for the given frame. 721 * @return Error Code generated by function. 0 indicates no error. 722 */ 723 public ErrorCode setControlFramePeriod(int frame, int periodMs) { 724 int retval = PigeonImuJNI.JNI_SetControlFramePeriod(m_handle, frame, periodMs); 725 return ErrorCode.valueOf(retval); 726 } 727 728 // ------ Faults ----------// 729 /** 730 * Clears the Sticky Faults 731 * 732 * @param timeoutMs 733 * Timeout value in ms. If nonzero, function will wait for 734 * config success and report an error if it times out. 735 * If zero, no blocking or checking is performed. 736 * @return Error Code generated by function. 0 indicates no error. 737 */ 738 public ErrorCode clearStickyFaults(int timeoutMs) { 739 int retval = PigeonImuJNI.JNI_ClearStickyFaults(m_handle, timeoutMs); 740 return ErrorCode.valueOf(retval); 741 } 742 /** 743 * Clears the Sticky Faults 744 * 745 * @return Error Code generated by function. 0 indicates no error. 746 */ 747 public ErrorCode clearStickyFaults() { 748 int timeoutMs = 0; 749 return clearStickyFaults(timeoutMs); 750 } 751 752 /** 753 * @return The Device Number 754 */ 755 public int getDeviceID(){ 756 return m_deviceNumber; 757 } 758 /** 759 * Configures all persistent settings. 760 * 761 * @param allConfigs Object with all of the persistant settings 762 * @param timeoutMs 763 * Timeout value in ms. If nonzero, function will wait for 764 * config success and report an error if it times out. 765 * If zero, no blocking or checking is performed. 766 * 767 * @return Error Code generated by function. 0 indicates no error. 768 */ 769 public ErrorCode configAllSettings(PigeonIMUConfiguration allConfigs, int timeoutMs) { 770 ErrorCollection errorCollection = new ErrorCollection(); 771 772 errorCollection.NewError(configFactoryDefault(timeoutMs)); 773 774 if(CustomParamConfigUtil.customParam0Different(allConfigs)) 775 errorCollection.NewError(configSetCustomParam(allConfigs.customParam0, 0, timeoutMs)); 776 if(CustomParamConfigUtil.customParam1Different(allConfigs)) 777 errorCollection.NewError(configSetCustomParam(allConfigs.customParam1, 1, timeoutMs)); 778 779 780 return errorCollection._worstError; 781 782 } 783 /** 784 * Configures all persistent settings (overloaded so timeoutMs is 50 ms). 785 * 786 * @param allConfigs Object with all of the persistant settings 787 * 788 * @return Error Code generated by function. 0 indicates no error. 789 */ 790 public ErrorCode configAllSettings(PigeonIMUConfiguration allConfigs) { 791 int timeoutMs = 0; 792 return configAllSettings(allConfigs, timeoutMs); 793 } 794 /** 795 * Gets all persistant settings. 796 * 797 * @param allConfigs Object with all of the persistant settings 798 * @param timeoutMs 799 * Timeout value in ms. If nonzero, function will wait for 800 * config success and report an error if it times out. 801 * If zero, no blocking or checking is performed. 802 */ 803 public void getAllConfigs(PigeonIMUConfiguration allConfigs, int timeoutMs) { 804 805 allConfigs.customParam0 = (int) configGetParameter(ParamEnum.eCustomParam, 0, timeoutMs); 806 allConfigs.customParam1 = (int) configGetParameter(ParamEnum.eCustomParam, 1, timeoutMs); 807 } 808 /** 809 * Gets all persistant settings (overloaded so timeoutMs is 50 ms). 810 * 811 * @param allConfigs Object with all of the persistant settings 812 */ 813 public void getAllConfigs(PigeonIMUConfiguration allConfigs) { 814 int timeoutMs = 50; 815 getAllConfigs(allConfigs, timeoutMs); 816 } 817 /** 818 * Configures all persistent settings to defaults. 819 * 820 * @param timeoutMs 821 * Timeout value in ms. If nonzero, function will wait for 822 * config success and report an error if it times out. 823 * If zero, no blocking or checking is performed. 824 * 825 * @return Error Code generated by function. 0 indicates no error. 826 */ 827 public ErrorCode configFactoryDefault(int timeoutMs) { 828 return ErrorCode.valueOf(PigeonImuJNI.JNI_ConfigFactoryDefault(m_handle, timeoutMs)); 829 } 830 /** 831 * Configures all persistent settings to defaults (overloaded so timeoutMs is 50 ms). 832 * 833 * @return Error Code generated by function. 0 indicates no error. 834 */ 835 public ErrorCode configFactoryDefault() { 836 int timeoutMs = 50; 837 return configFactoryDefault(timeoutMs); 838 839 } 840 841 public long getHandle() { return m_handle; } 842 843}