NavX MXP Port Issue

I’m attempting to use the NavX gyroscope, and I’m getting an error I didn’t get last year.

I’m not sure if this is related to the port on the roboRIO or the NavX itself, but here’s the error:

ERROR  -1073807253  HAL - VISA: Framing Error  Read [SerialPort.cpp:134]
	at frc::SerialPort::Read(char*, int)
	at SerialIO::Run()
	at AHRS::ThreadFunc(IIOProvider*)
	at int std::_Bind_simple<int (*(IIOProvider*))(IIOProvider*)>::_M_invoke<0u>(std::_Index_tuple<0u>)
	at std::_Bind_simple<int (*(IIOProvider*))(IIOProvider*)>::operator()()
	at std::thread::_Impl<std::_Bind_simple<int (*(IIOProvider*))(IIOProvider*)> >::_M_run()
	at /usr/lib/libstdc++.so.6(+0x9a39c) [0xb6a5e39c]

Error at Read [SerialPort.cpp:134]: HAL - VISA: Framing Error
	at frc::SerialPort::Read(char*, int)
	at SerialIO::Run()
	at AHRS::ThreadFunc(IIOProvider*)
	at int std::_Bind_simple<int (*(IIOProvider*))(IIOProvider*)>::_M_invoke<0u>(std::_Index_tuple<0u>)
	at std::_Bind_simple<int (*(IIOProvider*))(IIOProvider*)>::operator()()
	at std::thread::_Impl<std::_Bind_simple<int (*(IIOProvider*))(IIOProvider*)> >::_M_run()
	at /usr/lib/libstdc++.so.6(+0x9a39c) [0xb6a5e39c]

Any thoughts?

Use SPI - or I2C. They are much faster than using the TTL UART.

That worked! By initializing the gyro like this

Gyro.reset(new AHRS(SPI::kMXP));

instead of this

Gyro.reset(new AHRS(SerialPort::kMXP));

the error was eliminated.

do you think that is a good way to instantiate an object ?

This is a really good question. It’s important that the AHRS class only ever be instantiated once in a robot application.

For that reason, the standard usage model is to instantiate the AHRS class and store the returned reference into a variable that is then accessed later in the robot application.