Skip to content
Snippets Groups Projects
Commit 42457fca authored by shong7's avatar shong7
Browse files

class18: template updated

parent cad66142
No related branches found
No related tags found
No related merge requests found
#define _GNU_SOURCE
#include <time.h>
double seconds_now(void) {
struct timespec now;
if (clock_gettime(CLOCK_MONOTONIC, &now)) {
fprintf(stderr, "Retrieving system time failed.\n");
exit(1);
}
return now.tv_sec + now.tv_nsec / 1000000000.0;
}
void on_l2g(const lcm_recv_buf_t *rbuf, const char *channel,
const l2g_t *msg, void *userdata) {
printf("l2g: %.2f %.2f %.2f\n", , , );
}
int main(void) {
lcm_t *lcm = lcm_create(NULL);
l2g_t_subscription_t *l2g_sub = l2g_t_subscribe(lcm, , , NULL);
l2g_t l2g = {
.utime = 0,
.l2g = {1.0, 2.0, 3.0}};
l2g_t_publish(lcm, , );
double start = seconds_now();
while (seconds_now() - start < 0.5) {
lcm_handle_timeout(lcm, 100);
}
l2g_t_unsubscribe( , );
lcm_destroy(lcm);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment