This library is for the receiver end of the Razor 9 DOF IMU (reference here.
It is suggested that you download the entire repository and then select this folder, so that you can enjoy the benifits of VCS like git. It makes it simpler to update the contents whenever patch fixes are done. You can simply open a terminal (or gitbash on windows), go to the folder where you want to save this repository and type the following command.
git clone https://github.com/shashank3199/RazorIMU_9DOF
Not recommended: You can download only this folder by clicking here
Move this folder into the arduino libraries folder on your PC. If you don't know where the libraries folder of your arduino is, you can check out the README file of this entire repository for this, click here.
Please follow the following steps before working with this library:
- Download the official code folder from here, you'll be uploading this to the IMU.
- Extract folder Razor_AHRS to an appropriate location, open the Razor_AHRS file in Arduino IDE.
- Under the tools dropdown, select the following:
- Board: Arduino Pro or Pro Mini
- Processor: Atmega 328P (3.3V, 8MHz)
- Port: The connected port (/dev/ttyUSB* for Ubuntu, COM* for windows).
- In the code of Razor_AHRS file, go to USER SETUP AREA and uncomment the correct #define HW__VERSION_CODE. It's 10736 in our examples, check the version from the correct hardware datasheet.
- Upload the code.
- Open serial monitor
- Set baud rate to 57600
- There must be output
More info about setting up software here.
In order to use this library, you must do the following:
- Include the header file
RazorIMU_9DOF.h
(the RazorIMU_9DOF library folder must be in your arduino libraries folder). - Create an object of class
RazorIMU_9DOF
. You can pass the constructor parameters to initialize here itself, or leave it as a simple object declaration. - Initialize the Serial stream on which the IMU is attached using the
AttachIMUSerial
function. - To avoid wastage of resources, the library doesn't continuously poll the serial. You must call the function
UpdateData
for the library to fetch the values from the serial. - To get the values, you can use one of the getter functions, for example if you want to access the YAW value, then you could use the function: GetYaw which will give you the continuous YAW value.
This example is to show you how to fetch YAW, PITCH and ROLL values from the IMU using the RazorIMU_9DOF
library.
File: ./examples/Get_RPY_values/Get_RPY_values.ino
We simply follow the following steps:
- Include library
- Create object
- Initialize Serials. IMU on Serial1. Keep in mind to match the baud rates.
- Attach the serial of the IMU
- Then start a loop
- Update the data readings from IMU
- Get YAW, PITCH and ROLL values
- Re-run the loop
This library has a single class named RazorIMU_9DOF
. Let's explore all the contents in detail.
The header file for the RazorIMU_9DOF
class. It only has function declarations, not definitions.
This file consists the code for all the functions declared in the RazorIMU_9DOF
class.
This file consists the list of keywords and their types to be recognized by the Arduino IDE.
The description file that you're currently reading. All documentation here.
Let's explore the contents of the class, but first, we also have literals defined for general purpose use (using #define
). They are:
Name | Value | Purpose |
---|---|---|
PITCH | 0 | The index of pitch values in arrays |
ROLL | 1 | The index of roll values in arrays |
YAW | 2 | The index of yaw values in arrays |
Let's explore the class now
- float YPR_values[3]: Stores the values (-180 to 180, as output by the module) of Roll, Pitch and Yaw.
- Stream *IMU_Serial: This is the serial on which IMU operates. The parent Stream class allows any kind of serial, Hardware or Software.
- RazorIMU_9DOF(): Empty constructor for the class.
- RazorIMU_9DOF(Stream *AttachedSerial): To attach a pre-initialized serial to the IMU. This function calls the AttachIMUSerial member function.
- void AttachIMUSerial(Stream *AttachedSerial): Connect the IMU Serial.
- void UpdateData(): Updates the IMU readings stored in variables of the class.
- float GetRoll(): To get the continuous ROLL values.
- float GetPitch(): To get the continuous PITCH values.
- float GetYaw(): To get the continuous YAW values.