News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Model boat simulation

Started by KetilO, August 18, 2019, 06:17:37 AM

Previous topic - Next topic

KetilO

Hi all, long time no see.

I have made a renote controlled boat with GPS and sonar.
The idea is to put the boat on the water and let it find fish
for me. Meanwhile I can sit on the front porch drinking coffe.
If there is little or no fish I can enjoy a cold ber instead
of going fishing and catch nothing.
The system works as expected, but some new functions are needed.

To evaluate methods for land avoidance, return homa, goto
selected point and scan selected area, I have made this
simulation. Since the MCU used in the boat does not have
floating point, the boat simulation uses integers only.
When I have everything figured out and tested it will be
translated to C for implementation into the boats MCU.

For more information see the included ReadMe.txt file

KetilO

LiaoMi

Hi KetilO,

the project of the future, an extraordinary virtual joystick is something incredible :thumbsup: Are there any plans to control the drone ?!

Any obstacle in the way prevents return to base  :tongue:



Here you can buy an interesting book that describes the programming of gps, the book talks about a similar framework  :eusa_dance:
Programming GPS and OpenStreetMap Applications with Java - http://www.roaf.de/

Biterider

Hello KetilO

It's nice to see you here again   :biggrin:

This project is great!  :thumbsup:

I had to see where I had RadASM3 (still using RadASM2), but finally I found it and was able to run the program. Unfortunately, I can not help with the remote control, but I took a few steps into Kotlin.
My main idea was to code something to communicate between an Android tablet and an ASM program on the PC. How did you code for your pad?

Regards, Biterider

KetilO

Hi LiaoMi

Yes, the boat will stop if you get too close to the shore.
Path finding is not somting I need for this project.

Hi Biterider

To develop for android pad I use Android Studio programming in java.

To comunicate between PC an pad you can use bluetooth or WiFi.

Included is a small project that creates a WiFi server on the PC.
The pad can then connect to this server and exchange data.

KetilO

KetilO

Hi

This is the java code to connect to the server.


package com.modelboat.modelboat;

import android.util.Log;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;

/**
* Created by Ketil on 20.05.2019.
*/
public class TCPIPClient {
    // ESP8266 WiFi
    public static String SERVER_IP = "192.168.4.1";
    public static final int SERVER_PORT = 80;
    // My PC
    //public static String SERVER_IP = "10.1.1.144";
    //public static final int SERVER_PORT = 9090;
    public static boolean mConnected = false;
    public static Socket socket;

    public static String sendBytes(ControllerStructClass csc) {
        try {
            if (socket.isConnected()) {
                OutputStream out = socket.getOutputStream();
                DataOutputStream dos = new DataOutputStream(out);
                csc.Convert(csc);
                dos.write(csc.Bytes);
                return "OK";
            } else {
                Log.e("TCP", "C: sendString ERROR");
                mConnected = false;
                return "ERR";
            }
        } catch (IOException e) {
            //mRun = false;
            try {
                socket.close();
            } catch (IOException e1) {
            }
            mConnected = false;
            return "ERR";
        }
    }

    public static String recBytes(BoatStructClass bsc) {
        try {
            int l,i;
            if (socket.isConnected()) {
                InputStream in = socket.getInputStream();
                DataInputStream dis = new DataInputStream(in);
                i = 0;
                while (i < 640) {
                    i += dis.read(bsc.Bytes, i , 640 - i);
                    if (i < 0) {
                        socket.close();
                        mConnected = false;
                        return "ERR";
                    }
                }
                bsc.Convert();
                bsc.SonarData[0] = (byte)(FullscreenActivity.mControllerStructClass.PingRange & 0x07);
                return "OK";
            }
            mConnected = false;
            return "ERR";
        } catch (IOException e) {
            Log.e("TCP", "C: recString error");
            try {
                socket.close();
            } catch (IOException e1) {
            }
            mConnected = false;
            return "ERR";
        }
    }

    public static void connect() {
        try {
            Log.e("TCP Client", "C: Connecting...");
            mConnected = false;
            //create a socket to make the connection with the server
            //socket = new Socket(SERVER_IP,SERVER_PORT);
            SocketAddress sockaddr = new InetSocketAddress(SERVER_IP, SERVER_PORT);
            socket = new Socket();
            socket.connect(sockaddr, 5000);
            mConnected = true;
        } catch (Exception e) {
            Log.e("TCP", "C: Error", e);
            //FullscreenActivity.nShowError++;
        }
    }
}