Qualcomm技术william hill官网
直播中

丁兵溢

7年用户 179经验值
私信 关注
[经验]

基于SnapDragonBoard410C的机械臂(一)

今天我就基于高通410c的开发板开发的机械臂给大家分享下我们的开发过程。在开发中遇到最大的问题就是我么的智能小车是采用舵机控制的,导致我们往里面写一个值的时候电机一直以这个值做功。所以我们每次进行控制的时候都要先给每个点击上电,让每个电机都工作起来。



我们的谁被有6个电机分别为其分配了6个驱动节点分别如下:

private static String one = "/sys/class/pwm/pwmchip1/pwm4/duty";//500000-2700000
private static String two = "/sys/class/pwm/pwmchip1/pwm5/duty";//1000000-2300000
private static String three = "/sys/class/pwm/pwmchip1/pwm6/duty";//500000-26500000
private static String four = "/sys/class/pwm/pwmchip1/pwm7/duty";//800000-2800000
private static String five = "/sys/class/pwm/pwmchip1/pwm8/duty";//500000-2600000
private static String six = "/sys/class/pwm/pwmchip1/pwm9/duty";//600000-1600000
节点操作工具:

public static void WriteData(String path, String content) {
FileOutputStream fos = null;
File file = new File(path);
if (file.exists()) {
try {
fos = new FileOutputStream(file);
Log.e("File", "FileWriter" + content);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
byte[] array = content.getBytes();
try {
fos.write(array);
} catch (IOException e) {
e.printStackTrace();
}
try {
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static String Redata(String path) {
String content = new String();
String line = new String();
InputStreamReader is = null;
File file = new File(path);
if (file.exists()) {
try {
is = new InputStreamReader(new FileInputStream(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader bufferedReader = new BufferedReader(is);
try {
while ((line = bufferedReader.readLine()) != null) {
content = content + line;
}
} catch (IOException e) {
e.printStackTrace();
}
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return content;
}
主要的逻辑:

one.setProgress(50);
two.setProgress(50);
three.setProgress(50);
four.setProgress(50);
five.setProgress(50);
six.setProgress(50);
//每个电机在设置一个progres***ar 如下:
private void initevent() {
one.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (!isfirst) {
Config.writeALL(0);
isfirst = true;
}
Config.writeARM(1, 500000 + 22000 * progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
two.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (!isfirst) {
Config.writeALL(0);
isfirst = true;
}
Config.writeArm(2, 500000 + 22000 * progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
three.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (!isfirst) {
Config.writeALL(0);
isfirst = true;
}
Config.writeArm(3, 500000 + 22000 * progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
four.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (!isfirst) {
Config.writeALL(0);
isfirst = true;
}
Config.writeArm(4, 500000 + 22000 * progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
five.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (!isfirst) {
Config.writeALL(0);
isfirst = true;
}
Config.writeArm(5, 500000 + 22000 * progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
six.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (!isfirst) {
Config.writeALL(0);
isfirst = true;
}
Config.writeArm(6, 500000 + 22000 * progress);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}

更多回帖

发帖
×
20
完善资料,
赚取积分