marcobergman / ais_simulation

Simulates moving AIS targets by creating NMEA AIVD messages and sending them off by TCP
7 stars 2 forks source link

Can I use this to test autopilot_route_pi? #10

Open rgleason opened 1 year ago

rgleason commented 1 year ago

Marco, Is it reasonable to test autopilot_route_pi using this software? How would you suggest proceeding when using Windows?

THE ANSWER IS YES!!! but below are good trials.

marcobergman commented 1 year ago

Yeah I've tested the whole plugin this way; it runs very well under windows. Some more examples you can find in attached link.

https://github.com/pypilot/workbook/files/7745610/Autopilot.Route.OpenCPN.plugin.pdf

rgleason commented 1 year ago

This morning I've been trying your tool with some success. I think autopilot_route is still bad, but perhaps you can confirm that. I can get your ais_simulator.exe running nicely. When I use the python command in powershell I get an error.

PS C:\Users\fcgle\source> cd ais_simulation
PS C:\Users\fcgle\source\ais_simulation> python --version
Python 3.10.0
PS C:\Users\fcgle\source\ais_simulation> python simulate_ais.py
Traceback (most recent call last):
  File "C:\Users\fcgle\source\ais_simulation\simulate_ais.py", line 2, in <module>
    import wx
ModuleNotFoundError: No module named 'wx'
PS C:\Users\fcgle\source\ais_simulation>

In the python script I don't find wxWidgets referenced. What is this error due to? I have wxWidgets all set up with env variables and working for OpenCPN C:\Users\fcgle\source\wxWidgets-3.1.2

Perhaps you know what is happening? I have pyton 3.10

rgleason commented 1 year ago

Here are some screen shots I haven't figured out how to control the autopilot_route settings, but I am finding accessing from preferences to be a bit of a pain, but perhaps this is necessary due to the settings being needed at a lower level.

The round circle is behind the boat!!!! This isn't right I think. I did create my own goto here route and set it active. Is that the right thing to do? Autopilot_route-Test1

Zoomed

Autopilot_route-Preferences

marcobergman commented 1 year ago

The green circle is is what I have dubbed the guide point. The guide point is a fixed distance away from the boat, in your case 100 meters. The boat will steer towards the guide point. However, if the boat is too far from the track (more than the 100 metres) the boat would steer to the closest point on the track. This is what you see and it would not be practical. That's why, if the guide vector is more that MaxErrorAngle from the track's heading, it is capped at that. The result is the guide vector which is the red line. You see that in your pictures, the boat is trying to intersect the track at 30 degrees.

I have been using the github version of autopilotroute_pi for more than a year now, in conjunction with pypilot. I'm very happy with it; it works quite well. Something went wrong in the OpenCPN port; that version is not reliable.

marcobergman commented 1 year ago

ModuleNotFoundError: No module named 'wx'

I have no virgin windows machines anymore to test for you, but if I remember correctly on windows you can also install missing modules with pip, e.g. pip install -U wxPython

marcobergman commented 1 year ago

You seem to be missing an OpenCPN data connection outputting to the ais_simulator's 20220/TCP socket; then the simulator will assume the headings from the autoroute_pi and you are full-circle. You might have to check windows built-in firewall to get this going - cannot remember.

rgleason commented 1 year ago

Actually I do, I just didn't show a screenshot. I should have. I am wondering if the version I built is fixed.

Screenshot (398)

For the AIS-simulator I have Network input UDP protocol 0.0.0.0 Network Address and 10110 Network Port.

you seem to be missing a data connection outputting to the 20220/TCP socket <--- this makes me think I am missing something. Am I?

rgleason commented 1 year ago

Ok I tried adding a Network output TCP protocol 0.0.0.0 Network Address and 20220 Network Port Screenshot (407)

Here are some screenshots. I had to slow it down as it moves fast.

Screenshot (412) Screenshot (414) Screenshot (416)

Does this look right? This is helpful. The green circle is is what I have dubbed the guide point. The guide point is a fixed distance away from the boat, in your case 100 meters. The boat will steer towards the guide point. However, if the boat is too far from the track (more than the 100 metres) the boat would steer to the closest point on the track. This is what you see and it would not be practical. That's why, if the guide vector is more that MaxErrorAngle from the track's heading, it is capped at that. The result is the guide vector which is the red line. You see that in your pictures, the boat is trying to intersect the track at 30 degrees.

  1. I created my own "navigate to here" and set that route active. Is that the correct thing to do?
  2. I used your ais_simulator to "aim" the boat. It does not seem to be going anywhere on its own.
  3. So I must have not set up something correctly. Maybe it is the autopilot EC commands...

I have been using the github version of autopilotroute_pi for more than a year now, in conjunction with pypilot. I'm very happy with it; it works quite well. Something went wrong in the OpenCPN port; that version is not reliable. I am trying to get the OpenCPN version working in the same way. Somehow Sean's and mine diverged.

