Monthly Archives: March 2017

How to make a Balboa robot balance, part 3: encoders

via Pololu Blog

This is the third post in a series about how to make a Balboa 32U4 robot balance. Last week I talked about inertial sensors, especially the gyro. In this post I will talk about the Balboa’s built-in encoders, which allow accurate measurements of motor speed and distance.

[See also: Part 1: selecting mechanical parts, Part 2: inertial sensors, Part 4: a balancing algorithm, or Part 5: popping up and driving around.]

To get your Balboa to balance, you will soon need to create a balancing algorithm, a program that takes sensor input and computes the appropriate motor speed settings to keep the robot upright. So far our only inputs, both from the gyro, are the rate of rotation and current angle of the robot. These are not quite enough to make a good balancer. To see why, suppose that your program tries to balance by holding the angle at a constant 90°. If your definition of 90° is even slightly off-balance, the robot will need to keep accelerating, driving faster and faster to maintain it, until it reaches top speed or hits an obstacle. You might be able to account for this by using the motor output settings themselves as an input to your algorithm, but this is difficult, especially at the low speeds used for balancing. Also, even if you can avoid accelerating, your robot will gradually drift in one direction or the other. The Balboa’s encoders are valuable additional sensor inputs that allow you to measure how fast the wheels are actually turning, so you can directly control acceleration and drift. As a bonus, encoders are great for driving straight, precision turns, and navigation.

The encoders consist of a magnetic disc attached to the shaft of each motor, and two Hall effect sensors on the PCB directly under each disc:

Each disc is (invisibly) magnetized with three north poles and three south poles; during a rotation of the motor shaft, each of the six poles rotates across the two sensors, giving 12 “counts” per revolution. Each rotation of the wheels then gives a number of counts that is 12 multiplied by the gear ratio. These counts are the basic units of your encoder inputs, so it’s a good idea to learn what they correspond to in terms of actual distance traveled. For a gear ratio ``G`` and wheels with diameter ``D``, the distance per count is `` pi D // ( 12 * G )``. Using the 80mm wheels and the gear ratio table from my post about selecting mechanical parts, you can compute the distance per encoder count (in mm):

Gearmotor
30:1 50:1 75:1
External
gearbox
49:17 0.24 0.14 0.10
47:19 0.28 0.16 0.11
45:21 0.33 0.19 0.13
43:23 0.38 0.22 0.15
41:25 0.43 0.25 0.17

The values are all fractions of a millimeter, so for speeds of 1 m/s or more, you need to be able to read thousands of counts per second. Microcontrollers like the Balboa’s ATmega32U4 are great at this kind of task because of their support for interrupts, which are special functions in your code that execute immediately when a specified event occurs, suspending the rest of your code while they run. The Balboa 32U4 Arduino library includes interrupts that handle encoder counts automatically; to see the details, take a look at Balboa32U4Encoders.cpp and also read the section on encoders in the Balboa User’s Guide.

Since the library takes care of the counting, using encoders in a sketch is pretty easy. You just need to declare a Balboa32U4Encoders object and call its methods getCountsLeft() and getCountsRight() whenever you want to know the number of counts that have accumulated. However, there is a small complication: for efficiency, these methods return 16-bit unsigned integers, so with a maximum value of 65,535, they will overflow after your Balboa drives forward a few tens of meters. You should hope to eventually make it farther than that, so let’s look at how to save your encoder counts in nearly overflow-proof 32-bit integers. Luckily, there is another pair of functions we can use: getCountsAndResetLeft() and getCountsAndResetRight() set the internal number of accumulated counts to zero each time you check them, and they return the count as a signed integer that you can add to your own 32-bit variables distanceLeft and distanceRight:

Balboa32U4Encoders encoders;
int32_t distanceLeft;
int32_t speedLeft;
int32_t distanceRight;
int32_t speedRight;

void integrateEncoders()
{
  speedLeft = encoders.getCountsAndResetLeft();
  distanceLeft += speedLeft;

  speedRight = encoders.getCountsAndResetRight();
  distanceRight += speedRight;
}

