Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 2 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
|
All the information has been provided in the video given below.
Video will be available in few hours...
//Modied By ProfessorHulk
//The One and Only Smasher Tech (TOAOST)
//Install AFMotor.h library before uploading code to Arduino Board
//Install MuVisionSensor.h and Wire.h library before uploading code to Arduino Board
#include <Arduino.h>
#include <MuVisionSensor.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <AFMotor.h>
AF_DCMotor M1 (1, MOTOR12_1KHZ); //For Motor 1
AF_DCMotor M4 (4, MOTOR34_1KHZ);// For Motor 4
/*
* Choose communication mode define here:
* I2C_MODE : I2C mode, default pin: MU_SDA <==> ARDUINO_SDA, MU_SCL <==> ARDUINO_SCL
* SERIAL_MODE : Serial mode, default pin: MU_TX <==> ARDUINO_PIN3, MU_RX <==> ARDUINO_PIN2
*/
#define SERIAL_MODE
/*
* Choose MU address here: 0x60, 0x61, 0x62, 0x63
* default address: 0x60
*/
#define MU_ADDRESS 0x60
#ifdef SERIAL_MODE
#define TX_PIN 10
#define RX_PIN 9
SoftwareSerial mySerial(RX_PIN, TX_PIN);
#endif
MuVisionSensor Mu(MU_ADDRESS);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
uint8_t err = MU_ERROR_FAIL;
#ifdef I2C_MODE
Wire.begin();
// initialized MU on the I2C port
err = Mu.begin(&Wire);
#elif defined SERIAL_MODE
mySerial.begin(9600);
// initialized MU on the soft serial port
err = Mu.begin(&mySerial);
#endif
if (err == MU_OK) {
Serial.println("MU initialized.");
} else {
do {
Serial.println("fail to initialize MU! Please check protocol "
"version or make sure MU is working on the "
"correct port with correct mode.");
delay(5000);
} while (1);
}
// enable vision: number card
Mu.VisionBegin(VISION_TRAFFIC_CARD_DETECT);
}
// Forward Direction
void move_forward() {
M1.setSpeed(255);
M1.run(FORWARD);
M4.setSpeed(255);
M4.run(FORWARD);
delay(1000);
M1.run(RELEASE);
M4.run(RELEASE);
}
// LEFT Direction
void move_left() {
M1.setSpeed(255);
M1.run(FORWARD);
M4.setSpeed(255);
M4.run(BACKWARD);
delay(430);
M1.run(RELEASE);
M4.run(RELEASE);
}
// RIGHT Direction
void move_right() {
M1.setSpeed(255);
M1.run(BACKWARD);
M4.setSpeed(255);
M4.run(FORWARD);
delay(430);
M1.run(RELEASE);
M4.run(RELEASE);
}
// Stop
void move_stop() {
M1.setSpeed(0);
M1.run(RELEASE);
M4.setSpeed(0);
M4.run(RELEASE);
}
void loop() {
// put your main code here, to run repeatedly:
long time_start = millis();
// read result
if (Mu.GetValue(VISION_TRAFFIC_CARD_DETECT, kStatus)) { // update vision result and get status, 0: undetected, other: detected
Serial.println("vision shape card detected:");
Serial.print("x = ");
Serial.println(Mu.GetValue(VISION_TRAFFIC_CARD_DETECT, kXValue)); // get vision result: x axes value
Serial.print("y = ");
Serial.println(Mu.GetValue(VISION_TRAFFIC_CARD_DETECT, kYValue)); // get vision result: y axes value
Serial.print("width = ");
Serial.println(Mu.GetValue(VISION_TRAFFIC_CARD_DETECT, kWidthValue)); // get vision result: width value
Serial.print("height = ");
Serial.println(Mu.GetValue(VISION_TRAFFIC_CARD_DETECT, kHeightValue)); // get vision result: height value
Serial.print("label = ");
switch (Mu.GetValue(VISION_TRAFFIC_CARD_DETECT, kLabel)) { // get vision result: label value
case MU_TRAFFIC_CARD_FORWARD:
move_forward();
Serial.println("forward");
break;
case MU_TRAFFIC_CARD_LEFT:
move_left();
Serial.println("left");
break;
case MU_TRAFFIC_CARD_RIGHT:
move_right();
Serial.println("right");
break;
case MU_TRAFFIC_CARD_TURN_AROUND:
move_left();
move_left();
Serial.println("turn around");
break;
case MU_TRAFFIC_CARD_PARK:
//park();
Serial.println("park");
break;
default:
move_stop();
Serial.print("unknow card type: ");
Serial.println(Mu.GetValue(VISION_TRAFFIC_CARD_DETECT, kLabel));
break;
}
} else {
Serial.println("vision shape card undetected.");
}
Serial.print("fps = ");
Serial.println(1000/(millis()-time_start));
Serial.println();
}
//Modied By ProfessorHulk
//The One and Only Smasher Tech (TOAOST)
//Install AFMotor.h library before uploading code to Arduino Board
//Install MuVisionSensor.h and Wire.h library before uploading code to Arduino Board
#include <Arduino.h>
#include <MuVisionSensor.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <AFMotor.h>
AF_DCMotor M1 (1, MOTOR12_1KHZ);
AF_DCMotor M4 (4, MOTOR34_1KHZ);
/*
* Choose communication mode define here:
* I2C_MODE : I2C mode, default pin: MU_SDA <==> ARDUINO_SDA, MU_SCL <==> ARDUINO_SCL
* SERIAL_MODE : Serial mode, default pin: MU_TX <==> ARDUINO_PIN3, MU_RX <==> ARDUINO_PIN2
*/
#define I2C_MODE
/*
* Choose MU address here: 0x60, 0x61, 0x62, 0x63
* default address: 0x60
*/
#define MU_ADDRESS 0x60
#ifdef SERIAL_MODE
#endif
MuVisionSensor Mu(MU_ADDRESS);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
uint8_t err = MU_ERROR_FAIL;
#ifdef I2C_MODE
Wire.begin();
// initialized MU on the I2C port
err = Mu.begin(&Wire);
#elif defined SERIAL_MODE
mySerial.begin(9600);
// initialized MU on the soft serial port
err = Mu.begin(&mySerial);
#endif
if (err == MU_OK) {
Serial.println("MU initialized.");
} else {
do {
Serial.println("fail to initialize MU! Please check protocol "
"version or make sure MU is working on the "
"correct port with correct mode.");
delay(5000);
} while (1);
}
// enable vision: number card
Mu.VisionBegin(VISION_SHAPE_CARD_DETECT);
}
void loop() {
// put your main code here, to run repeatedly:
long time_start = millis();
// read result
if (Mu.GetValue(VISION_SHAPE_CARD_DETECT, kStatus)) { // update vision result and get status, 0: undetected, other: detected
Serial.println("vision shape card detected:");
Serial.print("x = ");
Serial.println(Mu.GetValue(VISION_SHAPE_CARD_DETECT, kXValue)); // get vision result: x axes value
Serial.print("y = ");
Serial.println(Mu.GetValue(VISION_SHAPE_CARD_DETECT, kYValue)); // get vision result: y axes value
Serial.print("width = ");
Serial.println(Mu.GetValue(VISION_SHAPE_CARD_DETECT, kWidthValue)); // get vision result: width value
Serial.print("height = ");
Serial.println(Mu.GetValue(VISION_SHAPE_CARD_DETECT, kHeightValue)); // get vision result: height value
Serial.print("label = ");
switch (Mu.GetValue(VISION_SHAPE_CARD_DETECT, kLabel)) { // get vision result: label value
case MU_SHAPE_CARD_TICK:
Serial.println("tick");
break;
case MU_SHAPE_CARD_CROSS:
Serial.println("cross");
break;
case MU_SHAPE_CARD_CIRCLE:
Serial.println("circle");
break;
case MU_SHAPE_CARD_SQUARE:
move_forward();
move_left_Square();
move_forward();
move_left_Square();
move_forward();
move_left_Square();
move_forward();
move_left_Square();
Serial.println("square");
break;
case MU_SHAPE_CARD_TRIANGLE:
Serial.println("triangle");
move_forward();
move_left_Triangle();
move_forward();
move_left_Triangle();
move_forward();
move_left_Triangle();
break;
default:
move_stop();
Serial.print("unknow card type: ");
Serial.println(Mu.GetValue(VISION_SHAPE_CARD_DETECT, kLabel));
break;
}
} else {
Serial.println("vision shape card undetected.");
}
Serial.print("fps = ");
Serial.println(1000/(millis()-time_start));
Serial.println();
}
// Forward Direction
void move_forward() {
M1.setSpeed(255);
M1.run(FORWARD);
M4.setSpeed(255);
M4.run(FORWARD);
delay(1000);
M1.run(RELEASE);
M4.run(RELEASE);
}
// LEFT Direction for Square Shape
void move_left_Square() {
M1.setSpeed(255);
M1.run(FORWARD);
M4.setSpeed(255);
M4.run(BACKWARD);
delay(470);
M1.run(RELEASE);
M4.run(RELEASE);
}
// LEFT Direction for Triangle Shape
void move_left_Triangle() {
M1.setSpeed(255);
M1.run(FORWARD);
M4.setSpeed(255);
M4.run(BACKWARD);
delay(580);
M1.run(RELEASE);
M4.run(RELEASE);
}
// RIGHT Direction
void move_right() {
M1.setSpeed(255);
M1.run(BACKWARD);
M4.setSpeed(255);
M4.run(FORWARD);
delay(500);
M1.run(RELEASE);
M4.run(RELEASE);
}
// Stop
void move_stop() {
M1.setSpeed(0);
M1.run(RELEASE);
M4.setSpeed(0);
M4.run(RELEASE);
}
Comments