Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.17 KB | None | 0 0
  1. <!-- wp:heading {"level":1} -->
  2. <h1>Camera Module</h1>
  3. <!-- /wp:heading -->
  4.  
  5. <!-- wp:heading -->
  6. <h2>Note on the types of cameras</h2>
  7. <!-- /wp:heading -->
  8.  
  9. <!-- wp:paragraph -->
  10. <p>There are two primary types of cameras available for LEGO. The first is the PixyCam and the second is the NXTCam (which can be used for both NXT and EV3). The PixyCam has two very different versions -- the original Pixy and the Pixy for LEGO. Mindsensors produces a adapter that allows the original Pixy to be used with LEGO and programmed like a NXTCam. This recap content applies to the Pixy original with the Mindsensors adapter, however the programming section likely also works for the NXTCam and the setup portion will apply mostly to the Pixy for LEGO. A brief addition regarding Pixy for LEGO will be in the recap for reference. </p>
  11. <!-- /wp:paragraph -->
  12.  
  13. <!-- wp:heading -->
  14. <h2>PixyCam Setup</h2>
  15. <!-- /wp:heading -->
  16.  
  17. <!-- wp:list {"ordered":true} -->
  18. <ol><li>Download and install the PixyMon configuration software from <a href="https://pixycam.com/downloads/">https://pixycam.com/downloads/</a>. </li><li>Focus the camera. Turn the lens until the image becomes clear. </li><li>Plug in the PixyCam. The camera feed should begin streaming. Make sure the option for cooked video is set (the chef button on the top bar, next to the raw meat symbol and setting). </li><li>Configure the communication interface. Note this is different for PixyCam for LEGO. See <a href="https://www.stormingrobots.com/robotalk/viewtopic.php?f=108&amp;t=1135">Dennis’ post</a>. &nbsp;(Configure -&gt; Interface. Set data out protocol to UART and baud rate to 115200). </li><li>Configure the colors. Point your camera at a color you wish to detect. Action -&gt; set signature x. Drag the area of the color on the now frozen image. You can set one color per signature. </li></ol>
  19. <!-- /wp:list -->
  20.  
  21. <!-- wp:heading -->
  22. <h2>RobotC Drivers</h2>
  23. <!-- /wp:heading -->
  24.  
  25. <!-- wp:paragraph -->
  26. <p>Go to <a href="https://github.com/botbench/robotcdriversuite">https://github.com/botbench/robotcdriversuite</a>, click clone or download and download as zip. Extract the contents into the directory of your RobotC project. The relevant header is mindsensors-nxtcam.h. To include the driver, use “#include "robotcdriversuite-master/include/mindsensors-nxtcam.h"”, which points to the path of the file. </p>
  27. <!-- /wp:paragraph -->
  28.  
  29. <!-- wp:heading -->
  30. <h2>Programming</h2>
  31. <!-- /wp:heading -->
  32.  
  33. <!-- wp:paragraph -->
  34. <p>See the sample code located in robotcdriversuite-master/examples/mindsensors-nxtcam-test1.c. </p>
  35. <!-- /wp:paragraph -->
  36.  
  37. <!-- wp:paragraph -->
  38. <p>First, include the library, from there you must initialize the camera. Define a camera object of type tSensors and the value being the sensor port. For example, “tSensors cam = S1;”. From there simply call “NXTCAMinit(cam);”. </p>
  39. <!-- /wp:paragraph -->
  40.  
  41. <!-- wp:paragraph -->
  42. <p>To get the blobs, you must first declare a variable of type blob_array (“blob_array blobs;”), which you pass to the function “nblobs = NXTCAMgetBlobs(cam, blobs, condensed);”, where if condenser is true then the colliding blobs will be combined. </p>
  43. <!-- /wp:paragraph -->
  44.  
  45. <!-- wp:paragraph -->
  46. <p>Each element in a blob_array is of type blob, and has the following variables: x1 (the left bound), y1 (the upper bound), x2 (the right bound), y2 (the bottom bound), colour (the signature number), and size. </p>
  47. <!-- /wp:paragraph -->
  48.  
  49. <!-- wp:paragraph -->
  50. <p>There are also a number of auxiliary functions that can help with blob analysis, such as NXTCAMgetAverageCenter, which can be found in the header file that was included. </p>
  51. <!-- /wp:paragraph -->
  52.  
  53. <!-- wp:paragraph -->
  54. <p>A brief sample code has been provided below that initializes a camera and continually grabs the blobs and prints out the location and size of the biggest blob. </p>
  55. <!-- /wp:paragraph -->
  56.  
  57. <!-- wp:paragraph -->
  58. <p>#include "robotcdriversuite-master/include/mindsensors-nxtcam.h"</p>
  59. <!-- /wp:paragraph -->
  60.  
  61. <!-- wp:paragraph -->
  62. <p>task main()<br>{<br> &nbsp;&nbsp;&nbsp;tSensors cam = S1;<br> &nbsp;&nbsp;&nbsp;NXTCAMinit(cam);<br> &nbsp;&nbsp;&nbsp;blob_array blobs;<br> &nbsp;&nbsp;&nbsp;bool condensed = true;<br> &nbsp;&nbsp;&nbsp;while (true)<br> &nbsp;&nbsp;&nbsp;{<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;short nblobs = NXTCAMgetBlobs(cam, blobs, condensed);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (nblobs &gt; 0)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_sortBlobs(nblobs, blobs);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// blobs[0] is now the largest blob. <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayTextLine(1, "Number of blobs: %d", nblobs);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayTextLine(3, "Top left: (%d, %d)", blobs[0].x1, blobs[0].y1);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayTextLine(5, "Bottom right: (%d, %d)", blobs[0].x2, blobs[0].y2);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayTextLine(7, "Colour: %d", blobs[0].colour);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;displayTextLine(9, "Size: %d", blobs[0].size);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br> &nbsp;&nbsp;&nbsp;}<br>}<br></p>
  63. <!-- /wp:paragraph -->
  64.  
  65. <!-- wp:heading -->
  66. <h2>Pixy for LEGO</h2>
  67. <!-- /wp:heading -->
  68.  
  69. <!-- wp:paragraph -->
  70. <p>Firstly, for setup, when configuring the interface the actions are different. Make sure the interface is set to LEGO I2C, not UART. </p>
  71. <!-- /wp:paragraph -->
  72.  
  73. <!-- wp:paragraph -->
  74. <p>When programming the Pixy for LEGO, use the LEGO I2C functions. Documentation on the I2C registers can be found here: <a href="http://cmucam.org/documents/36">http://cmucam.org/documents/36</a>. Documenation on RobotC I2C functions can be found here: <a href="http://botbench.com/driversuite/group__common.html">http://botbench.com/driversuite/group__common.html</a>. </p>
  75. <!-- /wp:paragraph -->
  76.  
  77. <!-- wp:paragraph -->
  78. <p>An example code is below (has not yet been tested so it may not work exactly as expected): <br><br>#include "robotcdriversuite-master/include/common.h"<br>tByteArray msg;<br>tByteArray reply;<br><br>// "port" is just the sensor port, "reg" is the register you want info for (0x50 for general, 0x51 - 0x57 for specific signatures -- see documentation). The information you get back will be in the array "msg". <br>bool getInfo(tSensors port, ubyte reg)<br>{<br> &nbsp;&nbsp;&nbsp;short replyLen;<br> &nbsp;&nbsp;&nbsp;if (reg == 0x50)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;replyLen = 6;<br> &nbsp;&nbsp;&nbsp;if (reg &gt;= 0x51 &amp;&amp; reg &lt;= 0x57)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;replyLen = 5;<br> &nbsp;&nbsp;&nbsp;else<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br> &nbsp;&nbsp;&nbsp;memset(msg, 0, sizeof(msg));<br> &nbsp;&nbsp;&nbsp;msg[0] = reg;<br> &nbsp;&nbsp;&nbsp;bool result = writeI2C(port, msg, reply, replyLen);<br> &nbsp;&nbsp;&nbsp;return result;<br>}<br></p>
  79. <!-- /wp:paragraph -->
  80.  
  81. <!-- wp:heading -->
  82. <h2>Full Video</h2>
  83. <!-- /wp:heading -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement