-
-
Save tjtolon/d7f25c9a911f37a9c738c02eeb1ae117 to your computer and use it in GitHub Desktop.
Sample code for getting data form the Microstrain IMU sensor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mscl/Communication/Connection.h" | |
#include "mscl/MicroStrain/Inertial/InertialNode.h" | |
#include <iostream> | |
using namespace std; | |
using namespace mscl; | |
void printStatus(mscl::InertialNode& node) { | |
mscl::MipChannels channels = node.getActiveChannelFields(mscl::MipTypes::CLASS_AHRS_IMU); | |
cout << "Number of channels: " << channels.size() << endl; | |
cout << "Communication mode: " << node.getCommunicationMode() << endl; | |
DeviceStatusData basicStatus = node.getBasicDeviceStatus(); | |
cout << "Basic Status: " << endl; | |
cout << " system state: " << basicStatus.systemState << endl; | |
cout << " imuStreamIsEnabled: " << basicStatus.imuStreamIsEnabled << endl; | |
cout << " outgoingIMUDroppedPacketCount: " << | |
basicStatus.outgoingIMUDroppedPacketCount << endl; | |
cout << " numOfBytesWrittenToComPort: " << | |
basicStatus.numOfBytesWrittenToComPort << endl; | |
cout << " numOfBytesWrittenFromComPort: " << | |
basicStatus.numOfBytesWrittenFromComPort << endl; | |
} | |
int main(void) { | |
mscl::Connection my_connection = | |
mscl::Connection::Serial("/dev/ttyACM0", 115200); | |
////create the InertialNode, passing in the connection | |
mscl::InertialNode node(my_connection); | |
cout << "made a node" << endl; | |
printStatus(node); | |
bool success = node.ping(); | |
if (!success) { | |
cout << "Node did not ping correctly!" << endl; | |
exit(1); | |
} | |
node.setToIdle(); | |
cout << "set MipChannel CH_FIELD_SENSOR_RAW_ACCEL_VEC" << endl; | |
mscl::MipChannels ahrsImuChs; | |
ahrsImuChs.push_back(mscl::MipChannel( | |
mscl::MipTypes::CH_FIELD_SENSOR_RAW_ACCEL_VEC, | |
mscl::SampleRate::Hertz(50))); | |
cout << "setActiveChannelFields" << endl; | |
node.setActiveChannelFields(mscl::MipTypes::CLASS_AHRS_IMU, ahrsImuChs); | |
printStatus(node); | |
cout << "enable data stream" << endl; | |
node.enableDataStream(mscl::MipTypes::CLASS_AHRS_IMU); | |
printStatus(node); | |
cout << "resume node" << endl; | |
node.resume(); | |
printStatus(node); | |
cout << "start inifinite loop" << endl; | |
while(true) | |
{ | |
mscl::MipDataPackets packets = node.getDataPackets(500); | |
cout << "Number of packets received: " << packets.size() << endl; | |
for(mscl::MipDataPacket packet : packets) | |
{ | |
packet.descriptorSet(); //the descriptor set of the packet | |
cout << "get packet data" << endl; | |
mscl::MipDataPoints points = packet.data(); | |
for(mscl::MipDataPoint dataPoint : points) | |
{ | |
dataPoint.channelName(); //the name of the channel for this point | |
dataPoint.storedAs(); //the ValueType that the data is stored as | |
cout << dataPoint.as_float() << endl; //get the value as a float | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment