Hello,
I am tryin to use the Arduino MS-12A board with an Arduino Giga but with no success. I keep encountering various error messages and I did not find solutions yet on the forum.
I used the example code
/**
- \par Copyright ©, 2012-2016, MakeBlock
- @file SmartServoTest.ino
- @author MakeBlock
- @version V1.0.0
- @date 2016/08/31
- @brief Description: this file is sample code for Smart servo device.
- Function List:
-
- boolean MeSmartServo::assignDevIdRequest(void);
-
- boolean MeSmartServo::moveTo(uint8_t dev_id,long angle_value,float speed);
-
- boolean MeSmartServo::move(uint8_t dev_id,long angle_value,float speed);
-
- long MeSmartServo::getAngleRequest(uint8_t devId);
-
- float MeSmartServo::getSpeedRequest(uint8_t devId);
-
- float MeSmartServo::getVoltageRequest(uint8_t devId);
-
- float MeSmartServo::getTempRequest(uint8_t devId);
-
- float MeSmartServo::getCurrentRequest(uint8_t devId);
- \par History:
-
- Mark Yan 2016/08/31 1.0.0 build the new
*/
//#include <SoftwareSerial.h>
#include “MeOrion.h”
#include “MeSmartServo.h”
MeSmartServo mysmartservo(uint8_t TX3, uint8_t RX3); //UART2 is on port 5
long loopTime = 0;
void setup() {
Serial.begin(115200);
mysmartservo.begin(115200);
delay(5);
mysmartservo.assignDevIdRequest();
delay(50);
Serial.println(“setup!”);
loopTime = millis();
}
void loop() {
mysmartservo.moveTo(1, 360, 50); //device ID, angle, speed; absolute angle move;
loopTime = millis();
while (millis() - loopTime < 2000) {
Serial.print(“angle:”);
Serial.print(mysmartservo.getAngleRequest(1));
Serial.print(" speed:");
Serial.print(mysmartservo.getSpeedRequest(1));
Serial.print(" voltage:");
Serial.print(mysmartservo.getVoltageRequest(1));
Serial.print(" temp:");
Serial.print(mysmartservo.getTempRequest(1));
Serial.print(" Current:");
Serial.println(mysmartservo.getCurrentRequest(1));
}
mysmartservo.move(1, -360, 50); //device ID, angle, speed; relative angle move;
loopTime = millis();
while (millis() - loopTime < 2000) {
Serial.print(“angle:”);
Serial.print(mysmartservo.getAngleRequest(1));
Serial.print(" speed:");
Serial.print(mysmartservo.getSpeedRequest(1));
Serial.print(" voltage:");
Serial.print(mysmartservo.getVoltageRequest(1));
Serial.print(" temp:");
Serial.print(mysmartservo.getTempRequest(1));
Serial.print(" Current:");
Serial.println(mysmartservo.getCurrentRequest(1));
}
}
I have the latest version of the github branch “Makeblock Drive Update 3.27.1”
I first encountered an error on Software Serial, as there is plenty of hardware serial port on the Giga, I switched to one. Then added the meOrion and meSmartServo headers. No I encounter an error on the incompatibility with a non avr board
fatal error: avr/eeprom.h: No such file or directory
#include <avr/eeprom.h>
^~~~~~~~~~~~~~
compilation terminated.
exit status 1
Compilation error: exit status 1
I juste wish to use the MakeBlock Ms-12 motor to have a feedback on the angle position and set the motor to specific angles. I already have a draft code for this purpose
#include <Servo.h>
// Constants for servo configuration
const int servo_pin = 9; // Pin where servo is connected
const int goAngle = 67; // Target angle for “go” condition (degrees)
const int noGoAngle = 114; // Target angle for “no-go” condition (degrees)
const int startAngle = 0; // Starting position (degrees)
const int minAngle = 0;
const int maxAngle = 180;
//Servo object declaration
Servo myservo;
// Timing constants (milliseconds)
const long updateInterval = 15; //updating interval of 15ms to update position
long stim_duration = 5000; // interval of 2000ms staying at the first position
long return_duration = 2000; //interval of 1000ms of the stim staying at the return position for the linear translation going back to starts
int currentPosition = startAngle; //variable storing the current position
unsigned long lastMoveTime = 0; //variable storing a timer for the move
/*
*In the setup we initialize the servo motor as well as the serial communication with the computer
*/
void setup(){
myservo.attach(servo_pin);
Serial.begin(9600);
// Initialize servo to start position
myservo.write(startAngle);
currentPosition = startAngle;
}
/*
*With the move servo function
* We create a function to move the servo motor with a smooth acceleation and precise timing
* @param
* @param targetAngle : Desired angle to move to (0-180 degrees)
* @hold
*/
// In void moveServo we create a function to the defined end position including multiple timers.
//the timer with UpdatePosInterval allows for a smooth movement of the motor
// The motor will the end position, hold the position before going back the the Start position and hold the start position for an amount of time
void moveAngle(int targetAngle, unsigned long hold_time){
targetAngle = constrain(targetAngle, minAngle, maxAngle);
unsigned long startTime = millis();
// Move to target position with position verification
Serial.print("Moving to angle: ");
Serial.println(targetAngle);
while(currentPosition != targetAngle){
if(millis() - lastMoveTime >= updateInterval){
if(currentPosition < targetAngle){
currentPosition ++;
}else if (currentPosition > targetAngle){
currentPosition --;
}
myservo.write(currentPosition);
lastMoveTime = millis();
// Debug output
Serial.print("Current position: ");
Serial.println(currentPosition);
}
yield();
}
// Hold position
Serial.println("Holding position");
unsigned long holdStartTime = millis();
while(millis() - holdStartTime < hold_time){
myservo.write(currentPosition); //holds the motor in its currentPosition
yield();
}
}
void moveServo(int targetAngle){
moveAngle(targetAngle, stim_duration);
moveAngle(startAngle, return_duration);
}
// In void Go we create a function to go to the noGo position including
void go(){
moveServo(goAngle);
}
// In void Go we create a function to go to the noGo position including
void noGo(){
moveServo(noGoAngle);
}
/**
*Code using the random function to do a random number of rotation to a random position and back
*This will bring variability in between the trails so the mouse cannot guess the position of the stimulus
- @param numRotations: Number of random movements (1-5)
*/
//Code using the random function to do a random number of rotation to a random position and back
// This will bring variability in between the trails so the mouse cannot guess the position of the stimulus
void randomMove(){
int rotations = random(1,6); //1 to 5 rotations
for (int i = 0; i<= rotations; i++){
int randAngle = random(minAngle, maxAngle);
moveServo(randAngle);
}
}
//Main loop, in which we can devise a sequence of movement of the servomotor to the go and no go position
void loop(){
go();
randomMove();
noGo();
}