As a side benefit, the change in encoder counts can be used as a measure of speed, so we store that as well, in the variables speedLeft and speedRight. Note these will only be a good measure of speed if integrateEncoders() is called on a regular period, with enough time between calls to accumulate at least a few counts. For example, if we call it every 10 ms, on a Balboa with 80 mm wheels, the 45:21 plastic gears, and 50:1 gearmotors, at 1 m/s we will measure a speed of ``1 text( m/s) * 0.01 text( s) // (0.19 text( mm/count)) ~~ 53``.

We now have four new inputs available for our balancing algorithm, which I will talk about in my next post.

Continue reading with Part 4: a balancing algorithm.

Robot Arm From Recyclables

via hardware – Hackaday

A robot assistant would make the lives of many much easier. Luckily, it’s possible to make one of your own with few fancy materials. The [circuito.io] team demonstrates this by building a robot arm out of recyclables!

With the exception of the electronics — an Arduino, a trio of servo motors, and a joystick — the arm is made almost completely out of salvaged recyclables: scrap wood, a plastic bottle, bits of plastic string and a spring. Oh, and — demonstrating yet another use for those multi-talented tubers — a potato acts as a counterweight.

Instead of using screws or glue, these hackers used string made from a plastic bottle as a form of heat shrink wrap to bind the parts of the arm together. The gripper has only one pivoting claw for greater strength, and the spring snaps it open once released. Behold: your tea-bag dunking assistant.


Code for the project is available to download from their site. Given this straightforward tutorial, it’s hard to find a reason NOT to embark on building your first robot arm — if you haven’t already begun.

We at Hackaday love seeing projects that strive to reuse materials in inventive ways. That said, you needn’t rely on a shiny new Arduino for this robot arm. If you have an aging palm pilot kicking around, that will also do the trick.


Filed under: Arduino Hacks, hardware, robots hacks

Line-following robot and mini-sumo main board from tdrobótica.co

via Pololu Blog

One of our distributors in Colombia, tdrobótica.co, has developed a line-following robot kit and a mini-sumo main board kit.

The first kit includes everything you need to build a sleek line-following robot. It uses an Arduino-compatible A-Star 32U4 Micro as the main controller. It also uses a DRV8833 Dual Motor Driver Carrier, two Pololu micro metal gearmotors, brackets, and a 3/8″ ball caster.

The second kit is also based on the A-Star 32U4 Micro and DRV8833 carrier, and it includes much of the electronics needed to build a custom mini-sumo robot, including a buzzer, a voltage regulator, and an IR receiver for controlling it with a TV remote. It has two DRV8833 carriers, each with their channels paralleled to drive a total of two motors. There are connection points for 7 digital sensors (up to 5 can be analog).

tdrobótica.co’s mini-sumo main board kit.

For more information (in Spanish), see the line-following robot kit and a mini-sumo main board product pages.

When SparkX builds a safe cracking robot, everyone wins!

via SparkFun Electronics Blog Posts

Cracked safe

Empty, but still cool to watch

An automatic safe cracker was something we had discussed on the very first day of SparkX, and it was really great to see it come to fruition. Thanks to all who watched and commented on our live stream!

We asked for you to take guesses, given very little information, on how long our bot would take to crack the safe, and also, what the combination would be. Whoever came the closest without going over (Price Is Right rules) would win a $100 Sparkfun gift certificate. Well, now that the dust has settled, and we’re still sitting here happily and a bit proudly staring at our open safe, we have found our winners. For time, with a guess of 00:30:05, our winner is TCRobotics. And for combination, with a guess of 12/76/53, the winner is GCF. Congratulations!

For those of you interested in the finer points of how we did what we did, we’ve added a tutorial on our entire process, which you can find here.

Thanks again for watching, and Happy Hacking!

comments | comment feed

Enginursday: Home-Brew Alexa Endpoint

