r9kawai / ToyDroneWithAutopilotBarcodeReader

Task of barcode read automatically at flight. Anyone can experiment it with toy drone of "Tello - Ryze Tech" and Ubuntu on PC. It use image processing of AR marker, camera process recognize position.
MIT License
17 stars 9 forks source link

ubuntu version #6

Open lifenghua0108 opened 5 years ago

lifenghua0108 commented 5 years ago

Is it only possible on ubuntu 18.10 ? how about 18.04?16.04?

r9kawai commented 5 years ago

I confirm on Ubuntu 18.10.

r9kawai commented 5 years ago

I think that, weak point of this software is complexity operating environment. I would like to rewrite it in Windows C ++ if I have time...

lfhlfh0108 commented 5 years ago

Thank you so much It works well on Ubuntu 18.04

r9kawai commented 5 years ago

Good! I'm happy your works well.

hkpc0715 commented 5 years ago

Hi @r9kawai,

First of all, thank you for sharing this code. I have successfully installed and ran the programme.

As this is quite an interesting project, I would like to understand more:

  1. AR markers are used in locating the next location is that correct? Therefore, we need an AR marker along with the QR code or Barcode. Am I right?

  2. I have tried both Barcodes and QR codes, sometimes it can read the code but sometimes do not.. I assume its the lighting problem or size of the codes affecting it.

hkpc0715 commented 5 years ago

Hence, I am facing a problem of it only reads the QR code below AR-02, and after reading the first code, it does not record the second code anymore.

r9kawai commented 5 years ago

This program works roughly follow below.

