The Maker Faire Bay Area is this weekend, May 19-21, 2017, at the San Mateo Event Center. MakeHardware had a booth at the Maker Faire last year, but we have been too busy to run a booth for 2017. We do plan to attend for a day to check out what other folks have been busy making!
If you decide to check out the Maker Faire this weekend, make sure you plan for enough time to get there and back. The Maker Faire is huge and even sets up exhibits in the parking lots at the San Mateo Event Center, so parking onsite is not available. There are shuttle buses and public transit, but be ready for a wait during busy times. The Maker Faire is totally worth the trouble, just be prepared!
Here are a couple of pics from our booth last year.
My favorite areas of the Maker Faire include the cooking (last year I bought some great fermentation tools), the crafts and the kid sections. There are lots of electronics, light sculptures, drones, huge metal sculptures, fire art, and tons of crazy creativity!
It turns out that a large number of toy drones use the same nRF24L01+ compatible RF chips. The word compatible is necessary because most of them seem to not use the Nordic Semiconductor chipset, but rather something like the XN297 from Panchip. . . . Continue Reading
For our drone flying project, we have been using the ELP 2 Megapixel USB Camera. The auto exposure on this camera works in most situations, but we found that it does not always adjust to bright sunlight. In preparation for demonstrating our computer-controlled drone at the Maker Faire, I wanted to have a plan in case we were outdoors. It was a good thing too, since we were assigned an outdoor booth next to the Drone Combat arena.
We detect the location of our drone by using blob detection on four paper circles that we have taped to the top of the drone. Originally, we were using a medium green color, but we found that under some lighting conditions, our code would confuse the light blue color on the body of the drone with the green circles. I thought about making our blob detection code more robust, but the Maker Faire was quickly approaching! Instead we decided to make our flying area more controlled. We used white poster board as the background for our flying area and I tested some different colors for the paper circles. Red circles were good, except that our code got confused if one of our hands was reaching into the flying area. Black was not good in dim light. In the end, we decided on a dark purple with a blue undertone.
OpenCV provides a way to set a webcam’s manual exposure, but there are two problems. The first is that OpenCV is not well-documented. I could find the documentation stating that I should be able to set the exposure value, but it was not at all clear what values to pass! The second problem is that your particular webcam may not support programmatic setting of the exposure. Thus, when your code doesn’t work, it can be difficult to determine if your code is wrong or if your webcam just won’t allow it!
OpenCV’s VideoCapture.set() is the method to use. If you look at the documentation, you will see that there is a property named CV_CAP_PROP_EXPOSURE. It took me some time to discover that depending on the version of OpenCV you are using, the property’s name might actually be CAP_PROP_EXPOSURE.
There is no hint as to what the exposure value should be set to, but luckily for me, I found a mapping for the ELP 2 MP webcam on this page by Joan Charmant. He shows that the exposure values range between -1 and -13. You can programmatically set the exposure in this manner:
Unfortunately, I could not figure out a programmatic way to set the exposure back to auto exposure. If you know how, please add a comment! Please be aware that for some webcams, such as this one, the manual exposure setting is stored in its on-board memory, which means that turning off your program and even turning off the webcam itself, the manual exposure will still be set!
As a workaround, I found a way to bring up the DirectShow property pages so that I could use the DirectShow GUI to set the manual exposure or to turn auto exposure back on.
Here’s the code to launch the DirectShow property page:
During the Maker Faire, our demonstration area was shaded by a tent for most of the day, but around 2 PM our flying area was part sun and part shade. We delayed the inevitable by moving our table back with the shade, but eventually we had to move our table back to the front of the booth and into the sun. On Saturday, the afternoon was mostly overcast, and the camera’s auto exposure worked most of the time. I was surprised that our blob detection code even worked when people walked in front of our booth and made our flying area partly shaded by their shadows.
Sunday was mostly sunny, and the webcam’s auto exposure did not work when it was very bright. At these times, I opened up the DirectShow property pages and set the exposure manually so that our demo would still work. Maker disaster averted!
In my previous post, I described how to set up Python and OpenCV on your computer. Now I will show you how to use OpenCV’s computer vision capabilities to detect an object.
OpenCV’s SimpleBlobDetector will be the primary function that we will be using. With the SimpleBlobDetector, you can distinguish blobs in your image based on different parameters such as color, size, and shape.
As an OpenCV novice, I searched Google to help me get started with the Python OpenCV code. You will find that OpenCV is very powerful and extensive, but unfortunately it is not well documented. Some classes and functions are described well, but some just list a method’s parameters with a terse description. I suppose we can’t have everything. On the bright side, there are many tutorials and examples to help you out.
Ball Tracking with OpenCV – this example is more extensive, and he has a nice animated gif at the top of his page showing the ball tracking in action. We use cv2.inRange() like he does, but we then use SimpleBlobDetector_Params() instead of findContours().
OpenCV’s Python Tutorials Page – I don’t have the patience to go through tutorials when I just need a quick solution, but I did look through a few of the tutorials on this page when the need arose. We based some of our color threshold code on the example shown if you go into the Image Processing in OpenCV section and then to the Changing Colorspaces tutorial.
When we were testing out our detection, we took a bunch of jpg photos with our webcam under different conditions and we put them in the ./images directory. In this code example, we loop through the image files and we try to detect the purple circles on our drone for each image.
The full code is detectDrone.py and is up on Github with the rest of the project. Here is the beginning of the code. We set up our import statements, and then we need to undistort the image. For our webcam, the image is distorted around the edges – like a fishbowl effect.
Blob Detection with OpenCV
# Load webcam calibration values for undistort()
# calibration values calculated using cv2.calibrateCamera() previously
Now to the heart of our code. We run cv2.GaussianBlur() to blur the image and which helps remove noise. The webcam image is in the BGR (Blue Green Red) color space and we need it in HSV (Hue Saturation Value), so the next call is cv2.cvtColor(image, cv2.COLOR_BGR2HSV).
We need to separate the purple circles from the rest of the image. We do this by using cv2.inRange() and passing in the range HSV values that we want separated out from the image. We had to do some experimentation to get the correct values for our purple circles. We used this range-detector script in the imutils library to help us determine which values to use. Unfortunately, the range of HSV values varies widely under different lighting conditions. For example, if our flying area has a mixture of bright sunlight and dark shadows, then our detection does not work well. We control this by shining bright LED lights over the flying area.
Blob Detection with OpenCV
# Blur image to remove noise
# Switch image from BGR colorspace to HSV
# define range of purple color in HSV
# Sets pixels to white if in purple range, else will be set to black
# Bitwise-AND of mask and purple only image - only used for display
# mask = cv2.erode(mask, None, iterations=1)
# commented out erode call, detection more accurate without it
# dilate makes the in range areas larger
Now we use SimpleBlobDetector to find our blobs and they are saved in keypoints.
Blob Detection with OpenCV
# Set up the SimpleBlobdetector with default parameters.
# Change thresholds
# Filter by Area.
# Filter by Circularity
# Filter by Convexity
# Filter by Inertia
# Detect blobs.
If we found more than 4 blobs, then we keep the four largest. We draw green circles around the blobs we found and we display these four images:
The original image after undistort and Gaussian blur (frame)
The image with the purple circles separated out and shown in white (mask)
The image with the purple circles separated out and shown in their original color (res)
The original image with green circles drawn around the purple circles (im_with_keypoints)
If there are multiple images in the directory, then we go through this whole process for the next image. Now our code can see where our drone is!
For our drone flying project, we needed a way for our computer to detect the location of our mini-drone through the use of a webcam mounted above the flying area. We are not at all familiar with computer vision algorithms, but we do know how to call functions from a Python library! We made use of OpenCV (Open Source Computer Vision), which is available for Python and C++.
For our Python environment, we chose Python(x,y). Python(x,y) is a version of Python developed specifically for scientific calculations and visualizations. If you are a fan of Matlab, then you will feel right at home with Python(x,y).
This is what you need to do to set up a Python(x,y) development environment with OpenCV.
Install the latest revision of the python(x,y) package. This includes Spyder (Scientific PYthon Development EnviRonment). Download Python(x,y) here.
For the Python(x,y) install, choose Custom install and select the Python ➞ PySerial 2.7-1 component. PySerial is needed to communicate with an Arduino.
Optional: We also like to add the Other ➞ WinMerge component when installing Python(x,y), but it is not required.
Unzip the opencv2 package and copy opencv\build\python\2.7\x86\cv2.pyd to <python dir>\Lib\site-packages\ where the default Windows location for <python dir> is C:\Python27
Note: If your computer supports it, copy opencv\build\python\2.7\x64\cv2.pyd instead of x86. I decided which to run by first trying the x64 copy, but the x64 version did not work for me when run. So I copied the x86 version instead. See below for how to check if OpenCV is loading properly.
Now it’s time to check if your development environment is working. Start Python(x,y) and you will see this window:
Click on the small blue and red icon that looks like a spider web to start the Spyder IDE. Here is what the Spyder IDE looks like:
The bottom right portion of the IDE shows the IPython console. You can run scripts or call Python commands directly in the IPython console.
In the IPython console, type import cv2 and hit enter.
If there is a problem, then you will receive an error, likely an error about “No module named cv2”. If that happens, then check that you copied the OpenCV files to the correct location as described in Step 3 above.
If everything is working, then the console will accept your command and show a prompt for your next command like this:
Hooray, you have successfully set up Python(x,y) and OpenCV! Nothing to it, right? Now let’s see what we can do with OpenCV. Take a look at our post on blob detection with OpenCV.
A few months ago, I watched this TED talk where they setup an indoor arena and did some amazing things with drones. It got me thinking, and it inspired me to build something like that for myself – but on a much smaller and cheaper scale.
In the video they use an expensive real-time infrared motion tracking system (I am guessing something like these Optitrack systems) to measure the position of the drones, and then uses a computer to calculate and send control signals to coordinate the drones. At a high level, my setup works in a similar way, as shown in this diagram:
Total cost for these items was around $85. In addition to the above, you might also need a folding table and stack of books to hold up the webcam as I did, but you can probably think up something more refined! Here is a video of it working:
Here are some links to further information on how this all works:
Every year my boss asks for suggestion for a teambuilding activity to have with his staff. Past activities have included thrilling activities like bocce ball and an indoor trampoline park (tip: this is a great idea if your team consists of 8 year-olds). This year I suggested that he buy everyone some drones and that we run some drone races. My suggestion was rejected – we went bowling instead. Well, I took matters into my own hands. I manage a team of engineers myself, and I was determined to do something a little different this year.
Step 1. Plan
Instead of the usual holiday lunch, I bought everyone on my staff a Cheerson CX-10 quadcopter. These are tiny little things – only about 2.5″ across, and they’re great for flying around indoors. Best of all, they only cost about $16 on Amazon. I gave them to everybody during a staff meeting, and scheduled another “meeting” about 3 weeks later to give everyone time to practice. Encourage them to practice – most likely they’ll need it.
At this next “meeting,” we had two events on the agenda:
We put 5 foam pads on the ground and on some tables. Most of them were about 8″x 8″, but one was about 4″ x 4″ for an extra challenge. The goal was to take off and land on each of the foam pads and return to the starting point. A successful landing on the large landing pad earned 50 points or 100 points for the smaller one. We had a time limit of 3 minutes to complete the course. Any crashes or other mishaps that require the pilot to touch the quadcopter (such as flipping it back upright) to were penalized with -30 points.
We setup a simple race course using a few poles as markers to make a loop. We had heats with 4 quadcopters flying at a time. Going around in a loop is harder than it looks. In both heats, the winner was the one who managed to fly three laps without crashing. Practice helps.
During the 3 weeks of practice, about 1/4 of my team managed to damage their quadcopters, so make sure that you have some spare parts available. Refer them to this repair guide.
Step 3. Profit
In addition to having a fun afternoon, I got to introduce a bunch of my coworkers to flying quadcopters, and we still fly them around sometimes (when no one else is watching).
Don’t forget this final critical step: Record your expenses and submit them under the category “Internal Meeting / Meal / Entertainment.”
Next year I think we’ll scale things up and go for a larger quadcopter we can fly outside – maybe a Hubsan X4.
If you’ve got access to a 3D-printer, or are just looking for an excuse to use one, these little blade guards are a neat project. Making your quadcopter look like a spaceship seems to be quite the thing, here’s links to some examples.
For all of you who received Cheerson CX-10 mini-quadcopters as holiday gifts and are learning to fly, bookmark this page because you’ll need it soon. Here’s a list of some common repairs – you might as well learn about it now.
and it didn’t come with a prop guard (which weighs 0.05 ounces / 1.5g), then you should definitely get one. It will dramatically reduce the number of broken propellers you have to deal with, particularly while you are first learning.
Removing the propellers: The propellers can be removed from the motor shaft by pulling them straight upwards. Sometimes they are loose, but sometimes it can take a little force. A pair of wirecutters gently put around the prop can help pry off the more stubborn ones. Just take care not to bend the motor shaft or nick it.
Proper Propeller Placement: You will need to remove the propellers when they break, but even more often something will get tangled in them (in my house, that tends to be hair or carpet fuzz). Removing the propeller makes it easy to remove the offending tangle.
The key thing to remember is that when you put the propellers back, you need to match the direction of rotation with the propeller. There are two types of propellers- some of them rotate clockwise, and some rotate counterclockwise. There is actually a letter code marking the propellers, but it’s easy enough to just remember the direction of rotation of the motor, and make sure that when the propeller rotates it should be pulling the quadcopter upwards.
Shorted out motor wires
This is a common issue. On one of my quadcopters, the motor wiring was worn and exposed on all four motors. This is what it looks like:
The problem is that the wiring will sometimes short against the metal body of the motor.
In my case, the quadcopter would still turn on and pair with the controller, but then once you tried to fly it the motors would spin for a half-second and then stop. The LEDs would then start blinking like it need to be charged again (even though it had just been charged).
On another quadcopter, it would fly for a few seconds, and then fall out of the sky. Amusing, but frustrating.
Here is the fix:
Remove the propellers
Unscrew the four screw in the bottom.
Gently pry off the the bottom white enclosure (note the clips on each end of the PCB)
Take off the blue case
You should end up with something that looks like this:
5. Fixing the insulation on the worn motors is tricky because it might make it too thick to slide the motor back into the case. In one case, I just removed the motor and remounted it so that the exposed part is away from the motor body. In another case I used tweezers to put in a place a very small piece of black electrical tape to insulate the wire.
6. Put everything back together (be careful when replacing the propellers!)
This version adds an altitude hold capability that can make it easier to fly. This is made possible by a very sensitive barometric (air pressure) sensor. For some reason it is mainly sold in some hideous rainbow or camouflage colors!
For those interested in hacking the CX-10, it looks like there has been at least 3 different PCB revisions. The primary reason for caring about this is if you want to pair to another transmitter such as the Walkera with DeviationTx. These are identifiable based on the color of the PCB when you open up the CX-10. There is the Red, Green, and Blue. There’s a lot of discussion on the Deviation TX board and RCGroups about which firmware is needed with which board (so go there for details), but in general I think that people have been able to make it work with all three versions.
I believe the Red and Green PCB versions came earlier. All of the units I purchased came from Amazon after Oct. 2015, and they have all been Blue PCBs.
The Cheerson CX-10A with Headless Mode
Cheerson CX-10A Mini-Quadcopter with Headless Mode
This is identical to the CX-10, but with an additional flying mode called “Headless Mode.” With the CX-10 and CX-10A in normal flying mode, the side with with the blue LEDs is the front (the “head”) of the quadcopter, and the side with the red LEDs is the back. The forward/backward, and left/right control (by default on the right joystick of the controller) are all referenced to this “head” orientation to quadcopter.
In Headless mode, the head of the quadcopter stays fixed to where it was based on how it started at takeoff of the device. This means that even if you rotate the the quadcopter with the left joystick and the blue/red LEDs indicate that the head of the quadcopter is rotating, it will not affect how the left/right controls work. When operating in headless mode, the LEDs will blink on and off (I guess they figure it’s ok for the LEDs to go off because they no londer indicate the heading).
This headless mode can make it less confusing for beginners to fly, but it doesn’t always work that great, so in general I never use it. However, I have noticed that in headless mode it the yaw rate seems to be reduced, and that overall can make things it slightly easier to fly.
On Amazon, the CX-10A seems to cost about $2-$3 more, but not all the listings are accurate. I’ve ordered a CX-10A at least once and received a normal CX-10. The packaging is the easiest way to tell the difference (see photos above), plus the symbol on the top middle of the body is different.
This CX-10A is also sold as the Cheerson Q4 where it is bundled with a handly little wrench to help pull off the propellers.
The difference with this one is obvious, and it’s pretty amazing. For an extra $10, you get a video camera that can record video or take still pictures to a micro SD card. The video below tells you everything you need to know.
The Cheerson CX-10D
Cheerson CX-10D Mini-Quadcopter with altitude hold.
This model adds the altitude hold feature the CX-10A (there is no camera). This is a nice feature for beginners, because keeping the drone at an even altitude is one of the trickier things to learn at first. Many folks bounce their drones off the ceiling and then the floor a few times before getting the hang of it. The altitude control feature is implemented using a barometric sensor. There is a nice review of the CX-10D here.
This version adds the amazing ability to stream images from the camera on the drone to your Android or iOS phone, which enables FPV (first-person view) flying. It is fun to play with, but admittedly, using your phone to fly this is not the best interface. Here is a thorough review of the CX-10W.
There is a third-party version of the app that enables you to fly via a CX-10C transmitter and then stream and record to your Android phone (the default app disables the transmitter capability once it is on).
The Cheerson CX-10WD with FPV and Altitude control
Cheerson CX-10WD Mini-Quadcopter with FPV and altitude hold.
If you don’t have enough room to fly the Cheerson CX-10 then you need a bigger living space, but maybe the Floureon FX-10 can help too. It includes headless mode, and flies about as well as the CX-10. Here is nice video review.