[Dprglist] PID

Murray Altheim murray18 at altheim.com
Thu Oct 1 01:23:48 PDT 2020


On 1/10/20 3:51 am, Chris N via DPRGlist wrote:
> Murray,
> 
> In order for yourself and others to make sense of this information, it 
> really ought to be time stamped.

Hi Chris,

Yes, very much agreed, that seems to be what was clearly missing, and as I noted
to David putting the timestamp into the log and pushing the messaging up from
the PID class to the PIDController class (where the loop lives and I can get
access to both PIDs) makes very good sense, probably marginally improves the
performance (since I'm reducing the number of log calls even if I'm upping the
amount of output data a bit).

> What I found most useful is to use a CSV format and to have the timestamp AND ALL RELEVANT VALUES TOGETHER  in each line.
> 
> So in your case then, each line might contain the following (only showing values for one motor for brevity - you obviously want stbd and port on the same line):
> 
> timestamp,  stbd absolute encoder count,  stbd measured velocity (in whatever units you keep track of it),   stbd target velocity (aka setpoint),  stbd commanded motor power (e.g. PWM duty cycle % or equivalent unit)  stbd error, stbd P 
> contribution, stbd I contribution, stbd D contribution, stbd Kp, stbd Ki, stbd Kd
> 
> Some of these values (e.g. error) are technically redundant, because they can be calculated (target velocity - measured velocity) by Excel, but explicitly recording what your code calculates is a good sanity check.   Also, the PID tuning 
> parameters Kp, Ki and Kd (possibly a separate set for each motor) usually don't change during a test run, but recording them along with the measurements and calculated values helps a lot when you later go back and look at the data.

Actually, I really like marching orders. All very sensible.

I was already using a vertical bar character as a delimiter in some places so
I'll just standardise on that so it'll be (after filtering out the other
messages) essentially a CSV file.

I can probably create a sed script or something to convert the raw log message
into pure CSV. Right now I'm just doing a Select All and Copy from my ssh window
as I figure that's less load on the Raspberry Pi but I could also modify my
Logger class to write to a log file.

As Bob suggested I might even just load this directly to ElasticSearch. I've
been thinking over the past few days of writing a small Python-to-RESTful
endpoint class so I could push the log messages directly to a service, but I
think that might be too much of a load on the Pi, esp. since I don't really
need the data to be live; it can be processed after the robot's run.

> I usually also include the readings from each sensor and even  internal state information from my control logic , such as the value of certain critical global variables,  or the state (literally) that certain finite state machines were in 
> at that point in time.
> 
> This may sound like a large volume of output, but if you keep the formatting minimal (e.g. CSV - like) , it is actually not that much.     I found the following to be a compromise between making it readable to a human and still easily 
> readable by Excel:  instead of strictly using comma separated "values", I include a few labels in between.
> 
> Example:
> 
> instead of
> ..........,1456,1460,75,73,.......
> 
> I do
> .........E,1456,1460,M,75,73,........
> 
> "E" is the prefix "reminding me" that the next 2 values represent the absolute encoder count
> 
> "M" is the prefix "reminding me" that the next 2 values represent the commanded motor power / pwm.
> 
> Excel will happily put the E and the M into separate columns and therefore these prefixes don't get in the way of plotting, and my brain is happy because it can easily parse each line of 20+ values
> 
> Of course you can still interleave the CSV formatted output with informational messages that don't adhere to this, but then you need to filter out those lines before importing into Excel or tell Excel to ignore those lines.
All great ideas, thanks. I was actually thinking of creating a signature
line at the beginning of a robot session that writes out a header line
so when it's been imported into Excel it's already got labels. What as
you may have noticed I'm doing is using the Python colorama library to
colorise the output, which is what I'm using to help me see what's
happening.

Thanks for the suggestions, I'll try to incorporate much of this.

Murray

...........................................................................
Murray Altheim <murray18 at altheim dot com>                       = =  ===
http://www.altheim.com/murray/                                     ===  ===
                                                                    = =  ===
     In the evening
     The rice leaves in the garden
     Rustle in the autumn wind
     That blows through my reed hut.
            -- Minamoto no Tsunenobu



More information about the DPRGlist mailing list