Object detection - help making nano talk to AOG

Ok, I see that now. It doesn’t record if you just click on a section button, but it does if you click auto on or manual on.

The auto sections on code should be a good solution.

I’m stuck and it seems the error I get sends me in a loop. I hope I’ve documented well enough. case dataSwitch is where the error is - I’ve commented with the language.

Controls.Designer.cs Line 510

//Section Manual and Auto
        private void btnManualOffOn_Click(object sender, EventArgs e)
        {
            System.Media.SystemSounds.Asterisk.Play();

            //code added to pass data from Tree detection sensor array
            SerialPort myport = new SerialPort();
            myport.BaudRate = 34800;
            myport.PortName = "com4";
            myport.Open();

            var data = myport.ReadLine();  //arduino sends On or Off
            string v = data.Trim();
            data = v;

            bool dataSwitch;

            if (data == "Off")
                dataSwitch = false;
            else
                dataSwitch = true;
            //end of added


            switch (manualBtnState)
            {   //the case satements stacked below make an 'OR' condition  dataswitch is added
                case dataSwitch:  *//CS0029 Cannot implicitly convert type 'bool' to 'AgOprnGPS.FormGPS.btnStates'*
                case btnStates.Off:
                    manualBtnState = btnStates.On;
                    btnManualOffOn.Image = Properties.Resources.ManualOn;

                    //if Auto is on, turn it off
                    autoBtnState = btnStates.Off;
                    btnSectionOffAutoOn.Image = Properties.Resources.SectionMasterOff;

                    //turn all the sections allowed and update to ON!! Auto changes to ON
                    for (int j = 0; j < tool.numOfSections; j++)
                    {
                        section[j].isAllowedOn = true;
                        section[j].manBtnState = manBtn.Auto;
                    }

                    ManualAllBtnsUpdate();
                    break;

                case btnStates.On:
                    manualBtnState = btnStates.Off;
                    btnManualOffOn.Image = Properties.Resources.ManualOff;

                    //turn section buttons all OFF or Auto if SectionAuto was on or off
                    for (int j = 0; j < tool.numOfSections; j++)
                    {
                        section[j].isAllowedOn = false;
                        section[j].manBtnState = manBtn.On;
                    }

                    //Update the button colors and text
                    ManualAllBtnsUpdate();
                    break;
            }
        }

That switch is checking for a button state not a bool. That’s part of the problem.

But you are in the middle of a button_click doing this. So the only time that this function runs is when the button is clicked, unless called otherwise. So I think what you are needing is to put your serial reader in the main loop. Then let it check for the condition and respond accordingly each time around.

Somewhere in the code, it tells the sections to all be on or individual. I don’t remember, maybe in csections.cs. Search for the phase supersection. I believe it’s around there.

Were you able to send the work switch serial in from the autosteer to see if that shut it off?

I don’t think you need to write any code in AOG. Just connect your sensor nano to either the AutoSteer Port or the Machine Port.

Capture

Then send the Serial.println pgns as DanielP suggested.

1 Like

Alright, I’ll give connecting to the machine port a try… No coding sounds fine to me.

Success - I think - pretty sure. We’ve got 40 MPH wind gust here today so I’m not going to the field I’d lose my sun screen. I have hooked it up and I read sensor changes as would be expected. (This is using DanielP suggestion).

Thanks to all who made suggestions.

1 Like

Good :+1:t3: I’m guessing you’ll do a setup video? And a demo video?

Hobbyfarmer.

I hadn’t thought of any videos, but i’ll sure do my best! Maybe this weekend.

@Ray_Jorgensen :wink:

Here’s a bit of video. The first clip is of the ultrasonic array as I circled a tree. (I’m going slow cause was running out of hands) You can’t see it on the vid but I have a LED that comes on as contact is made. I need to stiffen up the “do dad” It bounces to much and causes the switch to toggle when unwanted. I’ll get that fixed and do a vid of it in “auto” mode.

It works great and I’m :grinning: :grinning: :grinning:

4 Likes

After a few days of going in circles, I figured out my WAS had come unplugged.

Here’s a short vid of auto steer going and the switch working. I think it’s in the 1st circle where the switch toggles off and on. It’s real easy to find that in the recorded txt file and fix it - change a False to True.

Hobbyfarmer
Was this all you wanted to see?

Can anyone point me to where the definition for the Serial.println(“127,249,0,0,0,0,0,0,0,1”) (the number positions between the commas) might be found? It might come in handy for other stuff - what I don’t know - but ya never know what might come up.

Again a big thanks for all your help!

1 Like

In Support_Files.zip, a xlsx file PGNs 2020-04-04, line 31.

Another view of this PGN:
PGN32761

1 Like

If you type @Ray_Jorgensen it will notify the person you are addressing.

Perfect. Is this done all in the Arduino code or did you have to dig into the C#?

@Hobbyfarmer the @ is cool!! I added.

Serial.begin(38400);  
     while (!Serial) { ; } // wait for serial port to connect. Needed for native USB

to setup and


if (average > 0)
  {
    digitalWrite(ledPin, HIGH);
    Serial.println("127,249,0,0,0,0,0,0,0,1");   //Turn On Auto Sections AOG
  }
  else
  {
    digitalWrite(ledPin, LOW);
    Serial.println("127,249,0,0,0,0,0,0,0,2");   //Turn Off Auto Sections AOG
  }

to loop in Arduino code and that is it.

@SK21 I looked at that file once - looked like gibberish - I’ll look again with a new light.

1 Like

@SK21

I’d like to learn more about using the PGN as is being done in AOG. Can you give me some search terms or web sites to reference? I do a search on PGN and it returns Portable Game Notation.

Take a look at the Arduino autosteer code in the section that parses the data coming from AoG & outputs data to AoG. The code identifies which PGN it’s reading, and parses the data accordingly. Open the PGN xlsx file sk21 mentioned and you should be able to figure out how it works.

Thanks @m_elias,

I’ve gone through the autosteer code once. It’ll take me a few more times yet. Pretty neat how info can be sent back and forth.

@DanielP

You helped me with this for use with V4.3. With the changes with V5 It looks to me that I will need to make changes??? I have looked at the 5.1 PNG xls file and I’m not good enough with how that works to know what I need to get the same results. I’m hoping you might understand the new PNG and be willing to help again.

connect arduino with the Machine Serial Port
MTZ8302 Remote Switch code
Serial.println(“127,249,0,0,0,0,0,0,0,2”);//Turn Off Auto Sections
Serial.println(“127,249,0,0,0,0,0,0,0,1”);//Turn On Auto Sections
[/quote]

ahh yes for v5 you need
MTZ8302 Remote Switch code
Serial.println(“128,129,123,234,8,2,0,0,0,0,0,0,0,111”);//Turn Off Auto Sections
Serial.println(“128,129,123,234,8,1,0,0,0,0,0,0,0,110”);//Turn On Auto Sections

@DanielP - Thank you much!!! I would never have got that from what I see in the PNG file.