(read-log-data directory fileName foutput) // Apply foutput to each line of the log file directory/filename (read-log-data-to-file directory logfileName datafileName foutput cr?) // The not #f results of applying foutput to each line of // directory/logfileName are stored in directory/datafileName. // By default a carriage-return is added to each line in the outputfile.For each entry in the log-file of the form
foutput
above.
This example illustrates how to extract the odometry information from a log created as in Example 1.
(define (odometry-info directory logfileName volume outputFile ) (read-log-data-to-file directory (format #f "~a-vol~a.log" logfileName volume) outputFile (lambda (line) (let ((odo (assoc 'location (third line)))) (if odo (format #f "~a ~a" (first (cdr odo)) (second (cdr odo))) ))) ) )end of example
Notice that the function passed to read-log-data-to-file takes one argument (line) and returns an string. (third line) denotes the value you store for a particular line (entry) in the log.
Next we illustrate a more complex example on how to manipulate data in a log. The example below defines a function that produces a file with the (x,y) coordinates associated with the different rangefinder readings logged in a file. Odometry information is used to transform the rangefinder points (in the wheelchair frame of reference) to the global frame of reference associated with the odometry.
(define (integrate-readings directory logfileName volume outputFile ) (read-log-data-to-file directory (format #f "~a-vol~a.log" logfileName volume) outputFile (lambda (line) (let ((points (assoc 'points (third line))) (odo (assoc 'location (third line))) (x0 #f) (y0 #f) (th0 #f) (lineout "") ) (when (and odo points) (set! points (cdr points)) (set! x0 (first (cdr odo))) (set! y0 (second (cdr odo))) (set! th0 (third (cdr odo))) (set! points (map (lambda (p) (set! p (rotate-point p (+ (- *pi/2*) th0))) (list (+ x0 (first p)) (+ y0 (second p))) ) points)) (set! lineout "") (dolist (p points) (set! lineout (format #f "~a\n~a ~a" lineout (first p) (second p)))) lineout ))) #f ;;; don't add carriage return to lines ) )end of example