The Combine Forum banner

1 - 20 of 2024 Posts

·
Registered
Joined
·
5,856 Posts
Discussion Starter #1 (Edited)
So i thought i would start a topic that concerns just with AutoSteer. Hardware/software be it PI or arduino, is self contained and only uses AgOpenGPS for some parameters. In fact any front end could generate the ABLine or Contour data for it.

AgOpenGPS sends out 9 bytes on the autosteer port.

Header - 2 bytes - Signed integer, value 32766 or 127 high byte + 254 low byte. Purpose: As a header for upcoming sentence.

Relay Control - 1 byte - Byte, value 0 to 255 defines how many of the 8 sections required to be on. bit 0 LSB is section 1, bit 7 MSB, section 8.
Example 0000 0011 (3) -> Section #1 and Section #2 are on, Sections 3 thru 8 are off

Speed - 1 byte - Byte value 0 to 255, speed in km/h * 4.0.

DistanceFromGuidanceLine - 2 bytes - Signed integer, high byte then low byte. Value is in millimeters from guidance line. Positive denotes right side of line, Negative denotes left side of line.
Special numbers, if value is:
32020, it means autosteer in AgOpenGPS is turned off.
32000 means Autosteer is on but there is no guidance line to calculate a distance from.

HeadingError - 2 bytes - Signed integer, high byte then low byte. Value is in radians * 10,000.
Positive denotes heading toward the guidance line, Negative denotes heading away from guidance line.

PID gain value byte. The LSB bit 0 --> 0 means decrease, 1 means increase
Bits 1 thru 7 are the individual gains or parameters.
Bit 1 - Proportional gain
Bit 2 - Integral gain
Bit 3 - Derivative gain
Bit 4 - Overall gain

The use of binary rather then text means it isn't readable to humans, is more complex, but is much faster. The header bytes allow showing the start of new information. Accurate consistent data is important and since its just a stream of bytes, its important to know where the sentence starts. The GPS Data window in AgOpenGPS shows what is being sent. I will edit this page as required to reflect any changes in sentence structure.

https://github.com/farmerbriantee/AgOpenGPS

https://www.youtube.com/user/FarmerBrianTee
 

·
Registered
Joined
·
5,856 Posts
Discussion Starter #2 (Edited)
So to jump right in, start at the beginning, getting the right information....

Here is some Arduino code for discussion on parsing the sentence.

Code:
void setup() { setup here }

void loop()
{
  // header high/low, relay byte, speed byte, high distance, low distance, high delta, low delta

  if (Serial.available() > 0 & !isHeaderFound) //find the header, 127H + 254L = 32766
  {
    int temp = Serial.read();
    header = tempHeader << 8 | temp;               //high,low bytes to make int
    tempHeader = temp;                             //save for next time
    if (header == 32766) isHeaderFound = true;     //Do we have a match? 
   }
  
  //Header has been found, presumably the next 6 bytes are the data
  if (Serial.available()> 5 & isHeaderFound)
  {
        relay = Serial.read();   // read relay control from AgOpenGPS
        speeed = Serial.read();  //single byte
        distanceError = (float)(Serial.read() << 8 | Serial.read());   //high,low bytes     
        headingError = (float)(Serial.read() << 8 | Serial.read());     //high low bytes 
        isHeaderFound = false;
        isDataReady = true;              
  }        
       
  if (isDataReady)
{
..... We have solid data, and we know its the most current so do the next PID loop
}

} //end of main arduino loop
  {
Is this a good way to take a stream of numbers, find the start of them - consistently, load up the stream into variables, and then and only then allow the module to process data to control the autosteer loop? It is non blocking in any way, even if the port is disconnected it won't go wild because it always needs new data set to true to do the PID loop, and won't get locked up if no new data arrives. Seems to work very well.

Btw, speed is speeed as a variable because speed is an Arduino keyword.
 

·
Registered
Joined
·
9 Posts
In order to work right, I think that the Integral and Derivative part of the calculation needs to be done at a fixed frequency, you can't do 10 times/sec once, and then only 2times/sec, because the value of the Kd and Ki loose "consistency". If you can live without the integral part, then no problem (I'm starting without it). Maybe a way to solve it is to disconnect autosteering after 1sec of invalid data? I think it can also be good to add a "stop autosteering" input, so you can stop it with a foot switch or something.
 

