PitBot — A Star Is Born

Working at The First Structure in Our Sparring Robot — Lego Episode #24

J3
KidsTronics
6 min readJul 23, 2019

--

Hi everybody! In this episode, we’re gonna make PitBot v1 takes his first breath. Jump to videos? to see my Lego’s youtube playlist — click here;)

Gif 1. PitBot is alive!

Why PitBot? It’s a hybrid Animal + Robot. It’s a creature’s mixture of a Stubborn American Pit Bull Terrier plus a Sumo Sparring Boxing Robot :)

It’ll be used for Lego’s Sumo Robot personal trainer.

How to make it works?

Download Pixy Arduino Library from CMUcam5 Pixy. I used this version arduino_pixy-0.1.7.zip.

Then look for PixyMon; download from the link above. (There are several versions, be sure to pick the right one for your operating system.)

  • Launch the PixyMon application;
  • Select the Cooked view (click on the icon with the chef’s hat!); This view will show you exactly what the Pixy camera sees in real-time;
  • Click “Action->Set Signature1…”;
  • Select an area on the ball to teach color to the camera (I chose yellow);
  • Now that your setting is ok, deselect Cooked view, and you’ll see one geometric image; this is the mockup of the image location returned by the Pixy Camera to Arduino make its processing;
  • Upload the code below to your Arduino board (connected via ICSP pins) and maintain the USB cable supplying power to Arduino;
  • Now Connect a power via USB cable to Pixy and you are good to see PitBot alive (Gif 1 above): A Start Is Born \o/

The Code

Upload this code to your Arduino, and connect Pixy Camera with Arduino ICSP pins (provided by Pixy)

The Scenario

Now let’s do some math:)

Fig 1. Pixy Angle Math

Please see this video explaining all you see above:

Video 1. Explaining everything you’ll need to know about how Pixy swept all the object in its view

The Tasks

1- Error Calculation;

2- Set Servos to the center of the screen;

Explaining How It Works (The Arduino code above:)

The code is awesome! Thanks to charmedlabs o/

Let me try to explain the main structure.

First, you need to understand the scenario above. What is the objective of the tracking camera? Is to hold the object always centered on the screen, right?

How do I center an object on the screen? To make the camera follow the moving object while keeping it in the center of the screen, two things must be done: 1) calculate the actual error of making the moving object-centered again on the screen and 2) set the servos to center the object by correcting its positions on both axes.

By using the Pixy library, the first thing to do is to declare the X and Y_CENTER. This is done by the constants contained in the library itself (PIXY_MAX_X and PIXY_MIN_X). That’s simple enough, right?

Then for calculating the error, charmedlabs use ServoLoop::update method:

{
...
{
vel = (error*m_pgain + (error - m_prevError)*m_dgain)>>10;
...}

Here PD instead of PID is used. Please, see this post for more information about PID control :)

The number returned is then bitwised by 10, resulting in a number conversion of 32 bit into 16 bit long.

The number used by the servos are 10 bit long, remember? So 16 bit are more than sufficient.

Now, the ifs that follow are just limiting the number servos’ extremes into 0–1000 range.

if (m_pos>PIXY_RCS_MAX_POS) 
m_pos = PIXY_RCS_MAX_POS;
else if (m_pos<PIXY_RCS_MIN_POS)
m_pos = PIXY_RCS_MIN_POS;

And the actual error is maintained for derivative calculation procedure (m_prevError = error); Again, see this post for more information.

‘Till here, Just fine!

Now set servos to center the object again, inside the if blocks:

...if (blocks)
{
// Calculating the errors panError = X_CENTER-pixy.blocks[0].x;
tiltError = pixy.blocks[0].y-Y_CENTER;
// Carrecting the servos positions panLoop.update(panError);
tiltLoop.update(tiltError);

// Centering the camera again

pixy.setServos(panLoop.m_pos, tiltLoop.m_pos);

...
}

The beauty of the code resides in using polymorphism.