1.If find a AR in camera image, then order a yawing command to that. 2.Then order a up or down command to that. (These angles and distances are calculated from the size of the AR and the position on the screen.) (This calculation is not accurate, and I want to improve it next time.) 3.Then order a forward command to that. (It keeps a certain distance to avoid contact.) 4.If a distance of AR to aircraft is under 60cm, then try read process Barcode. (BARREAD_DISTANCE = 60) (This program could measure a distance of AR to aircraft, but could'nt measure a distance of Barcode to aircraft! because, size of barcode is unknown) (It is important that the AR size is as expected.) 5.If close AR under 60cm, It continue trying, and axis correct and capt a AR at center) (If Barcode is too detailed, regardless capt in screen, May not be readable for a long time.) (Needs are room is bright, the image transfer on WiFi is good, the Barcode is clear, the lines are not too thin)

6.If success to read the Barcode, then 180degree yawing. but, If couldn't capt a next AR at timing at it. Will not continue. (I wanted to search with a better algorithm.)

(In fact, A camera of Tello is too cheep for read a Barcode, Not practical, but I wanted to demonstrate a new usecase for drones.)

https://i.imgur.com/DNManZu.jpg

r9kawai commented 5 years ago

Move to like the Youtube demo movie, two AR codes are arrangement place at roughly need oposite facing each other. About 5m.

r9kawai commented 5 years ago

I'm going to build a Windows version that was completely rewritten in C ++. I don't know when...

hkpc0715 commented 5 years ago

This program works roughly follow below.

1.If find a AR in camera image, then order a yawing command to that. 2.Then order a up or down command to that. (These angles and distances are calculated from the size of the AR and the position on the screen.) (This calculation is not accurate, and I want to improve it next time.) 3.Then order a forward command to that. (It keeps a certain distance to avoid contact.) 4.If a distance of AR to aircraft is under 60cm, then try read process Barcode. (BARREAD_DISTANCE = 60) (This program could measure a distance of AR to aircraft, but could'nt measure a distance of Barcode to aircraft! because, size of barcode is unknown) (It is important that the AR size is as expected.) 5.If close AR under 60cm, It continue trying, and axis correct and capt a AR at center) (If Barcode is too detailed, regardless capt in screen, May not be readable for a long time.) (Needs are room is bright, the image transfer on WiFi is good, the Barcode is clear, the lines are not too thin)

6.If success to read the Barcode, then 180degree yawing. but, If couldn't capt a next AR at timing at it. Will not continue. (I wanted to search with a better algorithm.)

(In fact, A camera of Tello is too cheep for read a Barcode, Not practical, but I wanted to demonstrate a new usecase for drones.)

https://i.imgur.com/DNManZu.jpg

Thank you for your reply. It really helps to understand how it works. However, I am still thinking the following issues:

1) I am trying to figure out how would it trigger to scan another QR code after the first one: I turn on the drone and link to the system, holding the tello and scan the first QR with AR. Success Then I move the tello and point to another QR code with AR. However, it does not read the code anymore.

Hence, if I understand what triggers the next scanning, I think I I will try to create a simple route for the tello to fly and scan 3~4 QR codes, e.g. up and down motion only.

hkpc0715 commented 5 years ago

Furthermore, I have also tried to control the tello with 'w' 'a' 's' 'd' to scan QR codes. However, it would not scan the 2nd QR code.

Example: One QR with AR placed in lower position Second QR with AR placed in higher position

Take off > read the first QR and AR code Control tello to fly up and read the 2nd QR and AR code (failed)

r9kawai commented 5 years ago

I want you to try a little amend below.

source of "drone_ar_flight.py"

insert new line * 200 : # enable marker flag self.choise_marker = id 201 : detect[id] = True


*comment out line 318 : # self.choise_marker = self._marker_sel()


*comment out line 419 : # self._marker_reset()

May be, It has change action to your need. It support AR markers only No.0 - 3. This is not good code... but, The next future software will be fixed. If you add array variable 4 to more, so good.

hkpc0715 commented 5 years ago

Thank you for your quick reply. I will try your advise.

hkpc0715 commented 5 years ago

I was trying to build a flight path (auto pilot) for the following case, but I struggled alot... rip:

Following task:

  1. take off - scan the first QR & AR code (just at the front <60cm)
  2. move to right (40cm) - scan the second QR & AR code
  3. move up (30cm) - scan the third QR & AR code
  4. move to left (40cm) - scan the forth QR $ AR code

I have read the UI file and come up with the following changes, but I failed... :

Source of: drone_ar_flight.py

def get_command(self):
        if self.next_cmd != None:
            cmd = self.next_cmd
            val = self.next_cmd_val
            self.next_cmd = None
            self.next_cmd_val = 0
            return cmd, val

        cmd = 'stay'
        val = 0

        if self.mode == MODE_SEARCH_UD:
            self.choise_marker = self._marker_sel()
            #if self.marker_enable[self.choise_marker] == True:
        self.marker_enable[self.choise_marker] == True:
            self.mode = MODE_TO_DIR
            #else:
                #if self.now_height_cm > ALTITUDE_MAX:
                #    self.sub_mode = SUB_MODE_DOWN
                #if self.now_height_cm < ALTITUDE_MIN:
                #    self.sub_mode = SUB_MODE_UP

            droneMoveRight(self,40)
        self.drone.move_right(40)
            self.choise_marker = self._marker_sel()
        self._marker_reset()
        cmd = 'stay'
            val = 0

        droneUp(self,30)
        self.drone.move_right(30)
            self.choise_marker = self._marker_sel()
        self._marker_reset()
        cmd = 'stay'
            val = 0

        droneMoveLeft(self,40)
        self.drone.move_right(40)
            self.choise_marker = self._marker_sel()
        self._marker_reset()
        cmd = 'stay'
            val = 0
 return cmd, val

    def draw_bold_text(self, drawtxt, text, x, y, color1, color2):
        drawtxt.text((x+2,y-2), text, color2, font=self.fontbold)
        drawtxt.text((x+2,y+2), text, color2, font=self.fontbold)
        drawtxt.text((x-2,y-2), text, color2, font=self.fontbold)
        drawtxt.text((x-2,y+2), text, color2, font=self.fontbold)
        drawtxt.text((x,y), text, color1, font=self.font)
        return

    def _get_2point_degree(self, ax, ay, ax2, ay2):
        radian = math.atan2(ay2 - ay, ax2 - ax)
        return (int)(round(math.degrees(radian)))

    def _marker_reset(self):
        self.choise_marker = 0
        self.marker_id = [False, False, False, False]
        self.marker_time = [int(0), int(0), int(0), int(0)]
        self.marker_enable = [False, False, False, False]
        self.marker_inframe = [int(0), int(0), int(0), int(0)]
        self.marker_pointss = [[[float(0),float(0)],[float(0),float(0)],[float(0),float(0)],[float(0),float(0)]]]*4
        self.marker_distances = [int(0), int(0), int(0), int(0)]
        self.marker_diff_cm = [ [int(0), int(0)],[int(0), int(0)],[int(0), int(0)],[int(0), int(0)] ]
        self.marker_degree = [int(0), int(0), int(0), int(0)]
        self.marker_ztilt = [int(0), int(0), int(0), int(0)]
        self.code_flag = False
        self.chase_marker = int(-1)
        return

Apologies for being a beginner of python... Can I know which part I misunderstand?