·
Registered
Joined
·
5,856 Posts
Discussion Starter #4
You should be getting data every 200 msec with a 5 hz nmea and 100 with a 10 hz. The only time you miss data is if something went really wrong, but 99.99% of the time it should just be there.

In good programming though, that is the easy part, the actual program, the hard part is anticipating all the things that can go wrong and be able to handle them gracefully.
 

·
Registered
Joined
·
92 Posts
I think there is merit to separating the maths and the control elements.
I.e, the PID loop/Fuzzy inference system produces a desired steering angle at the whatever rate it receives the data. If it misses a packet, no problem, just let the control loop get on with the latest good data. If more than 1s worth of packets dropped, kill the output.
This desired steering angle is then acted upon in the control loop, which compares it against the measured steering angle and outputs appropriate PWM to the valve. This happens quite quickly, say at 25Hz. Any faster and I think the valve would struggle to react in time.
 

·
Registered
Joined
·
5,856 Posts
Discussion Starter #6
I think the oscillating frequency of the steering system is probably around 1 hz. Basic PID theory says we need a sampling frequency at ten times that as a minimum, or 10 hz. Its going to take some tricky math to get it stable with a 5 hz nmea signal.
 

·
Registered
Joined
·
4,007 Posts
A kalman filter could fill in the missing steps and get your a workable 10 Hz signal perhaps. In fact I suspect a kalman filter on the input is going to be required.
 

·
Registered
Joined
·
5,856 Posts
Discussion Starter #8
Teseler, here is that arduino code, it is in no way complete and really is just a bunch of ideas. I have to be careful if i make a change in one, changes are made in the other program and have both uploaded at once.
 

Attachments

·
Premium Member
Joined
·
398 Posts
You guys are brilliant. I am a total greenhorn when it comes to GPS and auto-steer. I know nothing about nothing, and would love to know more than that! I left the ag dealer back in 2000, when precision farming was in it's infancy. I don't want to hijack this thread, but can you point me in a direction of where I can start to learn?
 

·
Registered
Joined
·
131 Posts
Brian:

Good idea with the new thread. Should keep the AOG thread cleaner since we are working on a slightly different stage now!

A couple questions for anyone:

-Will it hurt anything if, rather than computing the PID on a timing, we just ran it every time we got new information? Potentially a little more wild depending on data? This leads into filtering the output......

-What is everyone using to dial in their coefficients in the controller? I have put together a PID controller that I have just been running on the Ardunio w/AOG and watching the writeback values to AOG while steering. Gets a rough approximation, until I can put together a physical control system.

-Should we as a group decide on a specific output format(or two) from the control system? Maybe pwm? Range? Are we checking a steering sensor? Specifics help in design!

One more for Brian:

Is it necessary to have both a section control and an autosteer communication option in AOG if the section control is sent through the autosteer as well? Maybe wrap them into one? Or are we looking ahead to $$$$ unlocks here? Hahaha!
 

·
Registered
Joined
·
131 Posts
You guys are brilliant. I am a total greenhorn when it comes to GPS and auto-steer. I know nothing about nothing, and would love to know more than that! I left the ag dealer back in 2000, when precision farming was in it's infancy. I don't want to hijack this thread, but can you point me in a direction of where I can start to learn?
Well, I know for a fact that my knowledge is just enough to be dangerous haha! However, I can build on the incredible work that Brian and a few others have been generous to open up to us. I am also excited to see the whole setup evolve as others join in and help refine everything!
 

·
Registered
Joined
·
9 Posts
Brian:
-Should we as a group decide on a specific output format(or two) from the control system? Maybe pwm? Range? Are we checking a steering sensor? Specifics help in design!
I'm using the PWM to drive a DC motor, the range would be an option for those who wish to try with servos?

For the steering sensor I'm planing to use an encoder attached to the autosteer motor + a reed relay for "zero" sensing.
Whe can always have a "low level layer", so we normalize the steering sensor input (be it encoder, potentiometer...) to the PID function.
 

·
Registered
Joined
·
5,856 Posts
Discussion Starter #13 (Edited)
Brian:

Good idea with the new thread. Should keep the AOG thread cleaner since we are working on a slightly different stage now!

