0% found this document useful (0 votes)
48 views26 pages

Connecting Pixy To Mbot

This document provides instructions for connecting Pixy camera to mBot robot. It includes examples of Pixy code in Arduino and mBlock. It discusses topics like object detection, tracking objects, and improving detection accuracy. Code examples demonstrate detecting and responding to different object signatures.

Uploaded by

lejlam2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views26 pages

Connecting Pixy To Mbot

This document provides instructions for connecting Pixy camera to mBot robot. It includes examples of Pixy code in Arduino and mBlock. It discusses topics like object detection, tracking objects, and improving detection accuracy. Code examples demonstrate detecting and responding to different object signatures.

Uploaded by

lejlam2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Connecting Pixy to mBot

By Wilmer Arellano
Updated 10-24-2018
Download the Examples Here
• You are free:
• to Share — to copy, distribute and transmit the work
• Under the following conditions:
• Attribution — You must attribute the work in the manner
specified by the author or licensor (but not in any way that
suggests that they endorse you or your use of the work).
• Noncommercial — You may not use this work for commercial
purposes.
• No Derivative Works — You may not alter, transform, or build
upon this work.

Wilmer Arellano © 2016


• With the understanding that:
• Public Domain — Where the work or any of its elements is in the public
domain under applicable law, that status is in no way affected by the
license.
• Other Rights — In no way are any of the following rights affected by the
license:
• Your fair dealing or fair use rights, or other applicable copyright exceptions and
limitations;
• The author's moral rights;
• Rights other persons may have either in the work itself or in how the work is used, such
as publicity or privacy rights.
• Notice — For any reuse or distribution, you must make clear to others the
license terms of this work.

Wilmer Arellano © 2016


Start Here
• https://docs.pixycam.com/wiki/doku.php?id=wiki:v1:pixy_regular_qu
ick_start
• Install PixyMon
Next
• Go to:
• https://docs.pixycam.com/wiki/doku.php?id=wiki:v1:teach_pixy_an_object_2
• Watch the video.
• Learn about the two methods to capture signature.
• Read the content about white balance and Signature Tuning.
Improving Detection Accuracy
• Learn about ways to improve signature capture at:
• https://docs.pixycam.com/wiki/doku.php?id=wiki:v1:some_tips_on_g
enerating_color_signatures_2
• Read about overexposure highlighting, minimum brightness, and
signature teach threshold.
Configuration Details
Configuration Details
Configuration Details
Installing Pixy
Installing Int Casting
Tweaking the Camera Output
• Due to lighting conditions, a
single object may appear as
several objects.
• By reducing the number of
blocks the pixy detects, object
detection can be improved.
• The Pixy gives priority at
reporting larger objects.
• Set this values according to your
needs.
Connecting Pixy to mBot
Example 1
• If one or more objects
are detected, this
program prints the
signature of object 1.
• The arguments for the
Pixy functions must be
integers. Scratch
works with doubles.
The function (int) is
needed to do the type
casting.
Range of Functions Values
• Get signature of object:
The signature number of the detected object (1-7 for normal signatures)
• Get x location of object:
The x location of the center of the detected object (0 to 319)
• Get Y location of object:
The y location of the center of the detected object (0 to 199)
• Get width of object:
The width of the detected object (1 to 320)
• Get height of object:
The height of the detected object (1 to 200)
• Get angle of object:
The angle of the object detected object if the detected object is a color code.
• Serial print data of object:
A member function that prints the detected object information to the serial port
Hello World Arduino Style
• The program on the right is a popular Pixy “Hello #include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
World” demo with a minor modification. #include <SPI.h>
#include "Pixy.h"
• Open the Arduino IDE from within mBlock. Copy
Pixy ;
the program on the right and paste it into the
void setup(){
IDE. Serial.begin(115200);
Serial.print("Starting...\n");
• Upload to mBot and run. pixy.init();
}
• Program will detect blocks and print the void loop(){
static int i = 0;
associated data. int j;
uint16_t blocks;
• The instruction if (i % 10 == 0) limits the printing char buf[32];
blocks = pixy.getBlocks();
to 1 every 10 cycles. if (blocks) {
i++;
if (i % 10 == 0) {
sprintf(buf, "Detected % d: \n", blocks);
Serial.println(buf);
for (j = 0; j<blocks; j++) {
sprintf(buf, " block % d: ", j);
Serial.print(buf);
pixy.blocks[j].print();
Serial.println();
}
}
}
}
Hello World mBot Style v1
• The program on the right is an
mBlock version of the “Hello
World” program in the previous
slide.
• The program has the original 50
cycles update period.
Hello World mBot Style v2
• The program on the right is a
modification from the one in the
previous slide.
• Prints information once every 11
frames.
• The modulo operation was
substituted by “greater than”
check.
Getting Blocks too often Version 1
• Calling the function Get
Objects to often may
falsely return 0 objects
when objects are present.
• The frame rate of Pixy is
20 ms. You should not call
twice in the same period.
• The program on the right
returns – 1 when you call
the function again in less
than 20 ms.
Getting Blocks too often Version 1
• With and object with
signature 1 in front of the
camera, Run the program
and watch the output in
the serial monitor.
• To re-run, please press
reset button first.
• Change .02 to .001 (1 ms)
and repeat.
• What is the difference?.
Getting Blocks too
often Version 2
• Another version of this
program without using
Block functions.
Example 2
• Everything together
• In this case we set, MaxBlocks 2,
MaxBlocks per signature 1.
• We use mBot to track an object
with signature 1.
• Please note that the Arduino is
detecting one object, but the
index for that object is 0
• See video at:
https://youtu.be/pmbLD0JBqyw
Example 3
• The program in next slide will sequentially track signature 1 and then get
away from signaturen2 by turning left.
• In this case we set, MaxBlocks 2, MaxBlocks per signature 1, Min block area
40.
• After pressing the button, the robot will track signature 1 until it has been
centered or away for more than 3 seconds, after that a tone is played.
• Then the robot will get away from signature 2, until it is not visible for 3
seconds, a different tone is played and the program stops.
• A video demonstrating this program can be found at:
https://youtu.be/9Ury4ilYpew
Example 4
• The program in next slide will rotate to find signature 1 and then move
towards it.
• In this case we set, MaxBlocks 2, MaxBlocks per signature 1, Min block area
40.
• After pressing the button, the robot will rotate to find signature 1 until it
has been centered then moves towards signature 1.
• The “y” value of the object is use to stop the robot, it must be adjusted for
the particular camera height.
• The scoreGoal function must be developed, it may be very similar to the
getBall function.
• A video demonstrating this program can be found at:
https://www.youtube.com/watch?v=GdPtPGIU5Fk

You might also like