34 printf(
"[Simulation] Setup LCM...\n");
37 printf(
"[ERROR] Failed to set up LCM\n");
38 throw std::runtime_error(
"lcm bad");
42 VpeBasicControlRegister vpeReg;
43 ImuFilteringConfigurationRegister filtReg;
45 const uint32_t SENSOR_BAUDRATE = 115200;
47 char strConversions[50];
48 uint32_t newHz, oldHz;
51 printf(
"[rt_vectornav] init_vectornav()\n");
54 VnSensor_initialize(&(
vn.
vs));
57 if ((error = VnSensor_connect(&(
vn.
vs), SENSOR_PORT, SENSOR_BAUDRATE)) !=
59 printf(
"[rt_vectornav] VnSensor_connect failed.\n");
65 if ((error = VnSensor_readModelNumber(&(
vn.
vs), modelNumber,
66 sizeof(modelNumber))) != E_NONE) {
67 printf(
"[rt_vectornav] VnSensor_readModelNumber failed.\n");
71 printf(
"Model Number: %s\n", modelNumber);
74 if ((error = VnSensor_readAsyncDataOutputFrequency(&(
vn.
vs), &oldHz)) !=
76 printf(
"[rt_vectornav] VnSensor_readAsyncDataOutputFrequency failed.\n");
83 if ((error = VnSensor_writeAsyncDataOutputFrequency(&(
vn.
vs), 0,
true)) !=
85 printf(
"[rt_vectornav] VnSensor_wrtieAsyncDataOutputFrequency failed.\n");
89 if ((error = VnSensor_readAsyncDataOutputFrequency(&(
vn.
vs), &newHz)) !=
91 printf(
"[rt_vectornav] VnSensor_readAsyncDataOutputFrequency failed.\n");
95 printf(
"[rt_vectornav] Changed frequency from %d to %d Hz.\n", oldHz, newHz);
98 if ((error = VnSensor_readVpeBasicControl(&(
vn.
vs), &vpeReg)) != E_NONE) {
99 printf(
"[rt_vectornav] VnSensor_ReadVpeBasicControl failed.\n");
103 strFromHeadingMode(strConversions, (VnHeadingMode)vpeReg.headingMode);
104 printf(
"[rt_vectornav] Sensor was in mode: %s\n", strConversions);
105 vpeReg.headingMode = VNHEADINGMODE_RELATIVE;
106 if ((error = VnSensor_writeVpeBasicControl(&(
vn.
vs), vpeReg,
true)) !=
108 printf(
"[rt_vectornav] VnSensor_writeVpeBasicControl failed.\n");
112 if ((error = VnSensor_readVpeBasicControl(&(
vn.
vs), &vpeReg)) != E_NONE) {
114 printf(
"[rt_vectornav] VnSensor_ReadVpeBasicControl failed.\n");
117 strFromHeadingMode(strConversions, (VnHeadingMode)vpeReg.headingMode);
118 printf(
"[rt_vectornav] Sensor now id mode: %s\n", strConversions);
120 if ((error = VnSensor_readImuFilteringConfiguration(&(
vn.
vs), &filtReg)) !=
122 printf(
"[rt_vectornav] VnSensor_readGyroCompensation failed.\n");
124 printf(
"[rt_vectornav] AccelWindow: %d\n", filtReg.accelWindowSize);
135 BinaryOutputRegister_initialize(
136 &(
vn.
bor), ASYNCMODE_PORT2,
138 (CommonGroup)(COMMONGROUP_QUATERNION | COMMONGROUP_ANGULARRATE |
140 TIMEGROUP_NONE, IMUGROUP_NONE, GPSGROUP_NONE, ATTITUDEGROUP_NONE,
141 INSGROUP_NONE, GPSGROUP_NONE);
143 if ((error = VnSensor_writeBinaryOutput1(&(
vn.
vs), &(
vn.
bor),
true)) !=
145 printf(
"[rt_vectornav] VnSensor_writeBinaryOutput1 failed.\n");
153 printf(
"[rt_vectornav] IMU is set up!\n");
int processErrorReceived(const std::string &errorMessage, VnError errorCode)
#define K_MINI_CHEETAH_VECTOR_NAV_SERIAL
static VectorNavData * g_vn_data
std::string getLcmUrl(s64 ttl)
void vectornav_handler(void *userData, VnUartPacket *packet, size_t running_index)
static lcm::LCM * vectornav_lcm