Python
To look for markers callsee():
markers is a Python list of “marker objects”, which each look like the following:
Codes
Every april tag has a code:- April tags 0-31 will be used for cubes. They won’t all be used in each round.
- April tags 100+ will around the arena on the walls. See the rules for specifics on where around the rules they will be placed
- You do not need to use the marker numbers, and can instead use marker.type and marker.owning_team
Blockly
Blocks for vision can be found in the Vision section.Example
After reading the motors documentation you should be able to create a function which moves your robot by a number of meters as well as turn. We can then use this to write some code where a robot:- Looks for a marker
- If it can see a marker:
- Turn so that it is facing the marker
- Drive the distance to the marker
- If there is no marker in sight turn a bit and look again, maybe there is a marker out of view.
The Marker object
Details about the markers can be accessed using the following syntax:
Marker object contains information about a detected marker. It has the following attributes:
The Camera object
An interface to the camera is provided in case you want to do additional computer vision.
Changing the resolution
By default the camera takes pictures at a resolution of 640x480px. You can change this by setting theres parameter.
(640, 480)(default)(1296, 736)(1296, 976)(1920, 1088)(1920, 1440)
Get data straight from the camera
If you wish to do your own computer vision you can capture frames directly from the camera usingrobot.camera.capture().
Using USB cameras
The built-in Pi Camera inside your brain should be great for your robot, however if you would like to use your own USB Camera (perhaps you want to put a camera somewhere else on your robot), you can! USB cameras can have slightly different functionality than the built-in Pi Camera, so they’ll need some fine tuning before you can use them. The basic steps outlined below should get you up and running. Please turn your robot off before plugging in your USB Camera of choice. To use a USB camera you will need to initialize theRobot with something which inherits from robot.vision.Camera. Then just call R.see() as you would normally.
Setting the resolution
You may now wish to change the resolution of your camera, this can be done the same as before withR.camera.res = (width,height).
Some resolutions may not work with your USB camera, as different cameras support different resolutions. Check your camera’s documentation. If you try and use a resolution that your camera doesn’t support, you will get an error that will state the closest resolution to the value you attempted to use. Try changing your resolution to the value that the error message suggests!
800x600:
Calibrating the camera
You will then need to calibrate your USB camera as the distance that it reports will not be accurate. You can do this by changing the value in theR.camera.focal_lengths dictionary up or down. By default, the robot will use the focal lengths for a “Logitech C270” camera, it’s unlikely this is your camera - so see the steps below on how to calibrate it.
- Place a marker exactly 1m away from the camera (measure this distance). Make sure there are no other markers in sight of the camera.
- Copy and paste the following code into your editor. Please set the
resolutionvalue to a resolution you wish to use.
R.camera.res or R.see(). You can also copy the line of code it produces and paste that into your code to set the focal lengths.
For example, if your focal length was 123 at the resolution of 800x600, you should use the following lines of code, in the same order:
