I want to implement an emitter robot and a receiver robot in webots. I have written following code.
#include <webots/robot.h>
#include <webots/receiver.h>
#include <stdio.h>
#include <math.h>
#define TIME_STEP 64
int main(int argc, char **argv) {
/* necessary to initialize webots stuff */
wb_robot_init();
WbDeviceTag rx = wb_robot_get_device("receiver");
wb_receiver_enable(rx, 64);
printf("Receiver sampling period: %d",wb_receiver_get_sampling_period(rx));
while (wb_robot_step(TIME_STEP) != -1) {
if (wb_receiver_get_queue_length(rx) > 0) {
const char *message = wb_receiver_get_data(rx);
const double *dir = wb_receiver_get_emitter_direction(rx);
double signal = wb_receiver_get_signal_strength(rx);
printf("received: %s (signal=%g, dir=[%g %g %g])\n",
message, signal, dir[0], dir[1], dir[2]);
wb_receiver_next_packet(rx);
}
};
/* Enter your cleanup code here */
/* This is necessary to cleanup webots resources */
wb_robot_cleanup();
return 0;
}
It compiles successfully. But when I execute it, it generate following result,
Error: wb_receiver_enable(): invalid device tag. Error: wb_receiver_get_sampling_period(): invalid device tag.
How can I fix this error?
I want to receive the message emitted by emitter