Hello there;
When i use the function which is defined in drv_hrt.c called hrt_absolute_time(), It always returning 0 value.
here is my use of it:
hrt_abstime clock = hrt_absolute_time();
PX4_INFO(“Time is : %10.6f”,clock);
Here is the code of the function:
/*
* Get absolute time.
*/
hrt_abstime hrt_absolute_time(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts_to_abstime(&ts);
}
Here is my full code :
int myserial_thread_main(int argc, char *argv[]){
char str[100]={0};
char c;
hrt_abstime clock;
//UART open
hrt_init();
int uart = uart_initt("/dev/ttyS6");
if(false == uart)return -1;
if(false == set_uart_baudratee(uart,9600)){
printf("[YCM]set_uart_baudrate is failed\n");
return -1;
}
int sensor_sub_fd = orb_subscribe(ORB_ID(sensor_combined));
px4_pollfd_struct_t fds[] = {
{ .fd = sensor_sub_fd, .events = POLLIN },
};
while(1){
/* start measuring */
clock=hrt_absolute_time();
int poll_ret = px4_poll(fds, 1,1000);
if(poll_ret > 0){
if (fds[0].revents & POLLIN) {
/* obtained data for the first file descriptor */
struct sensor_combined_s raw;
/* copy sensors raw data into local buffer */
orb_copy(ORB_ID(sensor_combined), sensor_sub_fd, &raw);
sprintf(str,"S %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f E\r\n",(double)raw.accelerometer_m_s2[0],
(double)raw.accelerometer_m_s2[1],
(double)raw.accelerometer_m_s2[2],
(double)raw.gyro_rad[0],
(double)raw.gyro_rad[1],
(double)raw.gyro_rad[2]);
for(int j=0;j<sizeof(str);j++){
c = str[j];
write(uart, &c, 1);
}
PX4_INFO("Time is: %10.6f",clock);
}
}
}
}
and the resulst is :
Do I forgot something ?