Example setup program for the 3DM-CX5-GNSS/INS, and 3DM-GX5-GNSS/INS using C.
More...
|
static void | log_callback (void *_user, const microstrain_log_level _level, const char *_format, va_list _args) |
| Custom logging callback for MIP SDK message formatting and output. More...
|
|
static void | capture_gyro_bias (mip_interface *_device) |
| Captures and configures device gyro bias. More...
|
|
static void | configure_gnss_message_format (mip_interface *_device) |
| Configures message format for GNSS data streaming. More...
|
|
static void | configure_filter_message_format (mip_interface *_device) |
| Configures message format for filter data streaming. More...
|
|
static void | configure_antenna_offset (mip_interface *_device) |
| Configures the GNSS antenna offset parameters for the device. More...
|
|
static void | initialize_filter (mip_interface *_device) |
| Initializes and resets the navigation filter. More...
|
|
static void | display_gnss_fix_state (const mip_gnss_fix_info_data *_fix_info) |
| Displays the current GNSS fix state when changes occur. More...
|
|
static void | display_filter_state (const mip_filter_mode _filter_state) |
| Displays the current filter state when changes occur. More...
|
|
static mip_timestamp | get_current_timestamp () |
| Gets the current system timestamp in milliseconds. More...
|
|
static bool | mip_interface_user_send_to_device (mip_interface *_device, const uint8_t *_data, size_t _length) |
| Handles sending packets to the device. More...
|
|
static bool | mip_interface_user_recv_from_device (mip_interface *_device, uint8_t *_buffer, size_t _max_length, mip_timeout _wait_time, bool _from_cmd, size_t *_length_out, mip_timestamp *_timestamp_out) |
| Handles receiving packets from the device. More...
|
|
static void | initialize_device (mip_interface *_device, serial_port *_device_port, const uint32_t _baudrate) |
| Initializes and configures a MIP device interface. More...
|
|
static void | terminate (serial_port *_device_port, const char *_message, const bool _successful) |
| Handles graceful program termination and cleanup. More...
|
|
static void | exit_from_command (const mip_interface *_device, const mip_cmd_result _cmd_result, const char *_format,...) |
| Handles graceful program termination and command failure cleanup. More...
|
|
This example shows a basic setup to configure the navigation filter with GNSS velocity and magnetometer as the heading source to stream filter data for the 3DM-CX5-GNSS/INS, and 3DM-GX5-GNSS/INS devices using C. This is not an exhaustive example of all settings for those devices. If this example does not meet your specific setup needs, please consult the MIP SDK API documentation for the proper commands.
License
- Copyright
- Copyright (c) 2025 MicroStrain by HBK Licensed under MIT License
◆ log_callback()
static void log_callback |
( |
void * |
_user, |
|
|
const microstrain_log_level |
_level, |
|
|
const char * |
_format, |
|
|
va_list |
_args |
|
) |
| |
|
static |
Processes and formats log messages from the MIP SDK based on severity level. Routes messages to appropriate output streams - errors and fatal messages go to stderr while other levels go to stdout. Each message is prefixed with its severity level name.
- Parameters
-
_user | Pointer to user data (unused in this implementation) |
_level | Log message severity level from microstrain_log_level enum |
_format | Printf-style format string for the message |
_args | Variable argument list containing message parameters |
◆ capture_gyro_bias()
static void capture_gyro_bias |
( |
mip_interface * |
_device | ) |
|
|
static |
- Parameters
-
_device | Pointer to the initialized MIP device interface |
◆ configure_gnss_message_format()
static void configure_gnss_message_format |
( |
mip_interface * |
_device | ) |
|
|
static |
Sets up GNSS data output by:
- Querying device base rate
- Validating desired sample rate against base rate
- Calculating proper decimation
- Configuring message format with:
- Parameters
-
_device | Pointer to the initialized MIP device interface |
◆ configure_filter_message_format()
static void configure_filter_message_format |
( |
mip_interface * |
_device | ) |
|
|
static |
Sets up filter data output by:
- Querying device base rate
- Validating desired sample rate against base rate
- Calculating proper decimation
- Configuring message format with:
- Filter timestamp
- Filter status
- LLH position
- NED velocity
- Euler angles
- Parameters
-
_device | Pointer to the initialized MIP device interface |
◆ configure_antenna_offset()
static void configure_antenna_offset |
( |
mip_interface * |
_device | ) |
|
|
static |
Sets up the physical antenna offset values relative to the device's reference point. The offset is specified in meters using a 3D vector:
- X: forward/back
- Y: left/right
- Z: up/down
- Parameters
-
_device | Pointer to the initialized MIP device interface |
- Note
- Offset values are specific to physical device setup and may need to be adjusted based on actual antenna placement
◆ initialize_filter()
static void initialize_filter |
( |
mip_interface * |
_device | ) |
|
|
static |
Configures the navigation filter by:
- Setting the magnetometer as the heading source
- Enabling filter auto-initialization
- Resetting the filter to apply new settings
- Parameters
-
_device | Pointer to the initialized MIP device interface |
◆ display_gnss_fix_state()
static void display_gnss_fix_state |
( |
const mip_gnss_fix_info_data * |
_fix_info | ) |
|
|
static |
Outputs readable messages for GNSS fix state transitions:
- 3D fix
- 2D fix
- Time-only fix
- No fix
- Invalid fix Also indicates whether the current fix is valid based on flag checks.
- Parameters
-
_fix_info | Pointer to the GNSS fix information structure containing fix type and validity flags |
◆ display_filter_state()
static void display_filter_state |
( |
const mip_filter_mode |
_filter_state | ) |
|
|
static |
Outputs readable messages for filter state transitions:
- Initialization mode
- Run solution valid mode
- Run solution error mode
- Parameters
-
_filter_state | Current filter mode from the MIP device interface |
◆ get_current_timestamp()
static mip_timestamp get_current_timestamp |
( |
| ) |
|
|
static |
Provides basic timestamping using system time:
- Returns milliseconds since Unix epoch
- Uses timespec_get() with UTC time base
- Returns 0 if time cannot be obtained
- Note
- Update this function to use a different time source if needed for your specific application requirements
- Returns
- Current system time in milliseconds since epoch
◆ mip_interface_user_send_to_device()
static bool mip_interface_user_send_to_device |
( |
mip_interface * |
_device, |
|
|
const uint8_t * |
_data, |
|
|
size_t |
_length |
|
) |
| |
|
static |
Implements the MIP device interface send callback:
- Extracts serial port from device user pointer
- Validates connection state
- Writes data buffer to serial port
- Parameters
-
_device | MIP device interface containing the connection |
_data | Buffer containing packet data to send |
_length | Number of bytes to send |
- Returns
- True if send was successful, false otherwise
◆ mip_interface_user_recv_from_device()
static bool mip_interface_user_recv_from_device |
( |
mip_interface * |
_device, |
|
|
uint8_t * |
_buffer, |
|
|
size_t |
_max_length, |
|
|
mip_timeout |
_wait_time, |
|
|
bool |
_from_cmd, |
|
|
size_t * |
_length_out, |
|
|
mip_timestamp * |
_timestamp_out |
|
) |
| |
|
static |
Implements the MIP device interface receive callback:
- Extracts serial port from device user pointer
- Validates connection state
- Reads available data into provided buffer
- Timestamps the received data
- Parameters
-
_device | MIP device interface containing the connection |
_buffer | Buffer to store received data |
_max_length | Maximum number of bytes to read |
_wait_time | How long to wait for data in milliseconds |
_from_cmd | Whether this read is from a command response (unused) |
_length_out | Number of bytes actually read |
_timestamp_out | Timestamp when data was received |
- Returns
- True if receive was successful, false otherwise
◆ initialize_device()
static void initialize_device |
( |
mip_interface * |
_device, |
|
|
serial_port * |
_device_port, |
|
|
const uint32_t |
_baudrate |
|
) |
| |
|
static |
Performs a complete device initialization sequence:
- Sets up a MIP device interface with specified timeouts and callbacks
- Verifies device communication with a ping command
- Sets the device to idle mode to ensure reliable configuration
- Queries and displays detailed device information
- Loads default device settings for a known state
- Parameters
-
_device | Pointer to a MIP device interface to initialize |
_device_port | Pointer to an initialized serial port for device communication |
_baudrate | Serial communication baudrate for the device |
◆ terminate()
static void terminate |
( |
serial_port * |
_device_port, |
|
|
const char * |
_message, |
|
|
const bool |
_successful |
|
) |
| |
|
static |
Handles graceful shutdown when errors occur:
- Outputs provided error message
- Closes device connection if open
- Exits with appropriate status code
- Parameters
-
_device_port | Serial port connection to close |
_message | Error message to display |
_successful | Whether termination is due to success or failure |
◆ exit_from_command()
static void exit_from_command |
( |
const mip_interface * |
_device, |
|
|
const mip_cmd_result |
_cmd_result, |
|
|
const char * |
_format, |
|
|
|
... |
|
) |
| |
|
static |
Handles command failure scenarios:
- Formats and displays an error message with command result
- Closes device connection
- Exits with failure status
- Parameters
-
_device | MIP device interface for the command that failed |
_cmd_result | Result code from a failed command |
_format | Printf-style format string for error message |
... | Variable arguments for format string |
◆ PORT_NAME
const char* PORT_NAME = "/dev/ttyACM0" |
|
static |
◆ BAUDRATE
const uint32_t BAUDRATE = 115200 |
|
static |
- Note
- For native serial connections this needs to be 115200 due to the device default settings command Use mip_3dm_*_uart_baudrate() to write and save the baudrate on the device
◆ SAMPLE_RATE_HZ
const uint16_t SAMPLE_RATE_HZ = 1 |
|
static |
◆ RUN_TIME_SECONDS
const uint32_t RUN_TIME_SECONDS = 30 |
|
static |