PVT Motion

This AeroScript program configures MovePVT() to generate a simple point sequence.

// PVT Example:
// Demonstrates a PVT move sequence by performing a sinusoidal oscillation.
// Configure Data Collection to collect the PositionCommand on the X axis.

#define PI 3.1415926535897932384626433832795

program

	// Enable and home the axis.
	Enable(X)
	Home(X)

	// Trigger a data collection snapshot in Studio.
	AppDataCollectionSnapshot()

	Dwell(0.005)

	// This program requires absolute coordinates.
	SetupTaskTargetMode(TargetMode.Absolute)

	// Perform an oscillation using a series of MovePvt() moves.
	// This command specifies a 5 cycle oscillation with a distance of 2.0 at a 500Hz frequency.
	// A 10kHz PVT point generation rate is used here.
	OscillatePVT(X, 2.0, 500.0, 5, 10.0)

	// Wait for motion to complete.
	WaitForInPosition(X)

	// Disable the axis.
	Disable(X)

	// Stop data collection.
	AppDataCollectionStop()

end


// Generates an oscillation. Assumes that the starting position is 0.0.
function OscillatePVT($axis as axis, $distance as real, $frequency as real, $cycles as real, $updateRate as real)
	var $oscillateTime = 0
	var $oscillatePosition
	var $oscillateVelocity

	// Enter critical section to guarantee one PVT per millisecond.
	CriticalSectionStart()

	// Compute the necessary number of milliseconds of motion and repeat the
	// sequence for each millisecond.
	repeat (($cycles / $frequency) * 1000)

		// Generate the correct number of points each millisecond by making one
		// MovePvt() call for each point. Note that $updateRate is specified in kHz.
		repeat ($updateRate)
			$oscillatePosition = ($distance / 2) * (Sin(2 * PI * $frequency * $oscillateTime + 1.5 * PI) + 1)
			$oscillateVelocity = PI * $frequency * $distance * Cos(2 * PI * $frequency * $oscillateTime + 1.5 * PI)
			MovePvt([$axis], [$oscillatePosition], [$oscillateVelocity], 1.0 / $updateRate)
			$oscillateTime = ($oscillateTime + 1 / ($updateRate * 1000)) % (1.0 / $frequency)
		end

		// Wait until the next millisecond before generating more points.
		Dwell(0.001)
	end

	// Generate the final point.
	MovePvt([$axis], [0], [0], 1.0 / $updateRate)

	CriticalSectionEnd()

end