Collaboration diagram for C# IMU API:
Modules | |
DTO | |
Enumerations | |
Events related with IMU Service | |
Classes | |
class | IMUManager |
Implementation of IIMUManager. Start point for interacting with Deepsy IMU service More... | |
interface | IIMUManager |
Interaface for managing IMU device More... | |
Detailed Description
To work with Deepsy IMU Manager service it is necessary to use IMUManager located in GMV.ITS.HAL.DEEPSY.IMU.Facade for getting the initial IMUManager object.
IIMUManager imuManager = new IMUManager("");
IMUManager has an optional parameter indicating the ip address of remote service. For instance:
IIMUManager imuManager = new IMUManager("192.168.0.145");
IMUManager implements IDisposable. It can hold resources (such as socket handles) until it is disposed. The Dispose method is automatically called when existing a using or try / catch block, for which the object has been declared. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur.
- IIMUManager imuManager = null;try{imuManager = new IMUManager("192.168.0.145");IIMUBaseConfiguration imuConfig = imuManager.GetConfiguration(IMUProperties.Property.ENABLE_ACCELEROMETER);} catch (Exception e) {throw e;}imuManager.Dispose();
Examples
-
Get IMU Configuration Parameter
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace GMV.ITS.HAL.DEEPSY.Examples.IMU{public class IMUGetConfiguration{static void Main(string[] args){try{string deepsyServerIp = args.Length == 0 ? "192.168.0.145" : args[0];using (IIMUManager imuManager = new IMUManager(deepsyServerIp)){IIMUBaseConfiguration imuConfig = imuManager.GetConfiguration(IMUProperties.Property.ENABLE_ACCELEROMETER);Console.WriteLine("Parameter: " + imuConfig.propertyID.ToString() + "\tValue: " + imuConfig.value.ToString());imuConfig = imuManager.GetConfiguration(IMUProperties.Property.POLLING_RATE_ACCELEROMETER);Console.WriteLine("Parameter: " + imuConfig.propertyID.ToString() + "\tValue: " + imuConfig.value.ToString());imuConfig = imuManager.GetConfiguration(IMUProperties.Property.RANGE_ACCELEROMETER);Console.WriteLine("Parameter: " + imuConfig.propertyID.ToString() + "\tValue: " + imuConfig.value.ToString());}}catch (HalException deepsyEx){Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");}catch (Exception ex){Console.WriteLine($"Error Not Handled exception {ex.Message}");}}}}
-
Get Inertial Value
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace GMV.ITS.HAL.DEEPSY.Examples.IMU{public class IMUGetInertialValue{static void Main(string[] args){try{string deepsyServerIp = args.Length == 0 ? "192.168.0.145" : args[0];using (IIMUManager imuManager = new IMUManager(deepsyServerIp)){//AccelerometerIIMUInertialData imuInfo = imuManager.GetInertialValue(IMUDevices.Device.ACCELEROMETER);Console.WriteLine("\n\nTimestamp: " + imuInfo.timestamp + " (YYYYMMDD T HHMMSS.SSSSSS) "+ "\nDevice: " + imuInfo.device.ToString()+ "\nX: " + imuInfo.X.ToString()+ "\nY: " + imuInfo.Y.ToString()+ "\nZ: " + imuInfo.Z.ToString()+ "\nStatus: " + imuInfo.status.ToString());//GyroscopeimuInfo = imuManager.GetInertialValue(IMUDevices.Device.GYROSCOPE);Console.WriteLine("\n\nTimestamp: " + imuInfo.timestamp + " (YYYYMMDD T HHMMSS.SSSSSS) "+ "\nDevice: " + imuInfo.device.ToString()+ "\nX: " + imuInfo.X.ToString()+ "\nY: " + imuInfo.Y.ToString()+ "\nZ: " + imuInfo.Z.ToString()+ "\nStatus: " + imuInfo.status.ToString());//MagnetometerimuInfo = imuManager.GetInertialValue(IMUDevices.Device.MAGNETOMETER);Console.WriteLine("\n\nTimestamp: " + imuInfo.timestamp + " (YYYYMMDD T HHMMSS.SSSSSS) "+ "\nDevice: " + imuInfo.device.ToString()+ "\nX: " + imuInfo.X.ToString()+ "\nY: " + imuInfo.Y.ToString()+ "\nZ: " + imuInfo.Z.ToString()+ "\nStatus: " + imuInfo.status.ToString());}}catch (HalException deepsyEx){Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");}catch (Exception ex){Console.WriteLine($"Error Not Handled exception {ex.Message}");}}}}
-
Set IMU Configuration Parameter
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace GMV.ITS.HAL.DEEPSY.Examples.IMU{public class IMUSetConfiguration{static void Main(string[] args){try{string deepsyServerIp = args.Length == 0 ? "192.168.0.145" : args[0];using (IIMUManager imuManager = new IMUManager(deepsyServerIp)){//Get/Set Enable Accelerometer propertyConsole.WriteLine("\nENABLE ACCELEROMETER");IIMUBaseConfiguration imuConfig = imuManager.GetConfiguration(IMUProperties.Property.ENABLE_ACCELEROMETER);Console.WriteLine("Parameter: " + imuConfig.propertyID.ToString() + "\tValue: " + imuConfig.value.ToString());imuManager.SetConfiguration(new IMUEnableAccelerometer(IMUEnableAccelerometer.DeviceStatus.OFF));imuConfig = imuManager.GetConfiguration(IMUProperties.Property.ENABLE_ACCELEROMETER);Console.WriteLine("Parameter: " + imuConfig.propertyID.ToString() + "\tValue: " + imuConfig.value.ToString());imuManager.SetConfiguration(new IMUEnableAccelerometer(IMUEnableAccelerometer.DeviceStatus.ON));imuConfig = imuManager.GetConfiguration(IMUProperties.Property.ENABLE_ACCELEROMETER);Console.WriteLine("Parameter: " + imuConfig.propertyID.ToString() + "\tValue: " + imuConfig.value.ToString());//Get/Set Accelerometer Polling Rate propertyConsole.WriteLine("\nACCELEROMETER POLLING RATE");imuConfig = imuManager.GetConfiguration(IMUProperties.Property.POLLING_RATE_ACCELEROMETER);Console.WriteLine("Parameter: " + imuConfig.propertyID.ToString() + "\tValue: " + imuConfig.value.ToString());imuManager.SetConfiguration(new IMUPollingRateAccelerometer(1));imuConfig = imuManager.GetConfiguration(IMUProperties.Property.POLLING_RATE_ACCELEROMETER);Console.WriteLine("Parameter: " + imuConfig.propertyID.ToString() + "\tValue: " + imuConfig.value.ToString());imuManager.SetConfiguration(new IMUPollingRateAccelerometer(200));imuConfig = imuManager.GetConfiguration(IMUProperties.Property.POLLING_RATE_ACCELEROMETER);Console.WriteLine("Parameter: " + imuConfig.propertyID.ToString() + "\tValue: " + imuConfig.value.ToString());//Get/Set Accelerometer Range propertyConsole.WriteLine("\nACCELEROMETER RANGE");imuConfig = imuManager.GetConfiguration(IMUProperties.Property.RANGE_ACCELEROMETER);Console.WriteLine("Parameter: " + imuConfig.propertyID.ToString() + "\tValue: " + imuConfig.value.ToString());imuManager.SetConfiguration(new IMURangeDevice(IMURangeDevice.RangeAccelerometer.RANGE_4));imuConfig = imuManager.GetConfiguration(IMUProperties.Property.RANGE_ACCELEROMETER);Console.WriteLine("Parameter: " + imuConfig.propertyID.ToString() + "\tValue: " + imuConfig.value.ToString());imuManager.SetConfiguration(new IMURangeDevice(IMURangeDevice.RangeAccelerometer.RANGE_2));imuConfig = imuManager.GetConfiguration(IMUProperties.Property.RANGE_ACCELEROMETER);Console.WriteLine("Parameter: " + imuConfig.propertyID.ToString() + "\tValue: " + imuConfig.value.ToString());}}catch (HalException deepsyEx){Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");}catch (Exception ex){Console.WriteLine($"Error Not Handled exception {ex.Message}");}}}}
-
Subscribe Inertial Data Events
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace GMV.ITS.HAL.DEEPSY.Examples.IMU{public class IMUSubscribeInertialDataEvents{static void Main(string[] args){try{string deepsyServerIp = args.Length == 0 ? "192.168.0.145" : args[0];using (IIMUManager imuManager = new IMUManager(deepsyServerIp)){imuManager.InfoEvent += InertialDataEvent;Console.WriteLine("Press any key for exit");Console.ReadKey();}}catch (HalException deepsyEx){Console.WriteLine($"Deepsy error : {deepsyEx.ErrorCode}");}catch (Exception ex){Console.WriteLine($"Error Not Handled exception {ex.Message}");}}private static void InertialDataEvent(object sender, IIMUInertialDataEvent e){Console.WriteLine("\n\nTimestamp: " + e.InertialData.timestamp + " (YYYYMMDD T HHMMSS.SSSSSS) "+ "\nDevice: " + e.InertialData.device.ToString()+ "\nX: " + e.InertialData.X.ToString()+ "\nY: " + e.InertialData.Y.ToString()+ "\nZ: " + e.InertialData.Z.ToString()+ "\nStatus: " + e.InertialData.status.ToString());}}}