基于SnapDragonBoard410c的智能小车(一)

今天我就基于高通410c的开发板开发的智能小车给大家分享下我们的开发过程。在开发中遇到最大的问题就是我么的智能小车是采用舵机控制的,导致我们往里面写一个值的时候电机一直以这个值做功。正因为如此,我们便开始编写自己的壁障算法——这当然要借助于超声波模块。

我们的智能小车的硬件组成有四个超声波模块,和小车。
我们的智能小车如没有自己的壁障算法,就很有可能出现下面的情况

这里写图片描述

我们先要读取超声波节点的数据:

 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;
    }

壁障规避:

  timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                String a[] = Config.location().split("@");
                if (a[0].equals("1")) {
                    if (a[2].equals("3")){
                        Api.right(15000000);
                    }else if (a[3].equals("4")){
                        Api.left(15000000);
                    }
                }
            }
        }, 0, 200);

更改运行状态:

   private static String leftback = "/sys/class/pwm/pwmchip1/pwm0/duty";
    private static String leftforward = "/sys/class/pwm/pwmchip1/pwm1/duty";
    private static String rightforward = "/sys/class/pwm/pwmchip1/pwm2/duty";
    private static String rightback = "/sys/class/pwm/pwmchip1/pwm3/duty";
    private static String voice = "/sys/devices/soc.0/sonar.*/value";
    private static String red_light = "/sys/devices/soc.0/ir-red.*/value";

    public static void forward(long speeed) {
        stop();
        Config.WriteData(leftforward, "" + speeed);
        Config.WriteData(rightforward, "" + speeed);
    }

    public static void back(long speeed) {
        stop();
        Config.WriteData(leftback, "" + speeed);
        Config.WriteData(rightback, "" + speeed);
    }

    public static void left(long speeed) {
        stop();
        Config.WriteData(leftforward, "" + 0);
        Config.WriteData(rightforward, "" + speeed);
    }

    public static void right(long speeed) {
        stop();
        Config.WriteData(leftforward, "" + speeed);
        Config.WriteData(rightforward, "" + 0);
    }

    public static void stop() {
        Config.WriteData(leftback, "" + 0);
        Config.WriteData(leftforward, "" + 0);
        Config.WriteData(rightforward, "" + 0);
        Config.WriteData(rightback, "" + 0);
    }

猜你喜欢

转载自blog.csdn.net/u013763766/article/details/78742135