Giter Club home page Giter Club logo

mavcomm's Introduction

MAVcomm

Java based proxy/hub for PX4 companions

Build Status

(Deprecated)

This Java based tool enables companions to be connected to PixHawk and serves as MAVLink proxy for QGC / MAVGC. Additionally MAVcomm can serve as central hub for distributed high-level flight control.

It also provides a MAVLink parser and a flat data model to https://github.com/ecmnet/MAVGCL and to the visual odometry https://github.com/ecmnet/MAVSlam.

Vehicle control is supported by a PX4 offboard manager.

Additionally, it offers an experimental LVH+ based autopilot (integrates with MAVSLAM), which provides local mapping and path planning as 2D proof of concept.

Supported companion platforms:

MAVComm supports any platform which is capable to run Java8 and can be connected to PixHawk or PixRacer via a high speed serial link.

It is currently tested with the following systems:

mavcomm's People

Contributors

ecmnet avatar natergator avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mavcomm's Issues

Not able to connect with Arducopter in SITL

Hello,

I am trying to connect to SITL with following details:

comm = MAVUdpCommNIO3.getInstance(model, "127.0.0.1",5760, 14550);
proxy = new MAVUdpProxyNIO3("127.0.0.1",5501,"0.0.0.0",14556,comm);
peerAddress = "127.0.0.1";
System.out.println("Proxy Controller loaded (SITL) ");

It got connected with SITL - ardupilot/Arduplane by running sim_vehicle.py.

Trying to give command in following manner:
msg_msp_status msg = new msg_msp_status(2,1);
msg.load = (int)(osBean.getSystemLoadAverage()*100);
msg.autopilot_mode = control.getCurrentModel().sys.autopilot;
msg.memory = (int)(mxBean.getHeapMemoryUsage().getUsed() * 100 /mxBean.getHeapMemoryUsage().getMax());
msg.com_error = control.getErrorCount();
msg.uptime_ms = System.currentTimeMillis() - tms;
msg.status = control.getCurrentModel().sys.getStatus();
msg.setVersion(config.getVersion());
msg.setArch(osBean.getArch());
msg.unix_time_us = control.getCurrentModel().sys.getSynchronizedPX4Time_us();
control.sendMAVLinkMessage(msg);
;

It gets connected with ArduPlane and mode changes from CIRCLE - RTL
Output in SITL:
APM: Ground start complete
online system 1
MANUAL> Mode MANUAL
APM: ArduPlane V3.8.2-dev (a629bb7f)
APM: Throttle failsafe on 767
APM: Failsafe. Short event on,
APM: Flight mode = 1
Flight battery 100 percent
Received 902 parameters
Saved 902 parameters to mav.parm
CIRCLE> APM: Airspeed sensor calibrated
Mode CIRCLE
APM: GPS 1: detected as u-blox at 115200 baud
APM: EKF2 IMU0 initial yaw alignment complete
APM: EKF2 IMU1 initial yaw alignment complete
APM: Init HOME
APM: Failsafe. Long event on,
APM: Flight mode = 11
RTL> Mode RTL
APM: EKF2 IMU0 tilt alignment complete
APM: EKF2 IMU1 tilt alignment complete
APM: EKF2 IMU0 Origin set to GPS
APM: EKF2 IMU1 Origin set to GPS
APM: EKF2 IMU0 is using GPS

I am not sure whether it is working correctly. Kindly confirm

Also trying same steps with ArduCopter (running sim_vehicle.py in ArduCopter) -- There is no change in mode or vehicle state.

Please suggest steps to connect MAVComm in SITL with ArduCopter. Kindly let me know if any configurational changes are required while using MAVComm with SITL.

Thanks in Advance.

Binding to all local addresses

Hi Eike,

Your tool is great. I changed the MAVUdpCommNIO class locally to bind to all local/brodcasted addresses using just the port number. This way peerAddress, peerPort, and bindAddress are not longer required. Here is my version. HTH and thanks again for making this too!

