Difference between revisions of "RoCKIn2014PhaseII"
Carlosrhrh (talk | contribs) (→Sequentially Read Each Sensor 1) |
Carlosrhrh (talk | contribs) (→Sequentially Read Each Sensor 1) |
||
Line 107: | Line 107: | ||
[[Image:Chain sesors.jpg|center|500px]] | [[Image:Chain sesors.jpg|center|500px]] | ||
+ | |||
+ | The pin BW, is setting to a HIGH logical state , for this. | ||
+ | |||
+ | The program active the first sensor, setting it to RX input to HIGH (for at least 20uS) and take the reading of them, after set it to LOW state and the program continues reading the next sensors, which are activate in a sequentially way. The program read all the sensor in order to know taht when a sensor is activated the others are turn off (0 cm). | ||
+ | |||
+ | const int senSor_a = 8; | ||
+ | const int senSor_b = 7; | ||
+ | const int senSor_c = 4; | ||
+ | |||
+ | const int time_Run = 12; | ||
+ | //variables needed to store values | ||
+ | long pulse, inches, cm; | ||
+ | |||
+ | void setup() { | ||
+ | |||
+ | //This opens up a serial connection to shoot the results back to the PC console | ||
+ | Serial.begin(9600); | ||
+ | pinMode(senSor_a, INPUT); | ||
+ | pinMode(senSor_b, INPUT); | ||
+ | pinMode(senSor_c, INPUT); | ||
+ | |||
+ | pinMode(time_Run, OUTPUT); | ||
+ | |||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | |||
+ | |||
+ | digitalWrite(time_Run, HIGH); | ||
+ | |||
+ | |||
+ | |||
+ | //Used to read in the pulse that is being sent by the MaxSonar device. | ||
+ | //Pulse Width representation with a scale factor of 147 uS per Inch. | ||
+ | |||
+ | pulse = pulseIn(senSor_a, HIGH); | ||
+ | //147uS per inch | ||
+ | inches = pulse/147; | ||
+ | //change inches to centimetres | ||
+ | cm = inches * 2.54; | ||
+ | |||
+ | Serial.print(" sensor a1 cm "); | ||
+ | Serial.println(cm); | ||
+ | Serial.println(); | ||
+ | |||
+ | pulse = pulseIn(senSor_b, HIGH); | ||
+ | //147uS per inch | ||
+ | inches = pulse/147; | ||
+ | //change inches to centimetres | ||
+ | cm = inches * 2.54; | ||
+ | |||
+ | Serial.print(" sensor b1 cm "); | ||
+ | Serial.println(cm); | ||
+ | Serial.println(); | ||
+ | |||
+ | pulse = pulseIn(senSor_c, HIGH); | ||
+ | //147uS per inch | ||
+ | inches = pulse/147; | ||
+ | //change inches to centimetres | ||
+ | cm = inches * 2.54; | ||
+ | |||
+ | Serial.print(" sensor c1 cm "); | ||
+ | Serial.println(cm); | ||
+ | Serial.println(); | ||
== Software == | == Software == |
Revision as of 19:31, 5 November 2013
Contents
Hardware
Structure modifications
Ultrasonic Sensors Belt
Ultrasonic sensors selecction
There are many different kind of ultrasonic sensors and manufacturers, but in this case we have used the Maxbotics [1] manufacturer . We use these, in order to recycle the ultrasonic sensors of an old watchful robot ( good rattletrap).
This robot use for his navigation system, three different Maxbotics models, the MB1220 [2], MB 1230 of the XL-Maxsonar-EZ series and the LV-Maxsonar-EZ1 model.
We will use the model MB1220, because it is the most appropriate for people detection and there are a large quantity of them.
First tests and validation sensors.
Theses sensors have a diode between his outputs PW (anode) and AN (cathode).
After a several test with and without the diode, we come to a conclusion that the sensor only work properly and in the PDF way, using these without diode.
Analogical read. In order to test the analogical output and his work, we take the process described in the tutorial[3], in which the analogical read (AN) is do it by a voltmeter or using the next program:
const int anPin = 1; //variables needed to store values long anVolt, inches, cm; int sum=0;//Create sum variable so it can be averaged int avgrange=60;//Quantity of values to average (sample size) void setup() { //This opens up a serial connection to shoot the results back to the PC console Serial.begin(9600); } void loop() { //MaxSonar Analog reads are known to be very sensitive. See the Arduino forum for more information. //A simple fix is to average out a sample of n readings to get a more consistant reading.\\ //Even with averaging I still find it to be less accurate than the pw method.\\ //This loop gets 60 reads and averages them for(int i = 0; i < avgrange ; i++) { //Used to read in the analog voltage output that is being sent by the MaxSonar device. //Scale factor is (Vcc/512) per inch. A 5V supply yields ~9.8mV/in //Arduino analog pin goes from 0 to 1024, so the value has to be divided by 2 to get the actual inches anVolt = analogRead(anPin)/2; sum += anVolt; delay(10); } inches = sum/avgrange; cm = inches * 2.54; Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); //reset sample total sum = 0; delay(500); }
After this, we know hat the analogical output of the sensor do not work.
Digital read PW output. One sensor.
This output is test using an Arduino and the next code [4]
const int pwPin = 7; //variables needed to store values long pulse, inches, cm; void setup() { //This opens up a serial connection to shoot the results back to the PC console Serial.begin(9600); } void loop() { pinMode(pwPin, INPUT); //Used to read in the pulse that is being sent by the MaxSonar device. //Pulse Width representation with a scale factor of 147 uS per Inch. pulse = pulseIn(pwPin, HIGH); //147uS per inch inches = pulse/147; //change inches to centimetres cm = inches * 2.54; Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); delay(500); }
Using multiple sensors
[5]
In order to use several sensors at the same time and avoid the cross-talk effect, [6] between them, it is necessary that the sensor work in sequentially way.
Sequentially Read Each Sensor 1
In order to trigger sequentially the sensors, and use the minimum digital outputs of the microcontroller, the sensors are connected like in the figure, but instead of use the AN output, using the PW ones.
The pin BW, is setting to a HIGH logical state , for this.
The program active the first sensor, setting it to RX input to HIGH (for at least 20uS) and take the reading of them, after set it to LOW state and the program continues reading the next sensors, which are activate in a sequentially way. The program read all the sensor in order to know taht when a sensor is activated the others are turn off (0 cm).
const int senSor_a = 8; const int senSor_b = 7; const int senSor_c = 4;
const int time_Run = 12; //variables needed to store values long pulse, inches, cm;
void setup() {
//This opens up a serial connection to shoot the results back to the PC console Serial.begin(9600); pinMode(senSor_a, INPUT); pinMode(senSor_b, INPUT); pinMode(senSor_c, INPUT);
pinMode(time_Run, OUTPUT);
}
void loop() {
digitalWrite(time_Run, HIGH);
//Used to read in the pulse that is being sent by the MaxSonar device. //Pulse Width representation with a scale factor of 147 uS per Inch.
pulse = pulseIn(senSor_a, HIGH); //147uS per inch inches = pulse/147; //change inches to centimetres cm = inches * 2.54;
Serial.print(" sensor a1 cm "); Serial.println(cm); Serial.println(); pulse = pulseIn(senSor_b, HIGH); //147uS per inch inches = pulse/147; //change inches to centimetres cm = inches * 2.54;
Serial.print(" sensor b1 cm "); Serial.println(cm); Serial.println(); pulse = pulseIn(senSor_c, HIGH); //147uS per inch inches = pulse/147; //change inches to centimetres cm = inches * 2.54;
Serial.print(" sensor c1 cm "); Serial.println(cm); Serial.println();
Software
FAQ/Problems
Xtion camera in a PC
The typical problem with Xtion pro model:
We launch
$ roslaunch openni_launch openni.launch
we get
[ INFO] [1383245066.923739155]: Number devices connected: 1 [ INFO] [1383245066.923896787]: 1. device on bus 002:05 is a PrimeSense Device (601) from PrimeSense (1d27) with serial id '' [ INFO] [1383245066.925020672]: Searching for device with index = 1 [ INFO] [1383245067.026459550]: No matching device found.... waiting for devices. Reason: openni_wrapper::OpenNIDevice::OpenNIDevice(xn::Context&, const xn::NodeInfo&, const xn::NodeInfo&, const xn::NodeInfo&, const xn::NodeInfo&) @ /tmp/buildd/ros-fuerte-openni-camera-1.8.6/debian/ros-fuerte-openni-camera/opt/ros/fuerte/stacks/openni_camera/src/openni_device.cpp @ 61 : creating depth generator failed. Reason: USB interface is not supported!
SOLUTION:
We have to modify global parameters of openni:
$ sudo vi /etc/openni/GlobalDefaults.ini
We go to line and uncomment the UsbInterface parameter:
; USB interface to be used. 0 - FW Default, 1 - ISO endpoints, 2 - BULK endpoints. Default: Arm - 2, other platforms - 1 UsbInterface=2
Reason:
Here and here but I think that the real reason is related to USB port management
From my point of view this is the outline (copy paste from USB port management
ENDPOINT -> The most basic form of USB communication is through something called an endpoint. A USB endpoint can carry data in only one direction, either from the host computer to the device (called an OUT endpoint) or from the device to the host computer (called an IN endpoint). Endpoints can be thought of as unidirectional pipes.
1 ISO-> Isochronous endpoints also transfer large amounts of data, but the data is not always guaranteed to make it through. These endpoints are used in devices that can handle loss of data, and rely more on keeping a constant stream of data flowing. Real-time data collections, such as audio and video devices, almost always use these endpoints.
2 BULK-> Bulk endpoints transfer large amounts of data. These endpoints are usually much larger (they can hold more characters at once) than interrupt endpoints. They are common for devices that need to transfer any data that must get through with no data loss. These transfers are not guaranteed by the USB protocol to always make it through in a specific amount of time. If there is not enough room on the bus to send the whole BULK packet, it is split up across multiple transfers to or from the device. These endpoints are common on printers, storage, and network devices.
0 FW [WARNING, I'm not sure]-> USB interfaces are themselves bundled up into configurations. A USB device can have multiple configurations and might switch between them in order to change the state of the device. For example, some devices that allow firmware to be downloaded to them contain multiple configurations to accomplish this. A single configuration can be enabled only at one point in time. Linux does not handle multiple configuration USB devices very well, but, thankfully, they are rare.
If someone find a better answer I will be happy to know it.
Multiple openni cameras
We have two different cameras Xtion PRo and kinect.This problem is related with the previous configuration, tt makes possible to work with Xtion but now we have problems with kinect.
[ INFO] [1383246210.089689756]: Number devices connected: 1 [ INFO] [1383246210.089891318]: 1. device on bus 001:17 is a Xbox NUI Camera (2ae) from Microsoft (45e) with serial id 'A00366A15277050A' [ INFO] [1383246210.091390182]: Searching for device with index = 1 [ INFO] [1383246210.193031599]: No matching device found.... waiting for devices. Reason: openni_wrapper::OpenNIDevice::OpenNIDevice(xn::Context&, const xn::NodeInfo&, const xn::NodeInfo&, const xn::NodeInfo&, const xn::NodeInfo&) @ /tmp/buildd/ros-fuerte-openni-camera-1.8.6/debian/ros-fuerte-openni-camera/opt/ros/fuerte/stacks/openni_camera/src/openni_device.cpp @ 61 : creating depth generator failed. Reason: USB interface is not supported!
Solution
; USB interface to be used. 0 - FW Default, 1 - ISO endpoints, 2 - BULK endpoints. Default: Arm - 2, other platforms - 1 UsbInterface=0