range_and_bearing
Posted: Mon May 20, 2019 5:06 pm
by badri86
I can't send 2 deffrent messages with range_and_bearing sensor:
CVector2 targetPosition; and bool isTarget;
My code:
m_pcRABA = GetActuator<CCI_RangeAndBearingActuator >("range_and_bearing" );
m_pcRABS = GetSensor <CCI_RangeAndBearingSensor >("range_and_bearing" );
m_pcRABA->SetData(0, isTarget);
float x = targetPosition.GetX();
float y = targetPosition.GetY();
m_pcRABA->SetData(1, x);
m_pcRABA->SetData(2, y);
Re: range_and_bearing
Posted: Wed Jun 05, 2019 4:31 am
by pincy
You need to correctly serialize the data. If it's float that you want to send, you need to consider that (by default) the range and bearing of the foot-bot only allows you to send 10 bytes per time step. You can change this in the XML file with the attribute <foot-bot rab_data_size="the size you want">.
As for the actual code, you need something like this. First, notice that you must always send exactly 10 bytes (or whatever size you set in the XML). Next, use this code:
Code: Select all
SIZE = 10; // or whatever you set in the XML file
CByteArray cBuf; // create a buffer for the message to send
float x = ... // whatever you want it to be
float y = ... // whatever you want it to be
cBuf << x; // this adds a float (4 bytes) to the buffer
cBuf << y; // this adds another float (4 bytes) to the buffer
// now the buffer is 8 bytes, but it must be SIZE
// keep adding a byte until the size is filled (there are faster ways to do this, it's just an example)
while (cBuf.size() < SIZE) cBuf << '\0';
// now cBuf is ready
m_pcRABA->SetData(cBuf);
Re: range_and_bearing
Posted: Wed Jul 03, 2019 1:30 pm
by badri86
The range-and-bearing system allows robots to perform localized communication. Localized communication means that a robot, upon receiving data from another robot, also detects the position of the sender with respect to its local point of view. It is important to notice that the range-and-bearing system is not like WiFi. First, because two robots can exchange data only if they are in direct line of sight - if an object is between two robots, the robots can't communicate. Second, because robots that send data can only broadcast it in a limited area - you can't pick who you talk to as you would with an IP address. Third, the robots can exchange only 10 bytes of data.
To set the data to broadcast, use set_data(). This function accepts input in two forms. You can write set_data(idx, data), and this means that you set the idx-th byte to the value of data. data must be a number in the range [0,255]. Alternatively, you can write set_data(data), where data must be a table containing exactly 10 numbers in the range [0,255].
At each time step, a robot receives a variable number of messages from nearby robots. Each message is stored in a table composed of data (the 10-bytes message payload), horizontal_bearing (the angle between the robot local x axis and the position of the message source; the angle is on the robot's xy plane, in radians), vertical_bearing (like the horizontal bearing, but it is the angle between the message source and the robot's xy plane), and range (the distance of the message source in cm).