コード例 #1
0
ファイル: CIMUXSens_MT4.cpp プロジェクト: astoeckel/mrpt
/*-------------------------------------------------------------
					initialize
-------------------------------------------------------------*/
void CIMUXSens_MT4::initialize()
{
#if MRPT_HAS_xSENS_MT4
	m_state = ssInitializing;

	try
	{
		// Try to open a specified device, or scan the bus?
		XsPortInfoArray portInfoArray;

		if (m_portname.empty())
		{
			if (m_verbose) cout << "[CIMUXSens_MT4] Scanning for USB devices...\n";
			xsEnumerateUsbDevices(portInfoArray);

			if (portInfoArray.empty())
				THROW_EXCEPTION("CIMUXSens_MT4: No 'portname' was specified and no XSens device was found after scanning the system!")

			if (m_verbose) cout << "[CIMUXSens_MT4] Found " <<  portInfoArray.size() <<" devices. Opening the first one.\n";
		}
		else
		{
			XsPortInfo portInfo(m_portname, XsBaud::numericToRate(m_port_bauds));
			if (m_verbose) cout << "[CIMUXSens_MT4] Using user-supplied portname '"<<m_portname<<"' at "<<m_port_bauds<<" baudrate.\n";
			portInfoArray.push_back(portInfo);
		}

		// Use the first detected device
		XsPortInfo mtPort = portInfoArray.at(0);

		// Open the port with the detected device
		cout << "[CIMUXSens_MT4] Opening port " << mtPort.portName().toStdString() << std::endl;

		if (!my_xsens_device.openPort(mtPort))
			throw std::runtime_error("Could not open port. Aborting.");

		// Put the device in configuration mode
		if (m_verbose) cout << "[CIMUXSens_MT4] Putting device into configuration mode...\n";
		if (!my_xsens_device.gotoConfig()) // Put the device into configuration mode before configuring the device
			throw std::runtime_error("Could not put device into configuration mode. Aborting.");

		// Request the device Id to check the device type
		mtPort.setDeviceId(my_xsens_device.getDeviceId());

		my_xsens_devid = mtPort.deviceId();

		// Check if we have an MTi / MTx / MTmk4 device
		if (!mtPort.deviceId().isMtix() && !mtPort.deviceId().isMtMk4())
		{
			throw std::runtime_error("No MTi / MTx / MTmk4 device found. Aborting.");
		}
		cout << "[CIMUXSens_MT4] Found a device with id: " << mtPort.deviceId().toString().toStdString() << " @ port: " << mtPort.portName().toStdString() << ", baudrate: " << mtPort.baudrate() << std::endl;

		// Print information about detected MTi / MTx / MTmk4 device
		if (m_verbose) cout << "[CIMUXSens_MT4] Device: " << my_xsens_device.getProductCode().toStdString() << " opened." << std::endl;

		// Configure the device. Note the differences between MTix and MTmk4
		if (m_verbose) cout << "[CIMUXSens_MT4] Configuring the device..." << std::endl;
		if (mtPort.deviceId().isMtix())
		{
			XsOutputMode outputMode = XOM_Orientation; // output orientation data
			XsOutputSettings outputSettings = XOS_OrientationMode_Euler | XOS_Timestamp_PacketCounter | XOS_CalibratedMode_All; // XOS_OrientationMode_Quaternion; // output orientation data as quaternion

			// set the device configuration
			if (!my_xsens_device.setDeviceMode(outputMode, outputSettings))
				throw std::runtime_error("Could not configure MT device. Aborting.");
		}
		else if (mtPort.deviceId().isMtMk4())
		{
			XsOutputConfigurationArray configArray;
			configArray.push_back( XsOutputConfiguration(XDI_SampleTime64,m_sampleFreq) );
			configArray.push_back( XsOutputConfiguration(XDI_SampleTimeFine,m_sampleFreq) );
			configArray.push_back( XsOutputConfiguration(XDI_SampleTimeCoarse,m_sampleFreq) );
			configArray.push_back( XsOutputConfiguration(XDI_Quaternion,m_sampleFreq) );
			configArray.push_back( XsOutputConfiguration(XDI_Temperature,m_sampleFreq) );
			configArray.push_back( XsOutputConfiguration(XDI_Acceleration,m_sampleFreq) );
			configArray.push_back( XsOutputConfiguration(XDI_RateOfTurn,m_sampleFreq) );
			configArray.push_back( XsOutputConfiguration(XDI_MagneticField,m_sampleFreq) );
			configArray.push_back( XsOutputConfiguration(XDI_VelocityXYZ,m_sampleFreq) );

			configArray.push_back( XsOutputConfiguration(XDI_StatusByte, m_sampleFreq) );
			configArray.push_back( XsOutputConfiguration(XDI_LatLon, m_sampleFreq) );
			configArray.push_back( XsOutputConfiguration(XDI_UtcTime, m_sampleFreq) );
			configArray.push_back( XsOutputConfiguration(XDI_AltitudeEllipsoid, m_sampleFreq) );

			if (!my_xsens_device.setOutputConfiguration(configArray))
				throw std::runtime_error("Could not configure MTmk4 device. Aborting.");
		}
		else
		{
			throw std::runtime_error("Unknown device while configuring. Aborting.");
		}

		// Put the device in measurement mode
		if (m_verbose) cout << "[CIMUXSens_MT4] Putting device into measurement mode..." << std::endl;
		if (!my_xsens_device.gotoMeasurement())
			throw std::runtime_error("Could not put device into measurement mode. Aborting.");

		m_state = ssWorking;

	}
コード例 #2
0
bool XSensINS::OnStartUp() {
  AppCastingMOOSApp::OnStartUp();

  // XSens Configuration Array
  XsOutputConfigurationArray configArray;

  // MOOS parser
  STRING_LIST sParams;
  m_MissionReader.EnableVerbatimQuoting(false);
  if (!m_MissionReader.GetConfiguration(GetAppName(), sParams))
    reportConfigWarning("No config block found for " + GetAppName());

  STRING_LIST::iterator p;
  sParams.reverse();
  for (p = sParams.begin() ; p != sParams.end() ; p++) {
    string orig  = *p;
    string line  = *p;
    string param = toupper(biteStringX(line, '='));
    string value = line;

    bool handled = false;
    if (param == "UART_BAUD_RATE") {
      m_uart_baud_rate = atoi(value.c_str());
      handled = true;
    }
    else if (param == "SERIAL_PORT") {
      m_uart_port = value;
      handled = true;
    }
    else if (param == "XDI_EULERANGLES"){
      XsOutputConfiguration config(XDI_EulerAngles, atoi(value.c_str()));
      configArray.push_back(config);
      handled = true;
    }
    else if (param == "XDI_ACCELERATION"){
      XsOutputConfiguration config(XDI_Acceleration, atoi(value.c_str()));
      configArray.push_back(config);
      handled = true;
    }
    else if (param == "XDI_RATEOFTURN"){
      XsOutputConfiguration config(XDI_RateOfTurn, atoi(value.c_str()));
      configArray.push_back(config);
      handled = true;
    }
    else if (param == "XDI_MAGNETICFIELD"){
      XsOutputConfiguration config(XDI_MagneticField, atoi(value.c_str()));
      configArray.push_back(config);
      handled = true;
    }
    else if (param == "XDI_LATLON"){
      XsOutputConfiguration config(XDI_LatLon, atoi(value.c_str()));
      configArray.push_back(config);
      handled = true;
    }
    else if (param == "XDI_VELOCITYXYZ"){
      XsOutputConfiguration config(XDI_VelocityXYZ, atoi(value.c_str()));
      configArray.push_back(config);
      handled = true;
    }
    
    if(!handled)
      reportUnhandledConfigWarning(orig);
  }

  registerVariables();

  //------ OPEN INS ---------------//
  XsPortInfo mtPort(m_uart_port, XsBaud::numericToRate(m_uart_baud_rate));
  if (!m_device.openPort(mtPort)) {
    cout << "CANNOT OPEN THE PORT : " << m_uart_port << '\n';
    reportRunWarning("Could not open the COM port" + m_uart_port);
  }

  //------ CONFIGURE INS ---------------//
  // Put the device into configuration mode before configuring the device
  if (!m_device.gotoConfig()) {
    reportRunWarning("Could not begin the config mode");
  }

  // Save INS Config
  if (!m_device.setOutputConfiguration(configArray)) {
    reportRunWarning("Could not save config");
  }

  //------ START INS ---------------//
  if (!m_device.gotoMeasurement()) {
    reportRunWarning("Could not start the INS");
  }

  return true;
}
コード例 #3
0
ファイル: Aris_IMU.cpp プロジェクト: chaixun/Aris
		void IMU::Initiate()
		{
			XsPortInfoArray portInfoArray;
			xsEnumerateUsbDevices(portInfoArray);

			if (!portInfoArray.size())
			{
#ifdef PLATFORM_IS_WINDOWS
				throw std::runtime_error("IMU: failed to find IMU sensor");
#endif
#ifdef PLATFORM_IS_LINUX
				XsPortInfo portInfo(pDevice->port, XsBaud::numericToRate(pDevice->baudRate));
				portInfoArray.push_back(portInfo);
#endif
			}
			
			pDevice->mtPort = portInfoArray.at(0);
			
			// Open the port with the detected device
			if (!pDevice->openPort(pDevice->mtPort))
				throw std::runtime_error("IMU: could not open port.");
			
			Aris::Core::Sleep(10);

			// Put the device in configuration mode
			if (!pDevice->gotoConfig()) // Put the device into configuration mode before configuring the device
			{
				throw std::runtime_error("IMU: could not put device into configuration mode");
			}
			
			// Request the device Id to check the device type
			pDevice->mtPort.setDeviceId(pDevice->getDeviceId());
			
			// Check if we have an MTi / MTx / MTmk4 device
			if (!pDevice->mtPort.deviceId().isMtMk4())
			{
				throw std::runtime_error("IMU: No MTi / MTx / MTmk4 device found.");
			}
			
			// Check device type
			if (pDevice->mtPort.deviceId().isMtMk4())
			{
				XsOutputConfiguration config0(XDI_Quaternion, pDevice->sampleRate);
				XsOutputConfiguration config1(XDI_DeltaQ, pDevice->sampleRate);
				XsOutputConfiguration config2(XDI_DeltaV, pDevice->sampleRate);
				XsOutputConfiguration config3(XDI_Acceleration, pDevice->sampleRate);

				XsOutputConfigurationArray configArray;
				configArray.push_back(config0);
				configArray.push_back(config1);
				configArray.push_back(config2);
				configArray.push_back(config3);
				if (!pDevice->setOutputConfiguration(configArray))
				{
					throw std::runtime_error("IMU: Could not configure MTmk4 pDevice-> Aborting.");
				}
			}
			else
			{
				throw std::runtime_error("IMU: Unknown device while configuring. Aborting.");
			}
			
			// Put the device in measurement mode
			if (!pDevice->gotoMeasurement())
			{
				throw std::runtime_error("IMU: Could not put device into measurement mode. Aborting.");
			}
		}
コード例 #4
0
bool XSensINS::OnStartUp() {
  AppCastingMOOSApp::OnStartUp();

  STRING_LIST sParams;
  m_MissionReader.EnableVerbatimQuoting(false);
  if (!m_MissionReader.GetValue("XSENSINS_SERIAL_PORT",m_uart_port))
    reportConfigWarning("No XSENSINS_SERIAL_PORT config found for " + GetAppName());
  if (!m_MissionReader.GetConfiguration(GetAppName(), sParams))
    reportConfigWarning("No config block found for " + GetAppName());

  STRING_LIST::iterator p;
  sParams.reverse();
  for (p = sParams.begin() ; p != sParams.end() ; p++) {
    string orig  = *p;
    string line  = *p;
    string param = toupper(biteStringX(line, '='));
    string value = line;

    bool handled = false;
    if (param == "m_uart_baud_rate") {
      m_uart_baud_rate = atoi(value.c_str());
      handled = true;
    }
    else if (param == "YAW_DECLINATION") {
      m_yaw_declination = atoi(value.c_str());
      handled = true;
    }
    if(!handled)
      reportUnhandledConfigWarning(orig);
  }
  
  registerVariables();

  //------ OPEN INS ---------------//
  XsPortInfo mtPort("/dev/xsens", XsBaud::numericToRate(115200));
  if (!m_device.openPort(mtPort)) {
    cout << "CANNOT OPEN THE PORT" << '\n';
    reportRunWarning("Could not open the COM port" + m_uart_port);
  }

  //------ CONFIGURE INS ---------------//
  // Put the device into configuration mode before configuring the device
  if (!m_device.gotoConfig()) {
    reportRunWarning("Could not begin the config mode");
  }

  XsOutputConfiguration euler(XDI_EulerAngles, 25);
  XsOutputConfiguration acceleration(XDI_Acceleration, 25);
  XsOutputConfiguration rateOfTurn(XDI_RateOfTurn, 25);
  XsOutputConfiguration magnetic(XDI_MagneticField, 25);
  XsOutputConfiguration latlon(XDI_LatLon, 25);

  XsOutputConfigurationArray configArray;
  configArray.push_back(euler);
  configArray.push_back(acceleration);
  configArray.push_back(rateOfTurn);
  configArray.push_back(magnetic);
  configArray.push_back(latlon);
  // Save INS Config
  if (!m_device.setOutputConfiguration(configArray)) {
    reportRunWarning("Could not save config");
  }

  //------ START INS ---------------//
  if (!m_device.gotoMeasurement()) {
    reportRunWarning("Could not start the INS");
  }

  return true;
}
コード例 #5
0
ファイル: mtiG.cpp プロジェクト: lukscasanova/mtig_driver
/**
 * @brief Creates an XsOutputConfigurationArray and pushes it to the sensor.
 * @details
 * - Configures the sensor with desired modules
 * - Refer to xsdataidentifier.h
 */
void mtiG::configure(){

	XsOutputConfigurationArray configArray;

	if(mSettings.orientationData){			//Quaternion - containsOrientation
			XsOutputConfiguration quat(XDI_Quaternion, mSettings.orientationFreq);// para pedir quaternion
			configArray.push_back(quat);
	}
	
	if(mSettings.gpsData){
			//LATITUDE E LONGITUDE -containsLatitudeLongitude
			XsOutputConfiguration gps(XDI_LatLon, mSettings.gpsFreq);// para pedir gps, //XDI_Quaternion 06/04
			configArray.push_back(gps);

			XsOutputConfiguration gps_age(XDI_GpsAge, mSettings.gpsFreq);// para pedir gps, //XDI_Quaternion 06/04
			configArray.push_back(gps_age);

			XsOutputConfiguration gps_sol(XDI_GpsSol, mSettings.gpsFreq);// para pedir gps, //XDI_Quaternion 06/04
			configArray.push_back(gps_sol);

			XsOutputConfiguration gps_dop(XDI_GpsDop, mSettings.gpsFreq);// para pedir gps, //XDI_Quaternion 06/04
			configArray.push_back(gps_dop);
	}
	
	if(mSettings.temperatureData){	
			//TEMPERATURA - containsTemperature
			XsOutputConfiguration temp(XDI_Temperature, mSettings.temperatureFreq);
			configArray.push_back(temp);
	}	
	
	if(mSettings.accelerationData){
			//ACCELERATION - containsCalibratedAcceleration
			XsOutputConfiguration accel(XDI_Acceleration, mSettings.accelerationFreq);
			configArray.push_back(accel);
	}

	if(mSettings.pressureData){	
			//PRESSURE - containsPressure
			XsOutputConfiguration baro(XDI_BaroPressure, mSettings.pressureFreq);
			configArray.push_back(baro);
	}

	if(mSettings.magneticData){
			//MAGNETIC FIELD - containsCalibratedMagneticField
			XsOutputConfiguration magnet(XDI_MagneticField, mSettings.magneticFreq);
			configArray.push_back(magnet);
	}

	if(mSettings.altitudeData){
			//ALTITUDE - containsAltitude
			XsOutputConfiguration alt(XDI_AltitudeEllipsoid, mSettings.altitudeFreq);
			configArray.push_back(alt);
	}

	if(mSettings.gyroscopeData){
			//GYRO - containsCalibratedGyroscopeData
			XsOutputConfiguration gyro(XDI_RateOfTurn, mSettings.gyroscopeFreq);
			configArray.push_back(gyro);
	}	

	if(mSettings.velocityData){
			//VELOCIDADE XYZ
			XsOutputConfiguration vel_xyz(XDI_VelocityXYZ, mSettings.velocityFreq);
			configArray.push_back(vel_xyz);
	}
	
	// Puts configArray into the device, overwriting the current configuration
	if (!device->setOutputConfiguration(configArray))
	{
			throw std::runtime_error("Could not configure MTmk4 device. Aborting.");
	}
}
コード例 #6
0
ファイル: ofxXsens.cpp プロジェクト: pierrep/ofxXsens
void ofxXsens::connect()
{
    try {
        // Scan for connected devices
        ofLogNotice("ofxXsens") << "Scanning for devices...";
        XsPortInfoArray portInfoArray = XsScanner::scanPorts();

        // Find an MTi / MTx / MTmk4 device
        mtPort = portInfoArray.begin();
        while (mtPort != portInfoArray.end() && !mtPort->deviceId().isMtix() && !mtPort->deviceId().isMtMk4()) {++mtPort;}
        if (mtPort == portInfoArray.end())
        {
            throw std::runtime_error("No MTi / MTx / MTmk4 device found. Aborting.");
        }
        ofLogNotice("ofXsens") << "Found a device with id: " << mtPort->deviceId().toString().toStdString() << " @ port: " << mtPort->portName().toStdString() << ", baudrate: " << mtPort->baudrate();

        // Open the port with the detected device
        ofLogNotice("ofxXsens") << "Opening port..." << std::endl;
        if (!control->openPort(mtPort->portName().toStdString(), mtPort->baudrate()))
        {
            throw std::runtime_error("Could not open port. Aborting.");
        }
		try
		{
			// Get the device object
			XsDevice* device = control->device(mtPort->deviceId());
			assert(device != 0);

			// Print information about detected MTi / MTx / MTmk4 device
			ofLogNotice("ofxXsens") << "Device: " << device->productCode().toStdString() << " opened." << std::endl;

			//Attach callback handler to device
			device->addCallbackHandler(&callback);

			// Put the device in configuration mode
			ofLogNotice("ofxXsens") << "Putting device into configuration mode..." << std::endl;
			if (!device->gotoConfig()) // Put the device into configuration mode before configuring the device
			{
				throw std::runtime_error("Could not put device into configuration mode. Aborting.");
			}

			// Configure the device. Note the differences between MTix and MTmk4
			ofLogNotice("ofxXsens") << "Configuring the device..." << std::endl;
			if (device->deviceId().isMtix())
			{
				ofLogNotice("ofxXsens") << "isMtix..." << std::endl;
				XsOutputMode outputMode = XOM_Orientation; // output orientation data
				XsOutputSettings outputSettings = XOS_OrientationMode_Quaternion; // output orientation data as quaternion
				XsDeviceMode deviceMode(100); // make a device mode with update rate: 100 Hz
				deviceMode.setModeFlag(outputMode);
				deviceMode.setSettingsFlag(outputSettings);

				// set the device configuration
				if (!device->setDeviceMode(deviceMode))
				{
					throw std::runtime_error("Could not configure MTmki device. Aborting.");
				}
				bSensorConnected = true;
			}
			else if (device->deviceId().isMtMk4())
			{
				ofLogNotice("ofxXsens") << "isMtMk4..." << std::endl;
				XsOutputConfiguration quat(XDI_Quaternion, 0);
				//XsOutputConfiguration gpssol(XDI_GpsSol, 0);
				XsOutputConfiguration latlong(XDI_LatLon, 0);
				XsOutputConfigurationArray configArray;
				configArray.push_back(quat);
				//configArray.push_back(gpssol);
				configArray.push_back(latlong);
				if (!device->setOutputConfiguration(configArray))
				{

					throw std::runtime_error("Could not configure MTmk4 device. Aborting.");
				}
				bSensorConnected = true;
			}
			else
			{
				throw std::runtime_error("Unknown device while configuring. Aborting.");
			}

			// Put the device in measurement mode
			std::cout << "Putting device into measurement mode..." << std::endl;
			if (!device->gotoMeasurement())
			{
				throw std::runtime_error("Could not put device into measurement mode. Aborting.");
			}
		}
		catch (std::runtime_error const & error)
		{
			std::cout << error.what() << std::endl;
		}
		catch (...)
		{
			ofLogError("ofxXsens") << "An unknown fatal error has occured. Aborting." << std::endl;
		}
    }
    catch (runtime_error const & error)
    {
        ofLogError("ofxXsens") << error.what();
    }
    catch (...)
    {
        ofLogError("ofxXsens") << "An unknown fatal error has occured.";
    }
}