更多创客作品,请关注笔者网站园丁鸟,搜集全球极具创意,且有价值的创客作品
摄像头云台采用2自由度云台控制可以控制,淘宝很多商家都有卖,云台如下图
舵机控制板采用24路舵机控制板,通过串口发送指令控制舵机的控制,如下图
舵机类Servo.java 封装了舵机控制的基本属性,可以根据属性获取控制的命令
package com.diego.serialcomm;
public class Servo {
private int pos=500;
private int servoChanel=1;
private int durationTime=100;
public Servo(int pos, int servoChanel, int durationTime) {
super();
this.pos = pos;
this.servoChanel = servoChanel;
this.durationTime = durationTime;
}
public int getPos() {
return pos;
}
public void setPos(int pos) {
this.pos = pos;
}
public int getServoChanel() {
return servoChanel;
}
public void setServoChanel(int servoChanel) {
this.servoChanel = servoChanel;
}
public int getDurationTime() {
return durationTime;
}
public void setDurationTime(int durationTime) {
this.durationTime = durationTime;
}
public String getCMDWithTime(){
String rts="#";
rts+=servoChanel;
rts+="P"+pos+"T"+durationTime+"\r\n";
return rts;
}
public String GetCMDWithoutTime(){
String rts="#";
rts+=servoChanel;
rts+="P"+pos+"\r\n";
return rts;
}
}
ServoCMD.java类,封装了24路舵机的操作
package com.diego.serialcomm;
import java.util.ArrayList;
import java.util.List;
public class ServoCMD {
private SerialComm servoCMDComm;
private List<Servo> servoList=new ArrayList<Servo>();
public void openSAC(String portName){
servoCMDComm=new SerialComm();
try {
servoCMDComm.connect(portName);
System.out.println("******the SAC "+portName+" has been opened!");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void init(String portName,int servoCount){
openSAC(portName);
for(int i=1;i<=servoCount;i++){
Servo s=new Servo(500,i,100);
servoList.add(s);
}
}
public void servoControl(int chanel,int pos,int durationTime){
String cmds="";
if(chanel>servoList.size()){
System.out.println("there is not this chanel "+chanel);
return;
}
servoList.get(chanel-1).setPos(pos);
servoList.get(chanel-1).setDurationTime(durationTime);
cmds=servoList.get(chanel-1).getCMDWithTime();
servoCMDComm.setMsg(cmds);
}
public void servo1Control(int pos,int dotime){
servoControl(1,pos,dotime);
}
public void servo2Control(int pos,int dotime){
servoControl(2,pos,dotime);
}
public void servo3Control(int pos,int dotime){
servoControl(3,pos,dotime);
}
public void servo4Control(int pos,int dotime){
servoControl(4,pos,dotime);
}
public void servo5Control(int pos,int dotime){
servoControl(5,pos,dotime);
}
public void servo6Control(int pos,int dotime){
servoControl(6,pos,dotime);
}
public void servo7Control(int pos,int dotime){
servoControl(8,pos,dotime);
}
public void servo8Control(int pos,int dotime){
servoControl(8,pos,dotime);
}
public void servo9Control(int pos,int dotime){
servoControl(9,pos,dotime);
}
public void servo10Control(int pos,int dotime){
servoControl(10,pos,dotime);
}
public void servo11Control(int pos,int dotime){
servoControl(11,pos,dotime);
}
public void servo12Control(int pos,int dotime){
servoControl(12,pos,dotime);
}
public void servo13Control(int pos,int dotime){
servoControl(13,pos,dotime);
}
public void servo14Control(int pos,int dotime){
servoControl(14,pos,dotime);
}
public void servo15Control(int pos,int dotime){
servoControl(15,pos,dotime);
}
public void servo16Control(int pos,int dotime){
servoControl(2,pos,dotime);
}
public void servo17Control(int pos,int dotime){
servoControl(17,pos,dotime);
}
public void servo18Control(int pos,int dotime){
servoControl(18,pos,dotime);
}
public void servo19Control(int pos,int dotime){
servoControl(19,pos,dotime);
}
public void servo20Control(int pos,int dotime){
servoControl(20,pos,dotime);
}
public void servo21Control(int pos,int dotime){
servoControl(21,pos,dotime);
}
public void servo22Control(int pos,int dotime){
servoControl(22,pos,dotime);
}
public void servo23Control(int pos,int dotime){
servoControl(23,pos,dotime);
}
public void servo24Control(int pos,int dotime){
servoControl(24,pos,dotime);
}
public void test(){
try {
servo1Control( 1500,100);
Thread.sleep(1000);
servo2Control( 1500,100);
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}