`

public class MAVUdpCommNIO implements IMAVComm {

    private DataModel model = null;
    private ByteChannel channel = null;
    private MAVLinkToModelParser parser = null;
    private boolean isConnected = false;
    private static MAVUdpCommNIO com = null;

    private AtomicReference<DatagramSocket> socketRef = new AtomicReference<>();
    private int serverPort;
    private int hostPort;
    private InetAddress hostAdd;
    private DatagramPacket sendPacket;
    private DatagramPacket receivePacket;

    public static MAVUdpCommNIO getInstance(DataModel model, String peerAddress, int peerPort, String bindAddress, int bindPort) {
        if (com == null) {
            com = new MAVUdpCommNIO(model, bindPort);
        }
        return com;
    }

    private MAVUdpCommNIO(DataModel model, int port) {
        this.model = model;
        this.parser = new MAVLinkToModelParser(model, this);
        this.serverPort = port;
    }

    public boolean open() {

        if (channel != null && channel.isOpen()) {
            isConnected = true;
            return true;
        }

        try {
            final DatagramSocket socket = new DatagramSocket(null);
            socket.setBroadcast(true);
            socket.setReuseAddress(true);
            socket.bind(new InetSocketAddress(serverPort));
            socketRef.set(socket);
            channel = new ByteChannel() {

            @Override
            public int read(ByteBuffer readData) throws IOException {
                final DatagramSocket socket = socketRef.get();
                if (socket == null)
                    return 0;

                if (receivePacket == null)
                    receivePacket = new DatagramPacket(readData.array(), readData.array().length);
                else
                    receivePacket.setData(readData.array());

                socket.receive(receivePacket);
                hostAdd = receivePacket.getAddress();
                hostPort = receivePacket.getPort();
                return receivePacket.getLength();
            }

            @Override
            public boolean isOpen() {
                return socket.isConnected();
            }

            @Override
            public void close() throws IOException {
                final DatagramSocket socket = socketRef.get();
                if (socket != null) {
                    if (socket.isConnected())
                        socket.disconnect();
                    socket.close();
                }
            }

            @Override
            public int write(ByteBuffer buffer) throws IOException {
                final DatagramSocket socket = socketRef.get();
                if (socket == null)
                    return 0;

                try {
                    if (hostAdd != null) { // We can't send to our sister until they
                        // have connected to us
                        if (sendPacket == null)
                            sendPacket = new DatagramPacket(buffer.array(), buffer.array().length, hostAdd, hostPort);
                        else {
                            sendPacket.setData(buffer.array(), 0, buffer.array().length);
                            sendPacket.setAddress(hostAdd);
                            sendPacket.setPort(hostPort);
                        }
                        socket.send(sendPacket);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return 0;
            }

        };

            msg_heartbeat msg = new msg_heartbeat(255, 0);
            msg.isValid = true;
            write(msg);

            msg_system_time time = new msg_system_time(255, 0);
            time.time_unix_usec = System.currentTimeMillis() / 1000L;
            time.isValid = true;
            write(time);

            parser.start(channel);
            isConnected = true;
            System.out.println("UDP connected...");
            return true;
        } catch (Exception e) {
            System.out.println("Cannot connect to Port: " +e.getMessage()+" " + serverPort);
            close();
            isConnected = false;
        }

        return false;
    }

    public List<Message> getMessageList() {
        return parser.getMessageList();
    }

    @Override
    public Map<Class<?>, MAVLinkMessage> getMavLinkMessageMap() {
        if (parser != null)
            return parser.getMavLinkMessageMap();
        return null;
    }

    public void write(MAVLinkMessage msg) throws IOException {
        ByteBuffer buf = ByteBuffer.wrap(msg.encode());
        channel.write(buf);
    }

    @Override
    public void addMAVLinkMsgListener(IMAVLinkMsgListener listener) {
        parser.addMAVLinkMsgListener(listener);
    }

    @Override
    public void addModeChangeListener(IMSPModeChangedListener listener) {
        parser.addModeChangeListener(listener);
    }

    public boolean isConnected() {
        return isConnected;
    }

    public DataModel getModel() {
        return model;
    }

    public void close() {
        if (parser != null)
            parser.stop();
        try {
            if (channel != null) {
                channel.close();
            }
        } catch (IOException e) {

        }
        LockSupport.parkNanos(1000000000);
    }

public static void main(String[] args) {
    MAVUdpCommNIO comm = new MAVUdpCommNIO(new DataModel(), 14550);

    comm.open();

    long time = System.currentTimeMillis();

    try {

        ModelCollectorService colService = new ModelCollectorService(comm.getModel());
        colService.start();

        System.out.println("Started");

        while (System.currentTimeMillis() < (time + 60000)) {

            // comm.model.state.print("NED:");
            // System.out.println("REM="+comm.model.battery.p+" VOLT="+comm.model.battery.b0+" CURRENT="+comm.model.battery.c0);

            if (comm.model.sys.isStatus(Status.MSP_CONNECTED))
                System.out.println("ANGLEX=" + comm.model.attitude.aX + " ANGLEY=" + comm.model.attitude.aY + " " + comm.model.sys.toString());

            Thread.sleep(1000);

        }

        for (Message m : comm.getMessageList()) {
            System.out.println(m.severity + ": " + m.msg);
        }

        colService.stop();
        comm.close();

        ExecutorService.shutdown();

        System.out.println(colService.getModelList().size() + " models collected");

        // for(int i=0;i<colService.getModelList().size();i++) {
        // DataModel m = colService.getModelList().get(i);
        // System.out.println(m.attitude.aX);
        // }
    } catch (Exception e) {
        comm.close();
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}   

}

`

How to use

Hello,

I'm planning to test MAVGCL in order to analyze live data sent from 3dr radio telemetry, however I couldn't find any information on how to use the Mavcomm.

I have successfully compiled the code but it doesn't seem to bound to my 3dr radio serial port.
I'm running gentoo linux. Which parameteres are expected from mavcomm.jar to be called?

Thanks in advance

pro2 dis # java -jar mavcomm.jar

Initializing (msp.properties)...
Configuration file'msp.properties' not found.
MSPControlService version Build tmp
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/ptr/ByReference
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.comino.mav.comm.highspeedserial.SerialAMA0.(Unknown Source)
at com.comino.mav.comm.highspeedserial.MAVHighSpeedSerialComm.(Unknown Source)
at com.comino.mav.comm.highspeedserial.MAVHighSpeedSerialComm.getInstance(Unknown Source)
at com.comino.mav.control.impl.MAVProxyController.(Unknown Source)
at com.comino.msp.main.StartUp.(Unknown Source)
at com.comino.msp.main.StartUp.main(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.ptr.ByReference
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 18 more

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.