|
3.17 EmitterDerived from Solid.
3.17.1 DescriptionThe Emitter node is used to model radio, serial or infra-red emitters. An Emitter node must be added to the children of a robot or supervisor. Please note that an emitter can send data but cannot receive it; in order to achieve bidirectional communication, a robot needs to have both an Emitter and a Receiver on board. 3.17.2 Field Summary
Note: Emitter nodes can also be used to communicate with the physics plugin (see chapter 6). In this case the channel must be set to 0 (the default). In addition it is highly recommended to choose -1 for the baudRate, in order to enable the fastest possible communication; the type, range and aperture will be ignored. 3.17.3 Emitter FunctionsNAMEwb_emitter_send - send a data packet to potential receiversC SYNOPSIS#include <webots/emitter.h>int wb_emitter_send(WbDeviceTag emitter, const void *data, int size); C++ SYNOPSIS#include <webots/Emitter.hpp>int Emitter::send(const void *data, int size); JAVA SYNOPSISimport com.cyberbotics.webots.controller.Emitter;int Emitter.send(byte[] data); PYTHON SYNOPSISfrom controller import Emitterint Emitter.send(string data, int size) DESCRIPTIONThe wb_emitter_send() function adds to the emitters's queue a packet of size bytes located at the address indicated by data. The enqueued data packets will then be sent to potential receivers (and removed from the emitter's queue) at the rate specified by the baudRate field of the Emitter node. On success this function returns 1. If the queue is currently full, 0 is returned and the packet will not be enqueued. The queue is considered to be full when the sum of bytes of all the enqueued packets exceeds the buffer size specified by the bufferSize field. Note that a packet cannot be smaller than 1 byte. See the following usage example:
Note that the above example sends packets in the form of null-terminated strings. The Emitter/Receiver API does not put any restriction on the type of data that can be transmitted. Any user chosen format is suitable, as long as emitters and receivers agree. Note: The Python send() function sends a string. For sending primitive data types into this string, the Python struct module can be used. This module performs conversions between Python values and C structs represented as Python strings. Here is an example:
NAMEwb_emitter_set_channel, wb_emitter_get_channel - set and get the emitter's channel.C SYNOPSIS#include <webots/emitter.h>void wb_emitter_set_channel(WbDeviceTag emitter, int channel); int wb_emitter_get_channel(WbDeviceTag emitter); C++ SYNOPSIS#include <webots/Emitter.hpp>void Emitter::setChannel(int channel); int Emitter::getChannel(); JAVA SYNOPSISimport com.cyberbotics.webots.controller.Emitter;void Emitter.setChannel(int channel); int Emitter.getChannel(); PYTHON SYNOPSISfrom controller import Emitternone Emitter.setChannel(int channel) int Emitter.getChannel() DESCRIPTIONThe wb_emitter_set_channel() function allows the controller to change the transmission channel. This modifies the channel field of the corresponding Emitter node. Normally, an emitter can send data only to receivers that use the same channel. However, the special WB_CHANNEL_BROADCAST value can be used for broadcasting to all channels. By switching the channel number an emitter can selectively send data to different receivers. The wb_emitter_get_channel() function returns the current channel number of the emitter. Note: In the oriented-object APIs, the WB_CHANNEL_BROADCAST constant is available as static integer of the Emitter class (Emitter::CHANNEL_BROADCAST). NAMEwb_emitter_set_range, wb_emitter_get_range - set and get the emitter's range.C SYNOPSIS#include <webots/emitter.h>void wb_emitter_set_range(WbDeviceTag emitter, double range); double wb_emitter_get_range(WbDeviceTag emitter); C++ SYNOPSIS#include <webots/Emitter.hpp>void Emitter::setRange(double range); double Emitter::getRange(); JAVA SYNOPSISimport com.cyberbotics.webots.controller.Emitter;void Emitter.setRange(double range); double Emitter.getRange(); PYTHON SYNOPSISfrom controller import Emitternone Emitter.setRange(float range) float Emitter.getRange() DESCRIPTIONThe wb_emitter_set_range() function allows the controller to change the transmission range at run-time. Data packets can only reach receivers located within the emitter's range. This function modifies the range field of the corresponding Emitter node. If the specified range argument is larger than the maxRange field of the Emitter node then the current range will be set to maxRange. The wb_emitter_get_range() function returns the current emitter's range. For both the wb_emitter_set_range() and emitter_get_range() functions, a value of -1 indicates an infinite range. NAMEwb_emitter_get_buffer_size - get the transmission buffer sizeC SYNOPSIS#include <webots/emitter.h>int wb_emitter_get_buffer_size(WbDeviceTag emitter); C++ SYNOPSIS#include <webots/Emitter.hpp>int Emitter::getBufferSize(); JAVA SYNOPSISimport com.cyberbotics.webots.controller.Emitter;int Emitter.getBufferSize(); PYTHON SYNOPSISfrom controller import Emitterint Emitter.getBufferSize() DESCRIPTIONThe wb_emitter_get_buffer_size() function returns the size (in bytes) of the transmission buffer. This corresponds to the value specified by the bufferSize field of the Emitter node. The buffer size indicates the maximum number of data bytes that the emitter's queue can hold in total. When the buffer is full, calls to wb_emitter_send_packet() will fail and return 0. ![]() ^ page top ^ |
| E-mail to webmaster | Last updated: | Copyright © 2008 Cyberbotics Ltd. |