Example of gathering IMU data from SeekurSample program that demonstrates how to get IMU data from an IMU on
a Seekur-class robot (from SeekurOS). Only some Seekurs have IMUs.
[Some Pioneers also have gyros that are integrated into the robot and normally automatically correct data or which can optionally return the data seperately (using different packets and different ARIA interface in ArAnalogGyro).]
The data comes back in a custom packet with ID 0x9A. It's requested with client command 26.
Press escape to exit the program.
#include "Aria.h"
#include <time.h>
if (packet->
getID() != 0x9a) {
return false;
}
ArLog::log(
ArLog::Normal,
"got IMUpac, %dms since readings took place, %d readings per axis", timeSince, numPerAxis);
int i;
int range;
double x = 0.0;
double y = 0.0;
double z = 0.0;
double multiplier = 0.0;
double offset = 0.0;
for (i=1; i <= numPerAxis; i++) {
x = 0.0;
y = 0.0;
z = 0.0;
if (range == 3) {
multiplier = 0.07326;
offset = 0.0;
}
else if (range == 2) {
multiplier = 0.03663;
offset = 0.0;
}
else if (range == 1) {
multiplier = 0.01832;
offset = 0.0;
}
if (numGyroAxes >= 1) {
}
if (numGyroAxes >= 2) {
}
if (numGyroAxes >= 3) {
}
i, numPerAxis, x, y, z);
}
for (i=1; i <= numPerAxis; i++) {
x = 0.0;
y = 0.0;
z = 0.0;
multiplier = 0.002522 * 9806.65;
offset = 0.0;
if (numAccelAxes >= 1) {
}
if (numAccelAxes >= 2) {
}
if (numAccelAxes >= 3) {
}
i, numPerAxis, x, y, z);
}
int numTemperatureAxes = packet->
bufToByte();
for (i=1; i <= numPerAxis; i++) {
x = 0.0;
y = 0.0;
z = 0.0;
multiplier = 0.1453;
offset = 25.0;
if (numTemperatureAxes >= 1) {
}
if (numTemperatureAxes >= 2) {
}
if (numTemperatureAxes >= 3) {
}
i, numPerAxis, x, y, z);
}
return true;
}
int main(int argc, char **argv) {
parser.loadDefaultArguments();
if (!simpleConnector.parseArgs() || !parser.checkHelpAndWarnUnparsed(1)) {
simpleConnector.logOptions();
}
if (!simpleConnector.connectRobot(robot)) {
}
exit(0);
}
static void shutdown()
Shutdown all Aria processes/threads.
Definition: Aria.cpp:332
Perform actions when keyboard keys are pressed.
Definition: ArKeyHandler.h:65
Use terse logging.
Definition: ArLog.h:61
ArTypes::UByte getID(void)
returns the ID of the packet
Definition: ArRobotPacket.cpp:81
Legacy connector for robot and laser.
Definition: ArSimpleConnector.h:51
bool comInt(unsigned char command, short int argument)
Sends a command to the robot with an int for argument.
Definition: ArRobot.cpp:5634
void addPacketHandler(ArRetFunctor1< bool, ArRobotPacket * > *functor, ArListPos::Pos position=ArListPos::LAST)
Adds a packet handler to the list of packet handlers.
Definition: ArRobot.cpp:2613
static void setKeyHandler(ArKeyHandler *keyHandler)
Sets the key handler, so that other classes can find it using getKeyHandler()
Definition: Aria.cpp:624
static void exit(int exitCode=0)
Shutdown all Aria processes/threads, call exit callbacks, and exit the program.
Definition: Aria.cpp:367
static void log(LogLevel level, const char *str,...)
Log a message, with formatting and variable number of arguments.
Definition: ArLog.cpp:93
virtual ArTypes::Byte2 bufToByte2(void)
Gets a ArTypes::Byte2 from the buffer.
Definition: ArBasePacket.cpp:456
static void init(SigHandleMethod method=SIGHANDLE_THREAD, bool initSockets=true, bool sigHandleExitNotShutdown=true)
Initialize Aria global data struture and perform OS-specific initialization, including adding OS sign...
Definition: Aria.cpp:128
Use stdout for logging.
Definition: ArLog.h:54
Central class for communicating with and operating the robot.
Definition: ArRobot.h:82
virtual ArTypes::Byte bufToByte(void)
Gets a ArTypes::Byte from the buffer.
Definition: ArBasePacket.cpp:443
Parse and store program command-line arguments for use by other ARIA classes.
Definition: ArArgumentParser.h:64
static bool init(LogType type, LogLevel level, const char *fileName="", bool logTime=false, bool alsoPrint=false, bool printThisCall=true)
Initialize the logging utility with options.
Definition: ArLog.cpp:437
void runAsync(bool stopRunIfNotConnected, bool runNonThreadedPacketReader=false)
Starts the instance to do processing in its own new thread.
Definition: ArRobot.cpp:301
int unlock()
Unlock the robot instance.
Definition: ArRobot.h:1272
static void sleep(unsigned int ms)
Sleep for the given number of milliseconds.
Definition: ariaUtil.cpp:151
Use normal logging.
Definition: ArLog.h:62
place item first in the list
Definition: ariaTypedefs.h:70
int lock()
Lock the robot instance.
Definition: ArRobot.h:1268
Functor for a global function with 1 parameter and return value.
Definition: ArFunctor.h:1270
void attachKeyHandler(ArKeyHandler *keyHandler, bool exitOnEscape=true, bool useExitNotShutdown=true)
Attachs a key handler.
Definition: ArRobot.cpp:6641
Represents the packets sent to the robot as well as those received from it.
Definition: ArRobotPacket.h:41
void restore(void)
Sets stdin back to its original settings, if its been restored it won't read anymore.
Definition: ArKeyHandler.cpp:117
WaitState waitForRunExit(unsigned int msecs=0)
Suspend calling thread until the ArRobot run loop has exited.
Definition: ArRobot.cpp:2923