Component: Servo Controller (Mechatronics)
Author | Matrix Ltd |
Version | 2.0 (Release) |
Category | Mechatronics |
Contents
Servo Controller component
Can control up to eight standard PWM driven servo's.
Supports 8-bit and 16-bit movement resolutions. '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 onwards 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. Servo Example 1 The Servo controller is linked to the standard servo component but this could be linked to any object on the panel.
Creating a multi-axis actuator using servo motors
This example links two servo motors together using panel primitive objects and groups. 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.
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 assign the new position. Range: 0-7
- BYTE Position
- Position to jump to. Range: 0-255
Return value
- This call does not return a value
MoveToPositionInt
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 assign the new position. Range: 0-7
- UINT Position
- Target position to move towards. Range: 0-65535
Return value
- BYTE : 1 = reached target, 0 = target not reached.
SetPositionInt
Moves directly to the specified position with no interpolation.
Uses a 16-bit position parameter to add extra precision.
Parameters
- BYTE Channel
- The channel to assign the new position. Range: 0-7
- UINT Position
- Position to jump to. Range: 0-65535
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 assign the new position. Range: 0-7
- BYTE Position
- Target position to move towards. Range: 0-255
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
IsAutoMoving
Is the AutoMoveToPosition movement complete.
Returns 1 if the servo is still moving.
Returns 0 if the servo movement is complete.
Parameters
- This macro has no parameters
Return value
AutoMoveToPosition
Automatically moves towards the new position at a fixed rate determined by the AutoMoveSpeed.
Parameters
- BYTE Channel
- The channel to assign the new position. Range: 0-7
- BYTE Position
- Position to automatically move to. Range: 0-255
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 shown in the Servo_Period_Multiplier property.
Parameters
- BYTE Speed
- 1=Slowest (Default), 2= Double, 3=Triple, 4=Quadruple
Return value
- This call does not return a value
AutoMoveToPositionInt
Automatically moves towards the new 16-bit position at a fixed rate determined by the AutoMoveSpeed.
Parameters
- BYTE Channel
- The channel to assign the new position. Range: 0-7
- UINT Position
- Position to automatically move to. Range: 0-65535
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.
Channel 1
This property is of type Single digital pin and can be referenced with the variable name pin1.
Pin on which to output PWM for the servo motor.
Channel 2
This property is of type Single digital pin and can be referenced with the variable name pin2.
Pin on which to output PWM for the servo motor.
Channel 3
This property is of type Single digital pin and can be referenced with the variable name pin3.
Pin on which to output PWM for the servo motor.
Channel 4
This property is of type Single digital pin and can be referenced with the variable name pin4.
Pin on which to output PWM for the servo motor.
Channel 5
This property is of type Single digital pin and can be referenced with the variable name pin5.
Pin on which to output PWM for the servo motor.
Channel 6
This property is of type Single digital pin and can be referenced with the variable name pin6.
Pin on which to output PWM for the servo motor.
Channel 7
This property is of type Single digital pin and can be referenced with the variable name pin7.
Pin on which to output PWM for the servo motor.
Peripherals
This property is of type Line of text and can be referenced with the variable name Peripherals.
Lists the internal peripherals of the MCU used by the component.
When the servo motor is initialised you will not be able to use the listed peripherals for other functionality.
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.
Trim 1
This property is of type Fixed list of ints and can be referenced with the variable name trim1.
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.
Trim 2
This property is of type Fixed list of ints and can be referenced with the variable name trim2.
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.
Trim 3
This property is of type Fixed list of ints and can be referenced with the variable name trim3.
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.
Trim 4
This property is of type Fixed list of ints and can be referenced with the variable name trim4.
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.
Trim 5
This property is of type Fixed list of ints and can be referenced with the variable name trim5.
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.
Trim 6
This property is of type Fixed list of ints and can be referenced with the variable name trim6.
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.
Trim 7
This property is of type Fixed list of ints and can be referenced with the variable name trim7.
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.
Period Multiplier
This property is of type Unsigned integer and can be referenced with the variable name Servo_Period_Multiplier.
Number of instructions for 1 / 256th of the positional accuracy.
This sets the default movement speed to maintain legacy move speeds.
Also sets the multiplication factor to convert from a byte 0-255 to a clocked position value.
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)).
Servo Object 1
This property is of type Panel object and can be referenced with the variable name sim1.
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)).
Servo Object 2
This property is of type Panel object and can be referenced with the variable name sim2.
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)).
Servo Object 3
This property is of type Panel object and can be referenced with the variable name sim3.
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)).
Servo Object 4
This property is of type Panel object and can be referenced with the variable name sim4.
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)).
Servo Object 5
This property is of type Panel object and can be referenced with the variable name sim5.
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)).
Servo Object 6
This property is of type Panel object and can be referenced with the variable name sim6.
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)).
Servo Object 7
This property is of type Panel object and can be referenced with the variable name sim7.
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)).