Object detection - help making nano talk to AOG

Now that I have AOG working, I need to record paths for spraying around 350 trees. Pushing the manual relay button on and off is nearly impossible.

To see what I’m doing; -

I have an ultrasound sensor rigged up, controlled by a nano. When the sensor “sees” a tree it sends a trigger to turn on the manual section control button in AOG. It would also turn this off when it doesn’t see the tree.

Here’s my sensor array. I had to use more than 1 sensor due to the narrow cone and because the tree shelters are round. The Arduino code works well.

IMG_0159

I have an open port on my usb hub to plug the sensor into. I will only need the sensor hooked up one time during the recording since the on and off would be recorded also.

This is my first real attempt any C# programming other than following along on learning tutorials.

I have tried a bit of code that I put together from samples online and not surprising I get errors when I insert it where I think it should go. I’d like to learn not only how to get this to work but why. If anyone would like to give me some guidance?

Controls.Designer.CS — where the manual button is controlled
Add at top add;
using System.IO.Ports;

//Section Manual and Auto line ### 510
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();

        while (true)
        {
            string data = myport.ReadLine();  //arduino sends On or Off
            if (data = On)
            {
                btnStates.On
            }
            else
            {
                btnStates.Off
            }
        }
        //end of added code 

        switch (manualBtnState)

You could direct/discrete connect the “sensing”-nano to the machine/section control-nano simulating an external button input, and use this way to relay the information into agopengps. Like the driver/an external trigger is pressing the button. You can still override the input and have no need to manipulate agopengps.

hagre,

I hadn’t thought of direct connecting the two Nano’s!!! Will doing this “backfeed” to AOG so that the ‘button push’ will be recorded with the path?

I don’t know all that is wrong with your code, but the if statement should read:

if (data == "On")

You will want to trim data to get rid of all the blanks that may come in with the read line.

If I remember right, it is:

data=data.trim();  

:wink: search “back tick” for your OS. On my iPhone they were hard to find. On regular windows keyboard they are top left corner.

Don’t know why forums make code formatting so hard to find…

1 Like

Under the second set of symbols on my keypad. Press symbol then press the 1/2. Then upper left corner. The 1/2 is not one half, it is one of two. Almost like shift. Thanks.

I agree with that. It just becomes an exterior switch. Tool is always on, and the spray relay signal is interrupted by a relay on the second nano. You could feed this back in to AOG, if you wanted to see it on the screen. But it will work just the same.

Your memory is good - Trim just needs to be cap T. Now only errors after }. I’ll do some looking for that cause.

Finish your lines with a semicolon;

Finishing lines w/; creates a diff error. I’m better versed w/the Arduino code and can sure make that route work.

How would I go about feeding this back into AOG? The goal being that the “switch” action is also included in the recorded path.

On second thought sending back to AOG basically results ijn the same problem - Back to work on C# code. I think I’m going to try placing it in a different location.

Doen’t this do what you are asking? I believe, the autosteer reads this and imports it to control the manual tool. That manual tool on records during the record session. I’m not familiar with most of this, someone else would know more than myself. But it appears that AOG reads this and turns the work on or off.

image

KentStuff,

I Don’t know what that is for. I’ll have a look in the code and see if I can figure it out. In the mean time I have the code done to bring it in the USB. At least I think I do, I don’t get any errors. I’ll have time in a day or so to try it out. I’ll report back either way.

I’ve been following your efforts on grade control - good work!!

I struggled to find the whole works of that button, but it appears to read a switch in the autosteer serial read. It did not look like it was still active in the arduino code, but may have originally read pin 7. Somewhere on this forum, I saw someone with a full switch board that controlled each section outside of AOG and AOG would respond to each switch. May be something to look for.

Thanks for the compliment on grade control. Been slowly learning C# since early last summer. Prior to that, my last programing was in Fortran in the last millinium. It still amazes me that the computer can process that much information that fast.

Just curious what type of trees are you spraying? We live in pecan country and Hurricane Michael got most of them in our area. The orange groves did much better.

Which version of AoG are you using? On my sprayer, I’m using an older version where my modified autosteer ino monitors 5 analog pressure sensors and when they read a pressure above a certain threshold it tells AoG to turn on that section which paints the screen for me. There’s a certain section control PGN that allows the Arduino to override AoG. I think this is what you want. Off hand, I don’t know the details of that PGN but I could look it up once there’s time.

In the link below is a video of it running backwards. The switch telling the computer what to do. Not sure how to find the original, but this was one of the ones I remember.

Where is the on/off recorded? Does AOG do this? Is this something you will be coding it to do?

1 Like

That’s the one

1 Like

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

or with the AutoSteer Serial Port(need to enable WorkSwitch in toolsettings)
Serial.println(“127,253,0,0,0,0,1,0,0,0”);//Turn Off Auto Sections
Serial.println(“127,253,0,0,0,0,0,0,0,0”);//Turn On Auto Sections

2 Likes

m_elias
I’m running 4.3.10.

KentStuff
We.ve got 2 - 3 acre pieces that for years tried to figure out something to make money rather than just mowing for fun. The patches are in city limits so have to keep them mowed. 3 years ago I happened on an article on Chestnuts, the rest is history. We live in NC Iowa - about 60 miles N of where the Derecho? big wind went through mid August.

I’ve seen some of the threads about using external buttons or switches. I need to go back and revisit them!!

SK21
If you record your path ( use the Martian in the upper left corner) 0f AOG - everything you do is recorded, speed, relays, etc. Brian’s video

DanielP
Thanks for the machine code. I’ve watched Brian’s videos on this many times. It’s only when I need to implement something of my own that I really begin to understand how it all works, so I will also make this switch work that way.

1 Like