Using AGOpenGPS with a joystick

During the last weekend I wanted to implement the use of a joystick for a better usage of the program as it is a little troublesome to rech for the tablet during basic tasks so I wanted to implement the Joystick from the cerea projekt.

The Project I used as the basis is this one from the Cerea forum.
Cerea joystick

To implement the functions in AG Open GPS I basically copied the work of GialucaRav from this Thread and changed it a little bit to fit more of my needs
Esp 32 bluetooth joystick

To set this up you need the following parts.

Arduino Leonardo/ Arduino Pro Micro
A regular Arduino UNO wont work as it doesnt support HID and therefore cant be used as a keyboard.

Some Jumper cables
A USB Cable for the Arduino to the HUB
Some cheap Push buttons for the controls

Some 50k Resistors.

You have to wire up the Arduino like this

I used the following sketch for the Arduino
AGopen_Joystick_6_Funktionen.ino (3,9 KB)

The keyboard print function doesnt work with agopen the HID library needs to be included
for it to work as it gives out actual keyboard strokes and not only the letters.
My programming knowledge basically amounts to pattern recognition so the code is probably subpar but it works.

To use all of the shortcuts implemented in the script, you have to edit the source Code of Ag Open and publish your own version

Therefore follow this path: Sourcecode>GPS>Forms>UDPComm.Designer
I used Microsoft Visual Studio to edit the Code

You have to include the following lines of Code under the region keystrokes in the File.

