智能小车制作过程全纪录: 六、软件平台--- 摄像头云台控制

更多创客作品,请关注笔者网站园丁鸟,搜集全球极具创意,且有价值的创客作品


摄像头云台采用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();
			}
	
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DiegoRobot

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值