Search

[OTHERS] #For Makers# MU-Arduino_UART_tutorial

Multra Post time 2016-12-30 17:31:22 |
Introduction
  As a vision sensor,MU can directly control servos and export data.Long press MU mode button to switch to vision sensor mode. In this mode, MU will detect pictures and export data without receiving commands.Short press the mode button to switch to setup mode, in which mode developers can set up parameters through UART commands.

About the detected data
  MU can recognize the object and return the current X and Y coordinates,varying from 0 to 100.MU Object detecting function is just like the selfie mode in cellphone,and a human face is detected and shown in a white rectangle.
  Once the “Vision Sensor” is in the running mode, it will keep emitting detection results once per video frame based on the current setting. The Vision Detection Result Output format is a binary format with a length of 9 bytes:

1.jpg

0xFF: Header byte 1
0xFE: Header byte 2
Detected: Whether the detection target is found in the current frame, 1: detected, 0: not detected
Score H8: The high 8 bit of the detection score (if target is detected).
Score L8: The low 8 bit of the detection score. (if target is detected).
X: X (horizontal) coordinate of the center of the detection rectangle, in the range of [0, 100].
Y: Y (vertical) coordinate of the center of the detection rectangle, in the range of [0, 100].
Width: The width of the detection rectangle, in the range of [0, 100].
Height: The height of the detection rectangle, in the range of [0, 100].

Note that X, Y, Width, Height use relative coordinates with respect to the width and height of the image frame. As show in this figure:

2.jpg

MU hardware ports
  MU has micro-USB port to connect to computer.Remove MU’s helmet and there are two lines of IO ports.
3.jpg

4.jpg
Multiplex ports:
  IO1-2 and 2-2 are GND port.
  IO1-2/1-3/1-4 and IO2-2/2-3/2-4 can be used as two sets of servo connectors to create a 2-degree-of-freedom vision sensor platform in servo submode.
  IO1-4 can be used as TX port to output data in UART submode.

Process of sending commands
  Download a serial software to transport data through MU and Arduino.
  Start up MU,Long press the mode button several times to switch to vision sensor mode.Then short press to switch to setup mode. Now you can connect MU to computer through micro-USB cable. Select the COM port and set baud rate to 115200.Then you can send commands to change settings.
  For example,send CMD+SENSOR_SETUP.Some software may need an enter key as an end key while others dont.If there is an error in sending command, you can try add or remove enter.
  If the command is right,MU will return a string such as Setup Mode.
5.jpg
  Now MU is in setup mode.Keep on sending command to set parameters.
  For example, in order to set MU to detect ball, you should send following commands:
CMD+VISION_TYPE=BALL
CMD+UART_STATUS=ENABLE
  You can send CMD+SENSOR_STATUS to watch all the current status.
  Finally, send CMD+SENSOR_EXIT. MU will save these settings and exit.

Hardware connection
  Remove MU’s helmet, connect its TX(IO1-4) port with RX port on arduino board . Then connect GND port together.
6.jpg
  Copy Vision_Sensor library into arduino libraries folder, open GetPosition.ino in the example folder and download to arduino board.
  If all the steps are right, you can see the data in arduino serial monitor.

7.jpg

MU-Arduino_UART_tutorial.rar (48.94 KB, Downloads: 22)
Reply

Use magic Report

Munsie Post time 2017-01-11 08:36:16 |
Thanks for posting this little tutorial. I downloaded the included RAR archive and found your handy serial comms utility inside. I configured the Mu as suggested and got the comms working.
I tend to find that sometimes there is no reply to commands I send. Sending a 2nd time gives ERROR and after that it works. Example:
After entering setup with CMD+SENSOR_SETUP I send CMD+SENSOR_STATUS, which gives:

Current Settings:
CMD+VISION_STATUS=ENABLE
CMD+VISION_TYPE=BODY
CMD+USB_STATUS=DISABLE
CMD+UART_STATUS=ENABLE
CMD+UART_BAUD=115200
and Data bits:8 Stop bits:1 Parity:NONE
CMD+SERVOX_STATUS=DISABLE
CMD+SERVOX_INITANGLE=90
CMD+SERVOX_STEP=10
CMD+SERVOX_REVERSE=DISABLE
CMD+SERVOY_STATUS=DISABLE
CMD+SERVOY_INITANGLE=90
CMD+SERVOY_STEP=10
CMD+SERVOY_REVERSE=DISABLE


Then I send  CMD+VISION_TYPE=BALL


Vision Type is BALL


Then CMD+SENSOR_STATUS which giver error:
Set ERROR
Your input command is:
ON_TYPE=BALL
CMD+SENSOR_STATUS
CM


Seems like you don't clear the receive buffer after receiving and reading a set CMD. Sending CMD+SENSOR_STATUS again:

Set ERROR
Your input command is:
D+SENSOR_STATUS
CMD+SENSOR_STATUS


Sending CMD+SENSOR_STATUS for a 3rd time:
Current Settings:
CMD+VISION_STATUS=ENABLE
CMD+VISION_TYPE=BALL
CMD+USB_STATUS=DISABLE
CMD+UART_STATUS=ENABLE
CMD+UART_BAUD=115200
and Data bits:8 Stop bits:1 Parity:NONE
CMD+SERVOX_STATUS=DISABLE
CMD+SERVOX_INITANGLE=90
CMD+SERVOX_STEP=10
CMD+SERVOX_REVERSE=DISABLE
CMD+SERVOY_STATUS=DISABLE
CMD+SERVOY_INITANGLE=90
CMD+SERVOY_STEP=10
CMD+SERVOY_REVERSE=DISABLE