A couple questions for anyone:

-Will it hurt anything if, rather than computing the PID on a timing, we just ran it every time we got new information? Potentially a little more wild depending on data? This leads into filtering the output......

-What is everyone using to dial in their coefficients in the controller? I have put together a PID controller that I have just been running on the Ardunio w/AOG and watching the writeback values to AOG while steering. Gets a rough approximation, until I can put together a physical control system.

-Should we as a group decide on a specific output format(or two) from the control system? Maybe pwm? Range? Are we checking a steering sensor? Specifics help in design!

One more for Brian:

Is it necessary to have both a section control and an autosteer communication option in AOG if the section control is sent through the autosteer as well? Maybe wrap them into one? Or are we looking ahead to $$$$ unlocks here? Hahaha!
That's a lot of questions! I shall make a video and explain what i have done in regards to a lot of this. Fortunately this isn't all that new, i've been able to use experience gained from 2 wheel balancing robots to apply to this project.

I think since there are already 2 serial options, Relay and autosteer, send the relay info to both. That way it doesn't matter what you use.

The first post lists the output format from AgOpenGPS. It will be updated as things and ideas change - as they always do.

PID i feel should be calculated based on the timing of the rec'd information, it is accurate enough, consistent. And simple, there is no math required for timing at all, for example integration is just addition, derivative is just the difference between this and last or lastlast error, and Proportional, just is. Each then is just multiplied by its own respective gain.

Coefficients will be different for every motor/steering/vehicle combination. But with some experience, should have some good starting points. It really depends on the normal oscillation of the system and the length of time that is. It can be pretty tricky to adjust PID values, but that is what makes it fun.

I've built in a system in AgOpen to allow adjustment of PIDO values, i hope its acceptable. You can increase and decrease 7 values by sending a single 8 bit byte.
 

·
Registered
Joined
·
4,007 Posts
You guys are brilliant. I am a total greenhorn when it comes to GPS and auto-steer. I know nothing about nothing, and would love to know more than that! I left the ag dealer back in 2000, when precision farming was in it's infancy. I don't want to hijack this thread, but can you point me in a direction of where I can start to learn?
What aspects are you wanting to learn? There is a vibrant beginner's community around the Arduino microcontroller. http://arduino.cc

That might be a good place to start for learning about robotics and sensors and control practices.
 

·
Registered
Joined
·
5,856 Posts
Discussion Starter #15 (Edited)
A not so short video on Autosteer. I noticed when i spoke of distance error = 32020 and 32000, I should be saying OR not AND. If the distance is 32020, the autosteer is off, if its 32000 that means there is no distance to calculate, as in there is no contour line within detection.

 

Attachments

·
Registered
Joined
·
380 Posts
Nice video! I like the ability to adjust PID values in the fly. Much easier for tuning then using a serial console manually or reprogramming constantly. Would there be any usefulness with saving the PID values with the rest of the tractor config data? Maybe being able to send those values to the Arduino at the initial connection? I'm thinking ahead to when I'll have AOG in our fleet of tractors, Arduinos and tablets might get swapped around but I'd like the tractor config to stay with the tractor settings. I'm also thinking of using something like Dropbox to sync between tractors.
 

·
Registered
Joined
·
5,856 Posts
Discussion Starter #17
A video showing an actual steering motor hooked up and a quick look at the circuits. BTW, the steering position sensor will be used to limit the angular velocity of the turns. The faster you go the lower the amount of steering should be allowed. So if the PID loop wants to turn it more then that limit, you just zero it. Code not written yet, but that's pretty easy. Since there is a foot of snow on the ground, got some time to fiddle.

Video showing the setup.

 

·
Registered
Joined
·
5,856 Posts
Discussion Starter #19
Does anyone know what is required for proportional valves for auto steer? Can you buy a steering block without going thru Outback or Raven etc?

Any hydraulic gurus out there?
 

·
Registered
Joined
·
4,007 Posts
As far as control goes, Matt Reimer used a standard PWM 12V motor controller to drive the two solenoids for his autonomous tractor. PWM on one solenoid to steer in one direction, and the other to steer in the other direction I'm presuming.

I can't remember what valve block Matt was using.
 
1 - 20 of 2024 Posts
Top