Table of contents |

Data Gathering

KMotion provides a flexible method for capturing data of all types every servo sample period (90µs). This same method is how KMotion gathers step response and Bode plot data.

Basically a list of addresses and data types are defined. An end address of where to stop capturing data is set, and when triggered the Servo Interrupt will capture the specified data values. All values are converted to double precision numbers before being placed into the gather buffer. The maximum size of the Gather Buffer is 1,000,000 double precision values (8 MBytes).

	
	#define MAX_GATHER_DATA 1000000 // Size of gather buffer (number of doubles, 8 bytes each).
	

The following example shows how to setup to capture the two PWM drives (for a stepper motor) and the commaned destination for a 0.5 second time period, trigger the capture, make a simple move, wait until the capture is complete, and print the results.

	
	#include "KMotionDef.h"
	
	main()
	{
		int i,n_Samples = 0.5 / TIMEBASE;
		
		gather.Inject = FALSE; // Don't inject any Data anywhere
		
		gather.list[0].type = GATHER_LASTPWM_TYPE; // Gather PWM 0
		gather.list[0].addr = &LastPWM[0];
		
		gather.list[1].type = GATHER_LASTPWM_TYPE; // Gather PWM 1
		gather.list[1].addr = &LastPWM[1];
		
		gather.list[2].type = GATHER_DOUBLE_TYPE; // Gather Dest axis 0
		gather.list[2].addr = &chan[0].Dest;
		
		gather.list[3].type = GATHER_END_TYPE;
		
		gather.bufptr = (double *)0xfffffffc; // force more than endbuf
		gather.endptr = gather_buffer + 3 * n_Samples;
		
		TriggerGather(); // start capturing data
		
		MoveRel(0,20); // Start a motion
		
		while (!CheckDoneGather()) ; // what till all captured
		
		// print all captured data (every 50th sample)
		
		for (i=0; i<n_Samples; i+=10)
		printf("%d,%f,%f,%f\n", i,gather_buffer[i*3],
		gather_buffer[i*3+1],
		gather_buffer[i*3+2]);
  	{
	

Data will be printed to the KMotion Console Screen which is also written to a permanent log file at:

<KMotionInstallDir>\KMotion\Data\LogFile.txt

Normally data scrolls off of the Console Screen into the permanent log file, to flush all data into the log file, exit the KMotion application.

An Excel plot of the captured data is shown below.

Gather Example Plot