//A-B linie verstellen
            if (keyData == (Keys.O)) // Full Screen click
            {
                btnCycleLines.PerformClick();
                return true;    // indicate that you handled this keystroke
            }

            // U Turn aktivieren 
            if (keyData == (Keys.U)) // Full Screen click
            {
                btnAutoYouTurn.PerformClick();
                return true;    // indicate that you handled this keystroke
            }

            // TB wegschalten links
            if (keyData == (Keys.L)) // Full Screen click
            {
                 btnSection1Man.PerformClick();
                return true;    // indicate that you handled this keystroke
            }

            // TB wegschalten rechts
            if (keyData == (Keys.I)) // Full Screen click
            {
                btnSection8Man.PerformClick();
                return true;    // indicate that you handled this keystroke

Afterwards you have to publish your own Version of AG open and the changes will only be in that specific Version so they will be gone with each new Update.
I edited it to my specific needs as I use Sprayer with 8 sections and have to switch away the outer sections regularly this obviously would be different for other users.

The other Functions use the already build in hotkeys of Agopen like “a” for Autosteer “m” for auto sections and “n” to mark the applied area during work.

I would like to implement features to snap the AB left and right like GialucaRav did but unfortuneatly that doesnt seem to work with version 5 and my programming knowledge is to limited for this as the icons only appear after activating Autosteer. Maybe someone here could help with that?

EDIT:
I found a working solution

if (keyData == (Keys.L)) //snap A-B line left
            {
                if (ABLine.isBtnABLineOn || curve.isBtnCurveOn)
                    if (isLateralOn)
                    {
                         if (isTT)
                             {
                                 MessageBox.Show(gStr.h_lblLateralTurnTouch, gStr.gsHelp);
                                 ResetHelpBtn();
                                 return true;
                             }

                    yt.BuildManualYouLateral(false);
                    return true;
                    }

            }

            if (keyData == (Keys.R)) //snap A-B line Right 
            {
                if (ABLine.isBtnABLineOn || curve.isBtnCurveOn)
                    if (isLateralOn)
                    {
                        if (isTT)
                        {
                            MessageBox.Show(gStr.h_lblLateralTurnTouch, gStr.gsHelp);
                            ResetHelpBtn();
                            return true;
                        }

                        yt.BuildManualYouLateral(true);
                        return true;
                    }

            }

I think it could be very usefull to build in more hotkeys for certain tasks.
maybe we can find a working solution here that can be implemented into the main build of AGopen.

Thanks to all the guys that publish their work like GialucaRav otherwise I wouldnt be able to change anything as I have basically no programming skills except the use of copy and paste.

I hope this can help someone that had the same problems implementing the Cerea joystick for example

This is the “joystick” in Action.

10 Likes

Nice work!

Thanks for sharing and the nice documentation.

Nice job!

Is there a list for all AOG shortcuts ? Maybe add it to manual ?

1 Like

The normal shortcuts build into AGOpen are the following

A= Autosteer on/off
C= Open Steer Chart
V= open Vehicle Settings
N= Auto section on/off
Numpad1= Auto section on/off (both do the same)
M= Manual Section On/Off (or mark the applied area)
Numpad0= Manual section on/off (both do the same)
G= Set Flag
P= snap to pivot (sets the AB Line to your position)
F11= Full screen

There are other hotkeys in the code but they are for simulator use

2 Likes

Would bei very nice to implement the shortcuts over UDP PGNs as well.
=> + External button-panel for small screens, or important Buttons on armrest,…
=> + Switching things even DĂĽring an other window ist opend (e.g.Explorer) when HID driver would not be working correctly.

4 Likes

Working on this


4 Likes

What about cheap Bluetooth remote option like this?

3 Likes

Nice, is it 3d Print?

Yea. it’s for 3D print.

1 Like

maybe you can design just a cradle for the Bluetooth stick. I like the idea of wireless in this particular case…

2 Likes

Can it be shared?

Not easy without measures

1 Like

Joystick v2.zip.txt (706,2 KB)

Remove .txt extension

3 Likes

Salut tu as la liste des autres raccourcis ? Merci

Salut
Bonjour
Je viens de coller le code entier ici pour faciliter les choses.

//keystrokes for easy and quick startup
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            //reset Sim
            if (keyData == Keys.L)
            {
                btnResetSim.PerformClick();
                return true;
            }

            //speed up
            if (keyData == Keys.Up)
            {
                if (sim.stepDistance < 0.04 && sim.stepDistance > -0.04) sim.stepDistance += 0.002;
                else sim.stepDistance += 0.02;
                if (sim.stepDistance > 1.9) sim.stepDistance = 1.9;
                hsbarStepDistance.Value = (int)(sim.stepDistance * 5 * fixUpdateHz);
                return true;
            }

            //slow down
            if (keyData == Keys.Down)
            {
                if (sim.stepDistance < 0.04 && sim.stepDistance > -0.04) sim.stepDistance -= 0.002;
                else sim.stepDistance -= 0.02;
                if (sim.stepDistance < -0.35) sim.stepDistance = -0.35;
                hsbarStepDistance.Value = (int)(sim.stepDistance * 5 * fixUpdateHz);
                return true;
            }

            //Stop
            if (keyData == Keys.OemPeriod)
            {
                sim.stepDistance = 0;
                hsbarStepDistance.Value = 0;
                return true;
            }

            //turn right
            if (keyData == Keys.Right)
            {
                sim.steerAngle += 2;
                if (sim.steerAngle > 40) sim.steerAngle = 40;
                if (sim.steerAngle < -40) sim.steerAngle = -40;
                sim.steerAngleScrollBar = sim.steerAngle;
                btnResetSteerAngle.Text = sim.steerAngle.ToString();
                hsbarSteerAngle.Value = (int)(10 * sim.steerAngle) + 400;
                return true;
            }

            //turn left
            if (keyData == Keys.Left)
            {
                sim.steerAngle -= 2;
                if (sim.steerAngle > 40) sim.steerAngle = 40;
                if (sim.steerAngle < -40) sim.steerAngle = -40;
                sim.steerAngleScrollBar = sim.steerAngle;
                btnResetSteerAngle.Text = sim.steerAngle.ToString();
                hsbarSteerAngle.Value = (int)(10 * sim.steerAngle) + 400;
                return true;
            }

            //zero steering
            if (keyData == Keys.OemQuestion)
            {
                sim.steerAngle = 0.0;
                sim.steerAngleScrollBar = sim.steerAngle;
                btnResetSteerAngle.Text = sim.steerAngle.ToString();
                hsbarSteerAngle.Value = (int)(10 * sim.steerAngle) + 400;
                return true;
            }

            if (keyData == (Keys.F))
            {
                CloseCurrentJob();
                return true;    // indicate that you handled this keystroke
            }

            if (keyData == (Keys.A)) //autosteer button on off
            {
                btnAutoSteer.PerformClick();
                return true;    // indicate that you handled this keystroke
            }

            //if (keyData == (Keys.S)) //open the steer chart
            //{
            //    toolstripAutoSteerConfig.PerformClick();
            //    return true;    // indicate that you handled this keystroke
            //}

            //if (keyData == (Keys.S)) //open the steer chart
            //{
            //    btnSnapToPivot.PerformClick();
            //    return true;    // indicate that you handled this keystroke
            //}

            if (keyData == (Keys.C)) //open the steer chart
            {
                steerChartStripMenu.PerformClick();
                return true;    // indicate that you handled this keystroke
            }

            if (keyData == (Keys.V)) //open the vehicle Settings
            {
                //lblHz.Per.PerformClick();
                return true;    // indicate that you handled this keystroke
            }

            if (keyData == (Keys.NumPad1)) //auto section on off
            {
                btnSectionOffAutoOn.PerformClick();
                return true;    // indicate that you handled this keystroke
            }

            if (keyData == (Keys.N)) //auto section on off
            {
                btnSectionOffAutoOn.PerformClick();
                return true;    // indicate that you handled this keystroke
            }

            if (keyData == (Keys.NumPad0)) //auto section on off
            {
                btnManualOffOn.PerformClick();
                return true;    // indicate that you handled this keystroke
            }

            if (keyData == (Keys.M)) //auto section on off
            {
                btnManualOffOn.PerformClick();
                return true;    // indicate that you handled this keystroke
            }

            if (keyData == (Keys.G)) // Flag click
            {
                btnFlag.PerformClick();
                return true;    // indicate that you handled this keystroke
            }

            if (keyData == (Keys.P)) // Snap/Prioritu click
            {
                btnSnapToPivot.PerformClick();
                return true;    // indicate that you handled this keystroke
            }

            if (keyData == (Keys.F11)) // Full Screen click
            {
                btnMaximizeMainForm.PerformClick();
                return true;    // indicate that you handled this keystroke
            }

            // Call the base class
            return base.ProcessCmdKey(ref msg, keyData);
        }
        #endregion

Merci
en fait je voulais savoir si tu avais les autres ceux du mode simulateur

Il y a d’autres touches de raccourci dans le code, mais elles sont destinées à une utilisation en simulateur.

J’ai remarqué cela après avoir posté le message, j’ai donc modifié le message pour qu’il inclue également les commandes du simulateur. :sweat_smile:

2 Likes

Can we stay with English please. Or at least copy Google translate underneath. Thanks!

Does someone know how to publish the modified code?
So i mean i can change the UDPComm… file but how to go on than?