(I also tried for about the 6th time to merge sean's watchdog and mine so that we have the pypilot alarm too, but mine has depth and rudder angle and he deleted files and changed the pypilot alarm considerably and now I am getting screwed by the fpb file changes.) I wish Sean would help a little by accepting PR's

rgleason commented 1 year ago

Perhaps you could try Autopilot_route 0.4.8.0 in the Opencpn PIM Plugin Manager's Beta Catalog? What are you using Linux? There are builds for all supported OS except Android. opencpn.conf or opencpn.ini has to have under [plugins] catalogexpert=1 to get to the Beta Catalog.

marcobergman commented 1 year ago

The 0.0.0.0:20220 should be the ip address:20220 of your machine. In my case it's 192.168.178.30.

On Fri, Jan 13, 2023 at 10:56 PM Rick Gleason @.***> wrote:

Perhaps you could try Autopilot_route 0.4.8.0 in the Opencpn PIM Plugin Manager's Beta Catalog? What are you using Linux? There are builds for all supported OS except Android. opencpn.conf or opencpn.ini has to have under [plugins] catalogexpert=1 to get to the Beta Catalog.

— Reply to this email directly, view it on GitHub https://github.com/marcobergman/ais_simulation/issues/10#issuecomment-1382435994, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEJFZEBH6IF2CYIKLD3BX33WSHFQBANCNFSM6AAAAAATZNQRH4 . You are receiving this because you commented.Message ID: @.***>

rgleason commented 1 year ago

Ok, got it. It is the IP assigned by the router.

marcobergman commented 1 year ago

it looks allright in the sense that the sent sentences are blue and I see that the heading in the APB matches the heading in the simulator (244.0) so I think you are all set. If yuou set a curly route the little boat must start following it, and then you can investigate how the autoroute_pi parameters affect performance. Mind you that the default speed-up ratio is 60x.

rgleason commented 1 year ago
--- Broadcasting NMEA messges to UDP:10110   <----Using 0.0.0.0
--- Listening to NMEA messages at TCP:20220     <--- Using my ip  192.168.120.1
--- Loading boats from ais_simulation.gpx
name=AIS-1, mmsi=1, lat=52.577615042, lon=3.062908344, heading=028, speed=10.3, status=1
name=AIS-2, mmsi=2, lat=52.560516681, lon=3.018649757, heading=28, speed=10.3, status=0
name=AIS-3, mmsi=3, lat=52.780918302, lon=3.132218962, heading=208, speed=10.3, status=1
name=AIS-4, mmsi=4, lat=52.477138333, lon=2.952928333, heading=028, speed=10.3, status=1
name=AIS-OWN, mmsi=6, lat=52.626518333, lon=3.199091667, heading=260, speed=6, status=1
Awaiting connection...
--- Initial positioning of boats
!AIVDM,1,1,,A,100000A01WP>1ERN5LjA60p00000,0*22
!AIVDM,1,1,,A,100000P01WP=lGbN4leQ60p00000,0*61
!AIVDM,1,1,,A,100000i01WP>Ea6N<qA`86P00000,0*28

Here are some screenshots. I still have to "guide" the boat by using ais_simulator.... It doesn't seem to want to align automatically to the route when it arrives on the route. Shouldn't it be doing that? Also when I turn the boat 30 degrees from the route, why doesn't it start to turn back to get on the route? It should be quite persistant about that.

Screenshot (418) Screenshot (416) Screenshot (420) Screenshot (421)

marcobergman commented 1 year ago

Yeah it should align. I compile straight from sean's github, both on raspbian and ubuntu. Can't find it now where I had summed the issues I had found with the PIM-provided version, but that might be one of them. Going AFK for now.

rgleason commented 1 year ago

Screenshot (422)

rgleason commented 1 year ago

Thanks you've been a help.

marcobergman commented 1 year ago

Does it align now?

rgleason commented 1 year ago

Not that I can determine. I am now looking at sean's version. Can you tell me if this is the version that you built? https://github.com/seandepagnier/autopilot_route_pi/commits/master Merge pull request https://github.com/seandepagnier/autopilot_route_pi/pull/20 from rgleason/master

Update to TP FE2 1.0.213 based on seandepagnier June 28 2022?

rgleason commented 1 year ago

I think I am going to wait and see if what I have done is OK. It will stay in the PIM beta catalog until we get some confirmation. Too much thrashing to just do it all over again.

Your Issue is here https://github.com/rgleason/autopilot_route_pi/issues/6

Is this what you are using?

The version 0.5 straight out of the master github shows the right headings.

Do you suppose this is missing? - It does not seem like that is the problem. https://github.com/seandepagnier/autopilot_route_pi/commit/098226d8c5779b491800eca8ba6e233e3ec9582c

marcobergman commented 1 year ago

Not that I can determine. I am now looking at sean's version. Can you tell me if this is the version that you built?

I think the last time I compiled it, it was the Dec 5, 2021 commit from sean's github, as per https://www.cruisersforum.com/forums/f134/autopilot-route-plugin-197566-8.html#post3661033. With my systems on the boat, I'll rig up a new openplotter raspberry so I can test github compiles. I cannot compile on windows.

For now, got the 0.4.8.0 version from PIM on Windows and it looks promising; the issue I reported earlier seems to have been resolved.

rgleason commented 1 year ago

After looking at the commits in Sean's repository

This is still [version 0.5.0](https://github.com/rgleason/autopilot_route_pi blob/098226d8c5779b491800eca8ba6e233e3ec9582c/VERSION.cmake)

[attempt to](https://github.com/rgleason/autopilot_route_pi/commit 098226d8c5779b491800eca8ba6e233e3ec9582c)fix https://github.com/seandepagnier/autopilot_route_pi/issues/6

https://github.com/seandepagnier/autopilot_route_pi/commit/098226d8c5779b491800eca8ba6e233e3ec9582c in Dec 5, 2021

rgleason commented 1 year ago

With my systems on the boat, I'll rig up a new openplotter raspberry so I can test github compiles

That would be very helpful. I think there is a Opencpn 5.7.1 RPI version, but I believe it uses Flatpak. Don't know if that is an issue, but that is how the OpenCPN builds have changed.

There is a fair amount of commits from me after this one of sean's "[Attempt to fix](attempt to fix https://github.com/seandepagnier/autopilot_route_pi/issues/6)" from Dec 5

but I will go back to that point and compile it. Then I have to figure out how to move that forward as there is a lot of documentation that was added.

marcobergman commented 1 year ago

Ok just tell what commit needs testing

rgleason commented 1 year ago

Marco, I cloned and git checkout 098226d8c5779 https://github.com/seandepagnier/autopilot_route_pi/commit/098226d8c5779b491800eca8ba6e233e3ec9582c in Dec 5, 2021 and made a new branch locally "attempt-to-fix"

Then I used a windows tool Winmerge to compare the attempt-to-fix branch with the src/ files in my current version 0.4.8.0 . In checking each of the files I did not find much that was different I did make one small change.

at line 200-201 of autopilot_route_pi.cpp to add

    wxAuiManager *pauimgr = GetFrameAuiManager();
    pauimgr->DetachPane(m_ConsoleCanvas);

Other than that it all appears to be the same, with the exception of minor changes that were necessary for the OpenCPN 5.7.1 plugin to build, etc.

marcobergman commented 1 year ago

Just a quick test on a raspberry, OpenCPN 5.6.2, installed the 0.4.8.0 plugin from the beta channel, looking quite good. The problem I have here is that at the end of the track, the simulation veers off. This might be due to the simulation mechanism or the speedup factor. But this is one of the things I don't want my boat to do, and I'd rather not see it in the simulation either.

image

marcobergman commented 1 year ago

The same with speedup factor=1:

image

rgleason commented 1 year ago

This is certainly an encouraging result. Thank you for testing. I am puzzled why a plugin built using wxWidgets 3.2.1 and intended for RPI OpenCPN 5.7.1 would work with RPI OpenCPN 5.6.2 and I wonder if that is what is causing the veer at the end of simulation? If it is not, then I need to find out why.

marcobergman commented 1 year ago

All right I'll update OpenCPN then

Edit: that was easier said than done

pi@openplotter:~ $ sudo add-apt-repository ppa:bdbcat/opencpn
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Raspbian/bullseye

pi@openplotter:~ $ flatpak install --user https://flathub.org/beta-repo/appstream/org.opencpn.OpenCPN.flatpakref
error: No such ref 'app/org.opencpn.OpenCPN/arm/beta' in remote flathub-beta
rgleason commented 1 year ago

Good Morning Marco, I was going to ask about this question in the Opencpn/Opencpn Issues as well. Maybe Dave and Leamas have some thoughts about it.

Seeing your examples, where the boat just follows the active route without user intervention using your ais-simulation tool, convinces me that I have not set up the testing environment properly. Procedure:

  1. Set Options > Connections
  2. Network Directon: Input Protocol: UDP Address: 0.0.0.0 Port: 10110
  3. Network Directon: Output Protocol: TCP Address: (your computer's IP address) 192.168.1.120 Port: 20220 Check "Output on this port (as autopilot or nmea repeater) Talker ID "EC" APB bearing precision x.xxxx Input precision: Accept only sentences. Output precison: Output only sentences.
  4. Open the Options > Connections Nmea0183 Debug window.
  5. Route import Gpx "test-route.gpx" and set it as an active route?
  6. Start ais-simulation.exe or execute python ais_simulation.py which uses/runs ais_simulation.gpx
  7. Then how do I get the boat to follow the route? Something appears to be missing still.

Screenshot (423) Screenshot (425)

rgleason commented 1 year ago

Maybe I need to do this in a debug environment with VS2022?

marcobergman commented 1 year ago

Pleasantly puzzled here. Do you see anything in the python logging?

image

marcobergman commented 1 year ago

Why would you have a zero here, and I don't?

image

marcobergman commented 1 year ago

And this is different image

rgleason commented 1 year ago

Yes! that is it. Garbage in Garbage out. My mistake. Sorry. It is working now.

marcobergman commented 1 year ago

It should not have been in blue then.

rgleason commented 1 year ago

It seems to overshoot and waiver back and forth perhaps 20 degrees. Can't it hold a better course?

It does turn pretty nicely to follow the route.

marcobergman commented 1 year ago

If it overshoots decrease the speedup in the upper right corner. The widget's value is taken immediately, no need to hit enter or tab.

rgleason commented 1 year ago

It hunts back and forth 20 degrees going along the route. Then at the end of the route it goes off at 20 degrees from the route.

Screenshot (427) Screenshot (428) Screenshot (430)

I turned on tracking finally.
I'll bet if I make max angle 10 degrees that it will go off at 10 degrees. Something is slightly wrong in the calcs.

marcobergman commented 1 year ago

If it overshoots decrease the speedup in the upper right corner. The widget's value is taken immediately, no need to hit enter or tab.

This one:

image

rgleason commented 1 year ago

Yes, that helps. I restarted and activated the circle route, it works much better, no hunting anymore at speed=20 but still goes off at 20 degrees at the end.

Screenshot (430) Screenshot (433)

rgleason commented 1 year ago

So we just have one problem at this point I think. The offset degrees at the end of the route. I think that should be fixed quite easily, perhaps by Sean.

marcobergman commented 1 year ago

At some point I consistently had a 180 degree turn at the end; and I was able to debug that with debug statements in the code. Could try the same here, but I have some problems compiling your version.

Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES wxWidgets_INCLUDE_DIRS)

rgleason commented 1 year ago

I changed maxangle to 10 degrees (right click on console) and speed up to 60 knts and the track shows it waivering. Very interesting effect. At 10 knots it stays right on the course.

Screenshot (437)

marcobergman commented 1 year ago

tried sudo mk-build-deps -ir ci/control to no avail

marcobergman commented 1 year ago

I changed maxangle to 10 degrees (right click on console) and speed up to 60 knts and the track shows it waivering. Very interesting effect. At 10 knots it stays right on the course.

FYI it's a speedup factor, not knots. By default .gpx config, at factor=1, the simulated boat would go 6.0 knots.

rgleason commented 1 year ago

I can build for windows locally, but all of these are built in the cloud by appveyor and circleci using the "ci" scripts. You need wxWidgets and most of the time it is wxWidgets 3.2.1 but for RPI it may be using something else... lets take a look at the scripts... in my repos https://github.com/rgleason/autopilot_route_pi https://github.com/rgleason/autopilot_route_pi/tree/master/ci Is it circleci-build-raspbian-armhf.sh or one of the other ones?

Perhaps seeing the right script will help?

rgleason commented 1 year ago

Some information about end of route issue.

Trials-End-of-Route

Waivering and Hunting at high speeds. Waiver-Hunting

rgleason commented 1 year ago

How did you get it to be 180 degrees at end of route? Perhaps you recall?

Why does the boat's course change before reaching the final waypoint? Shouldn't it stay on track until it reaches that final waypoint? Then take the course that it is using and set it as the course. Also shouldn't there be an alert or alarm or something before reaching that final waypoint? Maybe Watchdog does this?

rgleason commented 1 year ago

I tried setting my own route active.

Trial3

marcobergman commented 1 year ago

How did you get it to be 180 degrees at end of route? Perhaps you recall?

The 180 degrees thing was a sort of race condition; it did not realize it was done and turned back to the waypoint it just passed. That was already solved in the dec 5th commit, I think.

The waivering you see is probably due to the plugin settings (guide radius should be 100m or so) and simulation settings (speedup should be low, route legs should not be relatively short). I don't have the waivering here. The algoritm is good and beyond question.

Why does the boat's course change before reaching the final waypoint? Shouldn't it stay on track until it reaches that final waypoint? Then take the course that it is using and set it as the course.

The algorithm implies that when the boat reaches the last waypoint minus the guide radius, it already stops. So it makes sense to see it ending before the last waypoint is reached.

Also shouldn't there be an alert or alarm or something before reaching that final waypoint? Maybe Watchdog does this?

Some final waypoint notification would be nice!