Polymorphism happens when we relying on each object to know how to do the right thing in response to the same method call. The same message (in this case, ServoLoop::update) are called by panLoop and tiltLoop objects.

    panLoop.update(panError);
tiltLoop.update(tiltError);

This is a superb solution! Congratulations to charmedlabs!

And that’s all, folks!

In the next episode, we’re gonna get the PiBot steering for tracking the yellow cup. Be tuned!

By for now!

Credits References

Playing with your Pixy Pet! by and from Sparkfun

Assembling the pan/tilt Mechanism from Pixy Documentation Wiki Page

Running the Pan/tilt Demo from Pixy Documentation Wiki Page

Lego lança peças em braille para desenvolver habilidades de crianças cegas from Época Negócios Magazine

Related Posts

63 Ardu_Series — VNH2SP30 — Monster Moto Shield — Use This Board In Extreme High-Demand Application — Full-Bridge Motor Drivers — 30A@16v peak

23° ArduSeries — PID sample for Arduino — HowTo Control devices with PIDLibrary

5/5 Part JayThree Balancing Car Project — PID without a PhD

01º Lego Episode — Our Startup’s Journey — Invaders and Invasions?

02º Lego Episode — Timmyton Lego-Learning-By-Playing — L2BP Series

04º Lego Episode — Lego MotionsTribot v 1.0Seeing Your Creation Move — Move Steering Block

05º Lego Episode — Lego Motions Move Tribot Around — And Backward…Five Programs Files

06º Lego Episode — Lego SensorsTouch N Color — Two out of five human senses — Touch N Sight

07º Lego Episode — Lego Sensor LineFollower — Line Follower Tribot v1.0

08º Lego Episode — Maze Solving Robot v1 — Lego Solution Right-Wall-Follower-Robot

09° Lego Episode — Gettle_&_Sound_Bots — How gentle can a robot be? What is the audible range of the human ear? How deep can we dive?

10° Lego Episode — Data Logging — Data Collection and the EV3

11º Lego Episode — Binning the LineFollower Code — Binning: Arithmetic To Map Sensor Reading

12º Lego Episode — A Proportional LineFollower Robot — Advanced Math To Improve Your Robot’s Steering

8th KidSeries — J3 Follower Line Robot v1.0 — The Simplest Follower Line Robot

13º LEGO Theory — Multitasking — A very Useful Programming Technique

14º LEGO formula — Normalizing Data — Converting Data to Use The Same Range

15º Lego Episode — PID — The Ultimate Line Follower — Algorithm for your EV3 PID Line Follower Robot

16° Lego Meets Pixy Episode — How to Connect Your Inexpensive Camera Module to Lego

18° Lego Episode — GEARS & WORMS — Geartrains & Worm & Clutch Gears

23° Lego Episode — Differential Explained — How Differential Works?

24° Lego Episode — PitBot — A Star Is Born — Working at The First Structure in Our Sparring Robot

25 ° Lego Episode — PitBot Is Agressive? Well, No Worries! — Making PitBot bite!

26° Lego Episode — Dancing Good w/ PitBot — All The Secret for Replicate This Awesome Robot

27 ° LEGO Episode — Sumo Arena is Ready! — Here is the playing arena for Arduino x Lego

28 ° LEGO Episode — Pick Pitbot Up! — Our Robot Are Leaving Body & Paint Shop

28 ° LEGO — B — Episode — Pitbot Battery & Sensor Setup — Preparing The infrastructure for running Arduino code

29 ° LEGO Episode — Bridging All Sensors Together — Pitbot — Collecting All Codes for the Final Act of Giving Behaviors to Robot

Fig 4. PitBot staring at the yellow ball! Run Forest, Run…

Revision 1 @ 04/2020 — Explaining better how to connect Arduino & Pixy

--

--

J3
KidsTronics

Hi, Guys o/ I am J3! I am just a hobby-dev, playing around with Python, Django, Ruby, Rails, Lego, Arduino, Raspy, PIC, AI… Welcome! Join us!