uArm 基于硬件开源项目 Arduino 开发,因此对uArm进行调试或二次开发,则需要先安装Arduino开发环境。
Install Arduino (Just for Mac)
Download the Arduino Software at official website
Then install Arduino on Mac
Load uArm library for Arduino
Before you can control uArm , you must load uArm library for Arduino.
First, download Library uArmForArduino at github (https://github.com/uArm-Developer/UArmForArduino)
Second, move the download file to Arduino Library foler (/Arduino/libraries)
Started
Open Arduino IDE, build a new file,rename “MoveTest.ino” (or other name as you like),locate at your project fold.
The simple code for test move api.
#include "uArm_library.h" //name of uArm Library
#include <EEPROM.h>
#include <Wire.h>
#include <Servo.h>
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
}
void loop() {
uarm.moveTo(0,-10,20); //move to coordinate x=0, y=-10, z=20
exit(0); //exit the loop
}
The simple code for test get axis coordinate
#include "uArm_library.h" //name of uArm Library
#include <EEPROM.h>
#include <Wire.h>
#include <Servo.h>
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial port at 9600 bps
}
void loop() {
uarm.moveTo(0,-10,10); //move to coordinate x=0, y=-10, z=20
int x = uarm.getCalX(); // get axis coordinate
int y = uarm.getCalY();
int z = uarm.getCalZ();
Serial.print("The current location is ");
Serial.print(x);
Serial.print(" , ");
Serial.print(y);
Serial.print(" , ");
Serial.print(z);
delay(1000);
exit(0); //exit the loop
}
The simple code for telling uArm to move by communicating with serial port.(串口通信)
#include "uArm_library.h" //name of uArm Library
#include <EEPROM.h>
#include <Wire.h>
#include <Servo.h>
int x,y,z;
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial port at 9600 bps
}
void loop() {
if(Serial.available()>0)
{
char readSerial = Serial.read();
Serial.println(readSerial);
switch (readSerial)
{
case '1':
{
uarm.moveTo(10,-30,10);
break;
}
// case 2: move to a home position (x,y,z) = (0,-20,10)
case '2':
{
uarm.moveTo(0,-20,10);
break;
}
x = uarm.getCalX(); // get axis coordinate
y = uarm.getCalY();
z = uarm.getCalZ();
Serial.print("The current location is ");
Serial.print(x);
Serial.print(" , ");
Serial.print(y);
Serial.print(" , ");
Serial.print(z);
}
} // close read available
}