-
Notifications
You must be signed in to change notification settings - Fork 4
Description
I am trying to compile the code below for a robot using MU vision sensor. I have installed the MUvision sensor library.
The code below is a working code from https://www.hackster.io/professorhulk00/traffic-sign-and-shape-recognition-robot-81f3f7
//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();
}
I get the following error while compiling the code
Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"
C:\Users\alexf\Documents\Arduino\traffic_sign_recognition_robot.ino\traffic_sign_recognition_robot.ino.ino: In function 'void setup()':
traffic_sign_recognition_robot.ino:39:17: error: 'MU_ERROR_FAIL' was not declared in this scope
uint8_t err = MU_ERROR_FAIL;
^~~~~~~~~~~~~
C:\Users\alexf\Documents\Arduino\traffic_sign_recognition_robot.ino\traffic_sign_recognition_robot.ino.ino:39:17: note: suggested alternative: 'MU_SLAVE_FAIL'
uint8_t err = MU_ERROR_FAIL;
^~~~~~~~~~~~~
MU_SLAVE_FAIL
Multiple libraries were found for "SoftwareSerial.h"
Used: C:\Users\alexf\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\libraries\SoftwareSerial
Not used: C:\Users\alexf\Documents\Arduino\libraries\Dabble
exit status 1
'MU_ERROR_FAIL' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.