Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 51 Next »

 


Wed. 13.05.15 - 13:25 (fma)

For providing the ability of using the real sensors and actuators as well as the simulation to test the quadcopter, we decided to use some interface, which can both, communicate with the hardware or with the simulation.

...

 


Tue. 12.05.15 - 13:19 (fma)

Since the components are shipped with an unknown arrival date and for testing the interaction of the different sensors and actuators we will build an Arduino Lego Mindstorms setup on three wheels.

The NXT will therefor provide some basic navigation functions like goForwards, goBackwards, rotateRight, etc., as the software for basic flight is going to do later, too, and control the motors accordingly. The Arduino will be connected to the rest of existing components as usual. 

An NXT block is generally able to communicate over I2C as master to any slave device, for instance the Arduino. Via simple looped polling the NXT can ask the Arduino for drive commands.

To connect the Lego block to the Arduino a Mindstorms NXT cable is ordered, which will be cut open and linked to the microcontroller. For further understanding about wiring and I2C the LEGO MINDSTORMS NXT Hardware Developer Kit.pdf gives a good start. In addition the webpages of leJOS News and Dexter Industries seem to be quite helpful and even give some basic code example. Further information following...

 


Mon. 11.05.15

Ultrasonic sensors and bluetooth bridge have been delivered. Communication with Arduino is working.

Code:

The Arduino can detect the measured distance of a sensor and print it to the console
/*
 * code partly from http://www.robodino.de/2011/12/ultraschall-distanz-sensor-hc-sr04.html
 */ 
 
#define trigPin 31
#define echoPin 33
 
void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}
 
void loop() {
  long duration, distance;
  // To trigger the sensor a 10us HIGH signal is needed.
  // Create definite LOW for 2us 
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Give it a HIGH for 10us
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  // LOW again
  digitalWrite(trigPin, LOW);
  // Measure the pulse width of the incoming signal
  duration = pulseIn(echoPin, HIGH);
  // Calculate the distance with given function
  distance = (duration/2) / 29.1;

 
  if (distance >= 400 || distance <= 0) {
    Serial.println("Out of range");
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
  }
  // Wait a microsecond to start again
  delay(1);
}
The Arduino can receive command via bluetooth and set an LED on or off
/*
 * code partly from http://www.arduino-hacks.com/adding-bluetooth-capability-project-arduino-hc-06/
 */
 
char blueToothVal;           
 
void setup() {
  // Start a bluetooth connection via Serial1 ports
  Serial.begin(9600); 
  // User the LED on pin 13
  pinMode(13,OUTPUT);
}
 
void loop() {
  // If data over Serial1 are received
  if(Serial.available()>0) {
    // Read the data
    blueToothVal=Serial.read();
  }
  // If the data equal the letter 'n'
  if (blueToothVal=='n') {
    // Switch LED on
    digitalWrite(13,HIGH);
  }
  // Else if the data equal the letter 'f'
  else if (blueToothVal=='f') {
    // Switch LED off
    digitalWrite(13,LOW);
  }
  // Wait 100ms
  delay(100);
}
A computer can connect wirelessly to the Arduino and get the measured distance via bluetooth terminal
#define trigPin 31
#define echoPin 33
char blueToothVal;
 
void setup() {
 Serial.begin(9600); 
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
}
 
long getDistance() {
  long duration, distance;
  digitalWrite(13,HIGH);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  
  if (distance >= 400 || distance <= 0){
      distance = getDistance();
  }
  
  return distance;
}
 
 
void loop() {
  
  if(Serial.available()>0) {
    blueToothVal=Serial.read();
  }
  if (blueToothVal=='x') {
    Serial.print(getDistance());
    Serial.println(" cm");
  }
 
  // Reset blueToothVal to any letter but 'x'
  blueToothVal = 'c';
  delay(100);
}

The bluetooth module is found on the MacBook Pro as HC-06 in the list of available bluetooth devices. A connection can be established with Code '1234'.

 

In Terminal a list of all open serial ports can be shown via ' ls /dev/tty.* '.

/dev/tty.HC-06-DevB ' should be shown in the list. A serial console to the module can be established via ' screen /dev/tty.HC-06-DevB '.

Update:

To kill a running screen, press ctrl-a, afterwards crtl-\ (Yes: on German keyboard: ctrl-alt-shift-7), afterwards y.

 

Unfortunately the MacBook does not reconnect automatically after reset of the Arduino. The bluetooth module has to be unpaired and paired again to be usable again. Hopefully this will can be fixed somehow...

Update:

A much easier way of connecting via bluetooth is to use the Arduino Serial Monitor (Tools -> Serial Monitor).

It is now clear, how the module is handled by the MacBook Pro. Once paired, the HC-06 is always shown in the list of bluetooth devices as 'Not connected', unless an explicit connection is established. Establish a connection with a screen or the Serial Monitor. Once the connection is closed, HC-06 will be shown as 'Not connected' again. It is important to notice that the previous screen method has to be killed explicitly, not only closed, since there can only be one serial connection at once.

 


Thu. 07.05.15 - Meeting

Start:16:00 Attendees:
End:

18:00

 

apo

fma

lan

lpe

Protocol:lan (tick)(tick)(tick)(tick)

 


Thu. 30.04.15 - Meeting

Start:16:00 Attendees:
End:

16:40

 

apo

fma

lan

lpe

Protocol:lpe (tick)(tick)(tick)(tick)

 


Thu. 26.04.15 - Meeting

Start:17:30 Attendees:
End:

21:00

 

apo

fma

lan

lpe

Protocol:fma (tick)(tick) (tick)

 


Thu. 23.04.15 - Meeting

Start:17:30 Attendees:
End:

18:30

 

apo

fma

lan

lpe

Protocol:lpe (tick)(tick)(tick)(tick)

 


Thu. 23.04.15 - Meeting

Start:16:00 Attendees:
End:

17:00

 

apo

fma

lan

lpe

Protocol:lpe (tick)(tick)(tick)(tick)
  • No labels