cotardp
Posts: 4
Joined: Sun Jan 27, 2013 2:33 pm

Quadcopter

Sun Jan 27, 2013 3:00 pm

Hello,

For our final project at EPITA, a french Engineering school specialised in Informatic and embedded systems,we realized a quadcopter.

The copter is remotely piloted by a joystick, over a network. All data are treated and then dispatched between the copter, the joystick, and the web graphical interfaces. The data transmission is handled by the websocketpp library (http://www.zaphoyd.com/websocketpp).

We used a raspberry PI on the copter to recover data from the joystick and transmit them to a KK multicopter board.

A Real Time OS and a C++ program are running on it, which are treating joystick data to adapt them, according to sensors informations and asked procedures (thanks to joystick buttons or web interface) such as take off, landing, automatic control etc.. Treated data are then transmitted to the KK board in real time (with libbcm).

A live webcam video retransmission to the ground is also handled by the RPI.

You can have a quick presentation of our project with the following video hosted on Youtube :
http://www.youtube.com/watch?v=oMh0w0NcWiA

If you are intereested in this project, don't hesitate to leave a comment or to contact us.

Sincerely,
--

Philippe COTARD
Yves ROLLAND
Dorian ZACCARIA

User avatar
Yaug
Posts: 126
Joined: Thu Jan 03, 2013 1:52 pm
Location: France, Moselle
Contact: Website

Re: Quadcopter

Mon Jan 28, 2013 8:50 am

Great project guys.

What kind of power source did you used ? And how long was the autonomy ?
Did you succeed flying several minutes in a row ?
Organisateur d'aPiro : http://forum.raspfr.org/viewtopic.php?id=6
Domotique DIY : http://ydle.fr
Communauté française : http://forum.raspfr.org/
RaspberryGeek / http://manuel-esteban.com

cotardp
Posts: 4
Joined: Sun Jan 27, 2013 2:33 pm

Re: Quadcopter

Mon Jan 28, 2013 3:07 pm

Thank you!

We use a single 5000mAh 3 cells battery as a power source.
It powers the 4 motors, the KK board, the webcam and the RPI.

When we are flying, we have about 20 minutes of autonomy. We never made flights longer than a minute. Because of the weather (it was snowing here) we can only test the quadcopter inside, and we don't have enough space. But we'll test it outside sooner.

Moreover, with cold we have some trouble with the wifi connection. We loose the signal and the copter is not controllable. Very dangerous..

msimberg
Posts: 1
Joined: Wed May 15, 2013 7:30 am

Re: Quadcopter

Wed May 15, 2013 7:37 am

Really nice! But are you planning on making any of the source code available?

Pieter-Jan5000
Posts: 40
Joined: Tue Jun 12, 2012 7:20 pm
Contact: Website

Re: Quadcopter

Wed May 15, 2013 12:57 pm

Very nice project! Congrats on your work!
http://www.pieter-jan.com/

cotardp
Posts: 4
Joined: Sun Jan 27, 2013 2:33 pm

Re: Quadcopter

Thu Jun 27, 2013 7:33 pm

Thank you. Unfortunately this project officially belongs to my school because it was made during my studies. I do not have the right to distribute the source code. We wanted to share it and see it evolve but we can't.

blamarpa
Posts: 454
Joined: Thu May 23, 2013 4:02 pm
Location: España

Re: Quadcopter

Sun Jun 30, 2013 6:02 pm

Ok, thanks for your no-share, and enjoy your toy.

koverat
Posts: 2
Joined: Wed Jul 17, 2013 6:58 am

Re: Quadcopter

Wed Jul 17, 2013 7:16 am

Very interesting.
I'm working on a similar project on my free time.
Moreover, with cold we have some trouble with the wifi connection. We loose the signal and the copter is not controllable. Very dangerous.
.

I don't use wifi, it is only for short distances, easily drop packets or lost connection; instead I'll use an UART RF converter on 433MHz, some models work on more than 5 kilometer distances. Moreover, you have a Pi on the board which as you wrote can land autonomously, so I think one possibility to lessen the danger is program the pi to hover or land the copter when network connection is lost.
Treated data are then transmitted to the KK board in real time (with libbcm).
Can you please tell me some more information about the communication beetween the Pi and the KK? I understand that you can't have the rights to distribute the sources but I hope you can talk about this part of the project in a little more details.

Regards
Attila

cotardp
Posts: 4
Joined: Sun Jan 27, 2013 2:33 pm

Re: Quadcopter

Wed Jul 17, 2013 7:47 pm

We wanted to use radio instead of wifi but it was more expensive and our school budget is restricted.
The aim was to first make it fly. The amelioration would have been to use radio, but only after.

There is a lot of security about network loss. We handle automatic reconnection, stabilization during the loss... After a timeout, the last step is to simply stop the transmission to the motors to make it stop flying. It is dangerous, especially if the copter is 10 meters above the ground, but we are sure it will finally land...

As you say I have not the right to distribute it, but I can give you the few lines that handle that. It is negligible compared to the overall project .
As you know, on the PI you have avalable pins. We use bcm2835 lib to handle them. You have a lot of informations about it on this forum. We use 4 pins, one for each "axis" : collective, yaw, roll and pitch
On the KK board, there are 4 input pins which correspond to the same axis. The aim is to send them in an regular intervall (a fixed number of ms) some informations. The KK board will do the end of the job to control the motors.

More explicitly, you have to send during, for exemple 200 ms, all the informations about the axis.
  • - Initially, each pin on the PI at "0".
  • - At t=0, all pins are set to "1".
  • - You have to stop each pin at the right moment to "code" the value. If the pin is set to "0" imediattely after (t=~0ms), it represents 0%, and if it is set to "0" at the end (t=~200ms), it represents 100%.
Of course, you have to do that for the 4 pins in parallel.

I made you a small drawing to make it clearer.
rpi_to_kk_pins.png
rpi_to_kk_pins.png (6.32 KiB) Viewed 3243 times
Attached, you will find the source code that handles this part. It is a thread communicating with the main process to retrieve data throw a shared structure.

Code: Select all

stab.hh (partial)

typedef struct		cmd_time {
  /**
   * \brief Ref time at the beginning of the cycle
   */
  struct timeval	ref;
  /**
   * \brief Current time of the cycle
   */
  struct timeval	now;
}			s_cmd_time;



/**
 * \brief Send data to GPIOs
 *
 * Function launched in gpio_thread_ to send data to GPIOs Perodically
 *
 * \param encapsvoid Void pointer of the encapsulation structure
 */
void *send_to_gpio(void *encapsvoid);

/**
 * \brief Time difference
 *
 * Calculates te tine elapsed between two times
 *
 * \param time structure of the time references
 * \return the time elapsed
 */
int delta (s_cmd_time *time);

Code: Select all

stab.cc (partial)

int delta (s_cmd_time *time)
{
  int tmp = (time->now.tv_sec*1000000 + time->now.tv_usec)
    - (time->ref.tv_sec*1000000 + time->ref.tv_usec);
  return tmp;
}

/**
 * Send data each FREQ_ENVOI_CMD ms (Thread)
 */
void *send_to_gpio(void *encapsvoid) {
  Configuration* conf= Configuration::getInstance();
  Captors* captors= Captors::getInstance();
  s_encapsulation* encaps = (s_encapsulation*)encapsvoid;
  int **tablep =  encaps->tablep;
  int *table_locked = encaps->table_locked;
  s_cmd_time time;
  int eltime = 0;
  int i,j;
  bool captors_retrieved = false;

  int **table = (int**) malloc(4 * sizeof (int*));
  for (i=0; i<4; ++i) {
    table[i] = (int*) malloc (2 * sizeof (int));
    table[i][1] = i;
    table[i][0] = 0;
  }

  BCM2835_INIT();

  BCM2835_GPIO_FSEL(GPIO_COLLECTIVE, BCM2835_GPIO_FSEL_OUTP);
  BCM2835_GPIO_FSEL(GPIO_YAW, BCM2835_GPIO_FSEL_OUTP);
  BCM2835_GPIO_FSEL(GPIO_PITCH, BCM2835_GPIO_FSEL_OUTP);
  BCM2835_GPIO_FSEL(GPIO_ROLL, BCM2835_GPIO_FSEL_OUTP);

  while (true) {
    int gpio_sleep = conf->get(CONF_GPIO_SLEEP);
    /**
     * Test if a command have already been received (0 by default)
     */
    gettimeofday(&(time.ref), NULL);
    if (tablep[0][0]) {
      /**
       * Retrieve captors data
       */
      //captors_retrieved = captors->retrieve();

      gettimeofday(&(time.ref), NULL);
      /**
       * DEBUG
       */
      //ARM_DEBUG();
      //GPIO_DEBUG();

      BCM2835_GPIO_WRITE(GPIO_COLLECTIVE, HIGH);
      BCM2835_GPIO_WRITE(GPIO_YAW, HIGH);
      BCM2835_GPIO_WRITE(GPIO_PITCH, HIGH);
      BCM2835_GPIO_WRITE(GPIO_ROLL, HIGH);

      if(!(*table_locked)) {
	*table_locked = 1;
	for (i = 0; i < 4; ++i)
	  for (j = 0; j < 2; ++j)
	    table[i][j] = tablep[i][j];
	*table_locked = 0;
      }

      usleep(table[0][0] - 150);

      for (i = 0; i < 4; ++i) {
	do {
	  gettimeofday(&(time.now), NULL);
	  eltime = delta(&time);
	} while (eltime < table[i][0]);
	BCM2835_GPIO_WRITE(table[i][1], LOW);
      }
    }

    gettimeofday(&(time.now), NULL);
    eltime = delta(&time);
    if (eltime < gpio_sleep)
      usleep(gpio_sleep - eltime);
  }
}

jfornango
Posts: 113
Joined: Fri Sep 14, 2012 7:46 pm
Location: St. Louis, MO USA
Contact: Yahoo Messenger

Re: Quadcopter

Wed Jul 24, 2013 6:47 pm

Hehe... going after your Reverse Engineering skil patch, koverat? :lol:

This is actually an amazing project. The RPi can give you an incredible amount of autonomous control. Preprogrammed responses to certain conditions, fuzzy logic routines to help it decide what to do in highly dynamic environments, and the nature of the Pi makes the code expandible for more capabilities.

I could see putting something like this together as a hobbyist kit.
I'm only wearing black until they find something darker.

koverat
Posts: 2
Joined: Wed Jul 17, 2013 6:58 am

Re: Quadcopter

Fri Oct 11, 2013 1:18 pm

Hehe... going after your Reverse Engineering skil patch, koverat?
Sort of... ;)
I need to understand how the communication works because I want to control the copter with an USB computer joystick (Logitech Freedom), and to achieve this goal, I need to write the communication algorithms which convert the joystick data to a format which the KK understand, and it is possible only when I know how the KK works. :geek:
I could see putting something like this together as a hobbyist kit.
It's a nice idea but I'm not sure if I like to see a highly autonomous UAV which can be purchased and modified by "anybody" for any purpose without the proper understanding how it works because the lack of knowledge (and lack of "feeling" of responsibility) can cause serious accidents.

