How I reduce vibration when tracking

This is your starting point: https://github.com/Ardumower/ardumower/blob/master/code/ardumower/pid.h
Code:
class PID
{
  public:
    PID();
    PID(float Kp, float Ki, float Kd);
    void reset(void);
    float compute();
    double Ta; // sampling time	
    float w; // set value
    float x; // current value
    float esum; // error sum
    float eold; // last error
    float y;   // control output
    float y_min; // minimum control output
    float y_max; // maximum control output
    float max_output; // maximum output 
    float Kp;   // proportional control
    float Ki;   // integral control
    float Kd;   // differential control
    unsigned long lastControlTime;
};
 
We need to request a stable point in the system something that is unique and there is only one direction to get it. In this system it is the two maximum perimeterMag values. one is inside close to the cable and one is outside close to the cable.
If going to the minimum e.g. the cable exact you have the problem that there are other minimas far away from the cable which can also be the goal.
You can do that, but then you need things like transition timeout to get back on track.
 
ok, but -1 and 1 value is far away from the cable. Why we are not asking for 1000 and -1000 to by still close to cable ?
 
by dividing perimetermag / perimerterMagMax we give the current value( Mag) normalized to 1 (maximum)

perimeterMagMedian.getHighest() is getting the perimerterMagMax of the last 10s in my code
 
I have just make a test with part -1 1 and coeff 5 of your code and YES the result is more stable .
I think like you say the 0 is never reach on perimetermag but Something like 0.2 can be read and become stable for the PID.
With the due i can have a very fast tracking pwm=255 in straight line and without 90deg angle, but i need to reduce it and with pwm=160 all is perfectly working and the mower did not destroy the charging station, 160 is really the max for me.

I try to put a video
 
Yes The magmaxValue is fixed and manualy set in mower.cpp.
But your part of runningMedia code can be a very good way to acquire this value in a setup procedure and don't think it's good to recalculate it when tracking especially on the MEGA board.
For Denna Motor i use
P=16.5
I=8
D=0
The maxpwm value is set in Pfod setting perimeter and not the same as motor setting.
What is funny with your part of code is that (with small angle
 
well I just did it in the Statenew = STATE_PERI_TRACK https://github.com/Holoratte/ardumower/commit/548941f53de800ab5181d67ceb7eadff1bf19eac NOT YET TESTED

I was thinking to adjust the tracking speed depending on the permeterMag. Like if perimeterMag > 1000 -> curve ->slow down

I did not yet fully understand this section:

Code:
setMotorPWM( max(-motorSpeedMaxPwm/1.5, min(motorSpeedMaxPwm/1.5, motorSpeedMaxPwm/2.3 - perimeterPID.y)), 
                 max(-motorSpeedMaxPwm/1.5, min(motorSpeedMaxPwm/1.5, motorSpeedMaxPwm/2.3 + perimeterPID.y)), false)
 
I understand it follows :

setMotorPWM is defined (left motor PWM, right motor PWM, use accel)

for left motor = max(-motorSpeedMaxPwm/1.5, min(motorSpeedMaxPwm/1.5, motorSpeedMaxPwm/2.3 - perimeterPID.y)
for right motor = max(-motorSpeedMaxPwm/1.5, min(motorSpeedMaxPwm/1.5, motorSpeedMaxPwm/2.3 + perimeterPID.y)
accel = false

LEFT MOTOR:
min(motorSpeedMaxPwm/1.5, motorSpeedMaxPwm/2.3 - perimeterPID.y)
SW will take lower value motorSpeedMaxPwm/1.5 or motorSpeedMaxPwm/2.3 - perimeterPID.y.
It's protection, if calculation motorSpeedMaxPwm/2.3 - perimeterPID.y is higher then motorSpeedMaxPwm/1.5, then SW will take motorSpeedMaxPwm/1.5.

And this choosen value will compare with -motorSpeedMaxPwm/1.5 and will take a higher (max() - it's protection that we can't go under -motorSpeedMaxPwm/1.5.

uffff
 
I did not yet fully understand this section:
setMotorPWM( max(-motorSpeedMaxPwm/1.5, min(motorSpeedMaxPwm/1.5, motorSpeedMaxPwm/2.3 - perimeterPID.y)),
max(-motorSpeedMaxPwm/1.5, min(motorSpeedMaxPwm/1.5, motorSpeedMaxPwm/2.3 + perimeterPID.y)), false)

Yes it's not very easy to understand all this in one line off code but it's simple.

The min and max value is here to be sure to stay Under the Maxpwm
In fact in the tracking to be sure the 2 Wheel rotate we set a fix part of motorSpeedMaxPwm here for example motorSpeedMaxPwm/2.3 and accel one Wheel with the perimeterPID.y and brake the other with the same value.


Here the video for tracking with your 5*....
Good and perfectly working tracking with the DUE
https://youtu.be/yUL1JRDJ76Q
and bad but very funny at maxspeed pwm=255 and little change in the code to not lost the wire in 90Deg angle
https://youtu.be/-s58Jhmn8r4
Normaly i think it's can work on the MEGA but not so faster.
 
ok I got it..

but with my mega i see these funny 90degree turns already at slow speed, at leas sometimes. Maybe I am already close to max speed possible... we will see.
I cannot test today, we have rainy weather...

:unsure:
 
On Github in your code there are 2 state for the tracking
If blockinnerwheel=true in pfod

line 235 236 the mower lost the wire so it's hard angle so 1 wheel is near stop (/6) and the other (/2) PID is not use
You can gently change the /2 by /1.8 /1.5 etc..... the /6 can be stay or replace all the motorSpeedMaxPwm/6 by 0 to find quicly the wire but not smooth.

line 271 272 you are on the wire so the PID is used it's straight line
You can gently change the /2.3 by /2 /1.8 /1.5 ...

This change increase the speed but need to be adapt with your motor and perimeter pid.
 
I appreciate all your efforts on getting the tracking smoother, and we can pull your changes into the master code if you make a github pull request for it. If I understand correctly, your approach is to avoid getting into the 'dead band' where the perimeter signal is always zero (0) and that normally makes the zig-zag motion.

Idea: Maybe you can make this approach even more general and allow the user to enter signal strength (percent) as set-point for the tracking? For example, tracking at 90% maximum seen signal strength (mag). That would allow us to track beside the perimeter wire and is very helpful if trees, bushes etc. have been grown over time, using wider tires, wider chassis etc...
 
ok, I will try implement code today afternoon on my mower and I will inform you about result.
But not sure, if code change isn't too complicated. I'm lost when you send second list of changes :-(
Alex
 
Oben