8#include <yarp/os/Bottle.h>
9#include <yarp/os/Value.h>
20using namespace yarp::os;
78 Value *baudrate, *serial;
80 if(!config.check(
"serial", serial))
82 std::cout <<
"Can't find 'serial' name in config file";
86 comPortName = serial->toString();
90 printf(
"\n\nSerial opening %s\n\n\n", comPortName.c_str());
91 fd_ser =
::open(comPortName.c_str(), O_RDWR | O_NOCTTY );
93 printf(
"can't open %s, %s\n", comPortName.c_str(), strerror(errno));
98 struct termios options;
99 tcgetattr(fd_ser, &options);
102 int baudRate = B115200;
103 cfsetospeed(&options, baudRate);
104 cfsetispeed(&options, baudRate);
107 options.c_cflag &= ~CSIZE;
108 options.c_cflag |= CS8;
111 options.c_cflag &= ~CSTOPB;
114 options.c_cflag &=~PARENB;
117 options.c_iflag = IGNPAR;
122 options.c_cc[VMIN] = 0;
123 options.c_cc[VTIME] = 100;
126 options.c_cflag |= (CLOCAL | CREAD);
128 tcflush(fd_ser,TCIOFLUSH);
131 if ( tcsetattr(fd_ser, TCSANOW, &options) != 0)
133 printf(
"Configuring comport failed\n");
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
152 nbytes = ::write(fd_ser, (
void*)buff, 20);
153 nbytes =
::read(fd_ser, (
void*)reply, 19);
155 memcpy(buff+4, reply+1, 10);
164 nbytes = write(fd_ser, (
void*)buff, 20);
176 printf(
"Closed %s\n", comPortName.c_str());
192 printf(
"Not implemented yet\n");
204 uint64_t imu_timeStamp;
206 get_Euler(tmp_eul, &imu_timeStamp);
207 get_Acc_Ang_Mag(tmp_acc, tmp_gyro, tmp_mag, &imu_timeStamp);
210 for(
int i=0; i<3; i++, out_idx++)
211 out[out_idx] = (
double) tmp_eul[i];
213 for(
int i=0; i<3; i++, out_idx++)
214 out[out_idx] = (
double) tmp_acc[i];
216 for(
int i=0; i<3; i++, out_idx++)
217 out[out_idx] = (
double) tmp_gyro[i];
219 for(
int i=0; i<3; i++, out_idx++)
220 out[out_idx] = (
double) tmp_mag[i];
235bool imu3DM_GX3::threadInit()
240 printf(
"Started imu-3DM-GX3-25 thread\n");
244void imu3DM_GX3::run()
251 cmd_map_t::iterator it = cmd_ptr_map.begin();
252 while(it != cmd_ptr_map.end())
254 tmp_cmd = it->second;
256 nbytes = ::write(fd_ser, (
void*)&tmp_cmd->
cmd,
sizeof(uint8_t));
263 printf(
"Error while reading imu response to command XXX\n");
266 else if ( nbytes != tmp_cmd->
expSize )
268 printf(
"read %d instead of %d\n", nbytes, tmp_cmd->
expSize);
276 if ( ! (
bool)tmp_cmd->
process(th_data) )
278 printf(
"Checksum FAILURE\n");
284 lock_guard<mutex> lck(data_mutex);
291void imu3DM_GX3::threadRelease()
300void imu3DM_GX3::stop_continuous(
void)
304 const uint8_t buff[] = {
309 nbytes =
write(fd_ser, (
void*)buff,
sizeof(buff));
315void imu3DM_GX3::get_Acc_Ang(
float acc[3],
float angRate[3], uint64_t *
time) {
319 lock_guard<mutex> lck(data_mutex);
333 lock_guard<mutex> lck(data_mutex);
346void imu3DM_GX3::get_Acc_Ang_Mag(
float acc[3],
float angRate[3],
float mag[3], uint64_t *
time) {
349 lock_guard<mutex> lck(data_mutex);
366 lock_guard<mutex> lck(data_mutex);
382void imu3DM_GX3::get_Euler(
float euler[3], uint64_t *
time) {
386 lock_guard<mutex> lck(data_mutex);
389 memcpy((
void*)euler, eu->
eul.
_bytes,
sizeof(
float)*3);
394void imu3DM_GX3::get_Euler_AngularRate(
float euler[3],
float angRate[3], uint64_t *
time) {
398 lock_guard<mutex> lck(data_mutex);
401 memcpy((
void*)euler, ea->
eul.
_bytes,
sizeof(
float)*3);
408void imu3DM_GX3::get_Quaternion(
float quat[4], uint64_t *
time) {
412 lock_guard<mutex> lck(data_mutex);
virtual bool calibrate(int ch, double v)
virtual bool getChannels(int *nc)
void sample_setting(void)
virtual yarp::os::Stamp getLastInputStamp()
virtual bool open(yarp::os::Searchable &config)
virtual bool read(yarp::sig::Vector &out)
void * process_CE(data_3DM_GX3_t &data)
void * process_CB(data_3DM_GX3_t &data)
bool write(const std::string filename, const FullRegulation ®)
acc_ang_mag_orient_t aamom