Repeatable. I'll upgrade the firmware to see if the problem is still there.
Reply Support Not support

Use magic Report

Munsie Post time 2017-01-11 23:10:08 |
I will try to connect via the Arduino UNO board as described in section "Hardware connection" onco I receive my UNO board.

In the meantime I have the Makeblock mBot board, called "mCore", which is Arduino based. If you look carefully at the diagram on the  mCore product page you can see that the Wireless Module has a RX connector. Perhaps this RX connector could be used to connect the Mu to mBots? Have you tried this? It is worth considering connecting the Mu to the Makeblock robot products.
Reply Support Not support

Use magic Report

 Author| Multra Post time 2017-01-12 18:06:47 |
Munsie replied at 2017-01-11 08:36
Thanks for posting this little tutorial. I downloaded the included RAR archive and found your handy  ...

Serial Interface is an old and simple software, and sometimes it makes strange mistakes.It will lose some words and send a wrong command.
You send CMD+SENSOR_STATUS but get an error:
Set ERROR
Your input command is:
ON_TYPE=BALL
CMD+SENSOR_STATUS
CM

Software actually send a wrong command. There is a"clear"button beside the "send".Click it after sending a command may help.Or you can change a better Serial software.
Reply Support Not support

Use magic Report

 Author| Multra Post time 2017-01-12 18:26:30 |
Munsie replied at 2017-01-11 23:10
I will try to connect via the Arduino UNO board as described in section "Hardware connection" onco I ...

Whatever board you use, serial connection is the same.But perhaps you need a new library because of some pin difference.I think the mCore board can still use the library.This library is used to  explain data, and you can use the detected data directly in ino file.Serial monitor can record the data.
Reply Support Not support

Use magic Report

Munsie Post time 2017-01-13 18:48:59 |
Multra replied at 2017-01-12 18:06
Serial Interface is an old and simple software, and sometimes it makes strange mistakes.It will lo ...

OK, thanks. I will use PuTTY instead
Reply Support Not support

Use magic Report

Munsie Post time 2017-01-24 06:37:04 |
I upgraded the firmware and in SENSOR_SETUP mode the error reporting is better. More explanation. I downloaded "Serial Port Utility" from Darkwood Studio. Better suited than PuTTY for this job. After each command you have to make sure to press the <Enter> key, in SPU select the option "Auto Feed Line" and then press <Send>. Failing to add <Cr><Lf> causes the Mu not to process the command, causing some traffic jam in the Mu in-tray. The next command will go wrong then as well as it in concatenated to the first one, so the total command string is invalid. Anyway, I have it working now.
Reply Support Not support

Use magic Report

Munsie Post time 2017-01-24 07:32:21 |
I have the serial communication via Arduino working, as per your section "Hardware Connection". Firstly I had to solder in 2x 4 pins in the Mu's communication ports. Then fit the PCB carefully into the housing. The 2x 4 pins will stick out from the two slots as per the photo.

Connect the Mu to the Arduino via the Arduino RX port (see photo), compile and upload the Mu GetPosition scetch to the Arduino and run that. Again, with the "Serial Port Utility" mentioned in my previous post I open the COM port and Mu's messages start to roll in.
No object detected

or:
detected score is:984
Object detected at:51,31 with wdith of:41 and height of:54

Happy that it works!
Reply Support Not support

Use magic Report

Munsie Post time 2017-01-24 07:57:32 |
I like the Vision_Sensor library that you made for the Arduino. It allows the creation of a "VisionSensor" object which properties can be queried. This encapsulates the communication with the Mu very neatly. The interface as seen in the test program:

#include "VisionSensor.h"
VisionSensor MU(Serial, 115200);     /* Create the VisionSensor object and initialises the Arduino Serial Comms with Mu */

  MU.begin()      /* Sets Mu in Vision Sensor mode */
  MU.search()     /* get data from the Mu */   
  MU.valid()      /* if > 0 we got good data */
  MU.detected()   /* if "true" then Mu has seen something */
  MU.detectScore()  /* score of the item with the highest detection score */
  MU.getX()       /* getX() means X (horizontal) coordinate of the center of the detection rectangle */
  MU.getY()       /* getY() means Y (vertical) coordinate of the center of the detection rectangle */
  MU.getWidth()   /* Width of the detection rectangle */
  MU.getHeight()  /* Height of the detection rectangle */


Not sure if there are any more methods. My comments make deduction of what the interface methods do, as seen from the program logic.
Reply Support Not support

Use magic Report

Munsie Post time 2017-01-25 07:36:21 |
Multra replied at 2017-01-12 18:26
Whatever board you use, serial connection is the same.But perhaps you need a new library because o ...

I can confirm that the Hardware Connection also works with the Makeblock mCore board. The RX connector on this board sits under the Wireless Module connector which I had to remove. The "GetPosition" scetch works then unmodified. Mu was in Vision Sensor mode. Wow!

Time to give some eyes to my Makeblock mBot!
Reply Support Not support

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Multra

Threads

Posts

64

Credits
FORUM NAVIGATION
Copyright © 2017 Morpx All rights reserved 浙ICP备14027877号
Quick Reply To Top Return to the list