Cotardp, thank you for the information!
Sorry for the late reply, I do not have much free time to work on my projects...
The aim is to send them in an regular intervall (a fixed number of ms) some informations.
This is the point where I am confused a little bit.
On the net, I found 2 waveforms which are used in the field of RC communication (I know it has a lot of protocols but those 2 is the most widespread as I understand). One is the modulation which you mentioned in your previous post. The other is the "servo PWM": in every at least 25 ms, the signal is high for beetween 1 and 2 ms, 1ms is 0% ("servo full left"), 2ms is 100%.("servo full right") and 1.5ms is the "center".

To make some light in the darkness in my head, I was build a "servo PWM" signal generator from CD4047 and CD4098 (at first I was try with the Pi but I can not get enough resolution on the GPIO with the very little programming knowledge I have). I was connected the signal generator to the KK, calibrated the stick centers and the ESC throttles, and it was worked fine with "high" signals roughly from 800us (0%) to 2000us (100%). This was the first test.

The second test was with an arduino nano which have some PWM outputs which generate a waveform which is similar to the one you mentioned earlier except that the arduino have an almost 500hz signal (which is roughly 2ms wavelength, similar to "servo PWM"). The KK konnected to the PWM digital outputs, and the pins was controlled with AnalogWrite() to generate a PWM signal. The result: under roughly 40 percent, the KK think it is on zero percent. In other words, the KK think that 50% is the stick center, ~40% is the zero throttle, and 100% is the full throttle. A "little" asymmetric for my taste... :D

I think I need to conduct more tests to better know the KK's borders, but first I need to purchase an oscilloscope... ;)

About the Pi: because I'm a sysadmin, not a programmer, I need a lot of time to make a really working and fast algorithm. I use Perl (no C, no pointers, no cry :D ) and Freebsd as OS on the Pi, and yet I can make only a +- 2ms resolution on the GPIO ports which is not enough. Another problem is the Pi's 3.3V levels compared to KK's 5V levels, I need a level converter or optocoupler or similar thing.
At now, the Pi capable of interpret, convert and transmit an USB joystick's signal to the arduino through UART, but on the finish, I'd like to control the KK directly from the PI.

Best Regards
Attila

Return to “Automation, sensing and robotics”

Who is online

Users browsing this forum: Yahoo [Bot] and 10 guests