via SparkFun Electronics Blog Posts

These days, artificially intelligent, voice-activated assistants are big business. Apple has Siri, Google knows its name, and Amazon has Alexa. Unfortunately, getting to play around with any of these in any serious manner means getting a job with Google, Apple or Amazon. At least, until now.

Example setup

Amazon has released an example using Amazon Voice Services to interface with Alexa, which can be run on pretty much any desktop computer, including (wonderfully) the Raspberry Pi 3 or 2B. The entire example is open source and written in Java. The instructions online are thorough, detailed and correct. It requires that you create (or link your Amazon account to) a free developer account, and very good instructions are provided for that process as well.

It offers options for listening: you can set it up to be a push-to-talk device using the GUI on screen or a GPIO pin, or you can enable a wake word service to activate the system on the keyword “Alexa”.

Alexa on Pi screenshot

Image from the AVS Sample App wiki

The entire setup is free for use unless you’re developing it into a product.

Couple this with Shawn’s post from a few months ago about using Alexa with IFTTT, and you’ve got a very hacker-friendly setup for playing with Amazon Voice Services. The one downside is that you must manually register the device with AVS every time you boot it, so it doesn’t (quite) do the job of replacing an Echo. However, if you already have an RPi as part of a home automation system, adding AVS capability might be worth it, and I’m sure a more savvy user than myself could figure out a way to automate the startup procedures.

I used a Raspberry Pi 3 from our storefront stock, our pre-installed NOOBS microSD card, one of our miniature “hamburger” speakers and this Kinobo microphone from Amazon. Total cost overall is probably comparable to an Amazon Echo device, but it’s just so much cooler to build it yourself! Also, by running it on a Raspberry Pi, you have the Pi available for other home automation tasks.

Take a look and let us know what you think, especially if you figure out how to automate the boot process! Please share your thoughts in the comments below.

comments | comment feed

Incredible Raspberry Pi projects in issue 56 of The MagPi

via Raspberry Pi

Hi, Rob from The MagPi here! It’s the last Thursday of the month and that means there’s a new issue of the official Raspberry Pi magazine: yay!

MagPi Magazine 56 cover image

Grab your copy today!

The MagPi Magazine 56

The MagPi 56 covers some incredible Raspberry Pi projects built by members of our community, from simple things you can make quickly, like an easy robot or LEGO Pi case, to more advanced projects to experiment with, like a set of Pinoculars.

Our news section looks at some great new happenings in the world of Pi, such as the new Pimoroni kits for Zero W, the Cambridge theme for PIXEL, and our fifth birthday celebrations.

Also not to be missed in this issue is our lowdown of every Raspberry Pi operating system: which is your favourite? While you’re weighing up the pros and cons of Raspbian vs. Ubuntu MATE, you can also read about our DJ Hero harmonograph, some hot command line tips, and much more.

The MagPi is the only monthly magazine written by and for the Pi community. Regardless of your experience with the Raspberry Pi, there’s something for everyone.

Get your copy

You can grab the latest issue of The MagPi today from WHSmith, Tesco, Sainsbury’s, and Asda. Alternatively, you can order your copy online, or get it digitally via our app on Android and iOS. There’s even a free PDF of it as well.

We also have a fantastic subscription offer to celebrate the new Raspberry Pi Zero W: grab a twelve-month subscription and you’ll get a Raspberry Pi Zero W absolutely free, along with a free official case and a bundle of adapter cables. Get yours online right now!

MagPi Magazine Free Pi Zero W

Free Creative Commons download

As always, you can download your copy of The MagPi completely free. Grab it straight from the issue page for The MagPi 56.

Don’t forget, though, that, as with sales of the Raspberry Pi itself, all proceeds from the print and digital editions of the magazine go to help the Raspberry Pi Foundation achieve its charitable goals. Help us democratise computing!

We hope you enjoy the issue! That’s it until next month…

The post Incredible Raspberry Pi projects in issue 56 of The MagPi appeared first on Raspberry Pi.