Component: Servo Controller (Mechatronics)

From Flowcode Help
Jump to navigationJump to search


Author Matrix Ltd
Version 1.2 (Release)
Category Mechatronics


Image Servo Controller component

Can control up to eight standard PWM driven servo's. 'Servo Object' properties allow you to connect the controller to on-screen simulations using the "Servo Motor" component and its derivatives.


Examples

Importing from v5

The servo component in Flowcode v6 has a new Initialise macro which will need to be added to your program before any other calls to the servo motor component are made.


Controlling a servo with an analogue input

This example reads the value of the analogue potentiometer and uses this to set the position of the servo motor. FC6 Icon.png Servo Example 1 The Servo controller is linked to the standard servo component but this could be linked to any object on the panel.

ServoLink.jpg


Creating a multi-axis actuator using servo motors

This example links two servo motors together using panel primitive objects and groups. FC6 Icon.png Servo Example 2 The Servo controller can handle up to 8 motors and is used to control both of the standard servo components on the panel.

LinkedServo.jpg

Downloadable macro reference

DisableServo

Disables a servo channel effectivly disabling the motor.

Parameters

BYTE Channel
The channel to set the position for. First channel is zero.


Return value

This call does not return a value


SetPosition

Moves directly to the specified position with no interpolation.

Parameters

BYTE Channel
The channel to set the position for. First channel is zero.
BYTE Position
Target position to move towards.


Return value

This call does not return a value


MoveToPosition

Moves a single step towards the new position, the rate of movement is determined by how often the move to macro is called. Returns 1 if the position has been reached.

Parameters

BYTE Channel
The channel to set the position for. First channel is zero.
BYTE Position
Target position to move towards.


Return value

BYTE : 1 = reached target, 0 = target not reached.


SetTrim

Allows the level of trim for each servo channel to be adjusted progmatically.

Parameters

BYTE Channel
The channel to set the position for. First channel is zero.
BYTE Trim
0=0us, 1=+25us, 2=+50us, 3=+75us, 4=+100us, 5=-25us, 6=-50us, 7=-75us, 8=-100us


Return value

This call does not return a value


AutoMoveToPosition

Automatically moves towards the new position with a fixed rate of 100 steps per second.

Parameters

BYTE Channel
The channel to set the position for. First channel is zero.
BYTE Position
Position to move to.


Return value

This call does not return a value


EnableServo

Enables a servo channel effectivly setting the position of the motor to the value in the local position variable.

Parameters

BYTE Channel
The channel to set the position for. First channel is zero.


Return value

This call does not return a value


SetAutoMoveSpeed

Sets the speed of the auto move to position macro.

Default speed is 1.

Parameters

BYTE Speed


Return value

This call does not return a value


Initialise

Sets up the servo motor interrupts

Parameters

This macro has no parameters


Return value

This call does not return a value


Simulation macro reference

This component does not contain any simulation macros


Property reference

Channels (1 - 8)

This property is of type Fixed list of ints and can be referenced with the variable name Channel_Count.

Set the number of servo's that you need to control.

Value from 1 to 8.

Channel 0

This property is of type Single digital pin and can be referenced with the variable name pin0.

Pin on which to output PWM for the servo motor.

Trim 0

This property is of type Fixed list of ints and can be referenced with the variable name trim0.

Trim the pulse width for this channel. Use this to trim the positioning of two servos so that similar

input values will produce the same degree of movement.

Minimum (us)

This property is of type Unsigned integer and can be referenced with the variable name min_pulse_width.

Shortest pulse width that will be used.

Maximum (us)

This property is of type Unsigned integer and can be referenced with the variable name max_pulse_width.

Longest pulse width used for the PWM signals.

Servo Object 0

This property is of type Panel object and can be referenced with the variable name sim0.

Drag a servo motor component onto the System Panel, and then select it here, to create

an on screen simulation of the way that your flowchart moves the servo's.

Servo motors should be based on the 'Servo Motor Base' component, or use a custom component

set to responf to 'User.Notify' events (ID = n/a, Data = Position (0-127)).