Quantcast
Channel: lithium flowers bloom » xbee
Viewing all articles
Browse latest Browse all 4

Communication Setup for Blinded

$
0
0

Li and I worked on a group of robotic/kinetic creatures to create an ironic and self-balanced networked system called Blinded.

A very detailed documentation of the construction iterations are up on Li’s website, so I’ll just write a bit about the communication between the creatures.

For the first iteration we had only one creature fully assembled so I built a quick “single character communication protocol” that allows the creature to be remotely controlled from a computer. I have two pre-paired series one xbees which are perfect for this basic cable replacement purpose.

The arduino on the creature side is expecting specific “single character” functions from the serial channel via xbee, available instructions are:

1. L – turn left
2. R – turn right
3. F – step forward
4. anything else – stop

At the same time, for monitoring purpose the arduino is reporting if the creature is on its target by comparing its left and right sensors and their historic readings, the reported status is written into the serial channel simply with notation of 1 (on-target) and 0 (target lost).

Because we had only one creature ready back then, the pursuing status is not entirely making sense, so the computer mainly served as a remote controller. The controller setup is pretty simple though, it can be just an xbee explorer board and any serial terminal program can be used to send commands to the remote creature. Following video shows one of our field tests in the park.

After more creatures were added to the group, the situation became much more complicated and I have to put up a processing sketch to coordinate input from multiple creatures. I did not use the xbee library for processing although it did look pretty promising in the examples and taking care a lot of the heavy liftings. But I dig into the source code a little bit and got a feeling that it might be a pain to use with series 2 xbees. So I just wrote some very simple parsing functions to take apart I/O packets and make sure I have access to any digital or analog pins without too much hack.

For physical setup, I switched all remote xbees to series 2 and put their firmware to router-at mode. The base station that stays with the computer is in coordinator-api mode. I used 4 pins of the remote xbees, 2 for digital output (remote commands), 2 for analog input (transferring sensor values to the remote computer/coordinator). Each remote xbee will still need to handle status reporting and command receiving, and the arduino on the creature remains as local intelligence that parses the sensor information and actually controls the motion.

Commands for Xbee configuration:

ATD04
ATD14
ATD22
ATD32

During runtime, the computer is able to set the remote xbee digital pin state through processing sketch. Code snippet for setting

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
void setRemotePin(byte []address, String command, int value)
{
  if (address.length != 8)
  {
    println("invalid address");
    return;
  }
  if (command.length() != 2)
  {
    println("invalid command");
    return;
  }
  serialSelector.port.write(0x7E); // start byte
  serialSelector.port.write(0x0); // high part of length (always zero)
  serialSelector.port.write(0x10); // low part of length (the number of bytes that follow, not including checksum)
  serialSelector.port.write(0x17); // 0x17 is a remote AT command
  serialSelector.port.write(0x0); // frame id set to zero for no reply
  // ID of recipient, or use 0xFFFF for broadcast

  for (int i = 0;i < 8; i++)
  {
     serialSelector.port.write(address[i]);
  }

 /* broadcast */
 /*
  serialSelector.port.write(00);
  serialSelector.port.write(00);
  serialSelector.port.write(00);
  serialSelector.port.write(00);
  serialSelector.port.write(00);
  serialSelector.port.write(00);
  serialSelector.port.write(0xFF); // 0xFF for broadcast
  serialSelector.port.write(0xFF); // 0xFF for broadcast
  */

  // 16 bit of recipient or 0xFFFE if unknown
  serialSelector.port.write(0xFF);
  serialSelector.port.write(0xFE);
  serialSelector.port.write(0x02); // 0x02 to apply changes immediately on remote
  // command name in ASCII characters
  serialSelector.port.write(command.charAt(0));
  serialSelector.port.write(command.charAt(1));
  // command data in as many bytes as needed
  serialSelector.port.write(value);
  // checksum is all bytes after length bytes
  int sum = 0x17 + 0xFF + 0xFE + 0x02 + int(command.charAt(0)) + int(command.charAt(1)) + value;
 
  for (int i = 0;i < 8; i++)
  {
     sum += address[i];
  }

  serialSelector.port.write( 0xFF - ( sum & 0xFF)  ); // calculate the proper checksum
  //delay(10); // safety pause to avoid overwhelming the serial port (if this function is not implemented properly)
}

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images