Component: Formula AllCode API (Mechatronics)

From Flowcode Help
Jump to navigationJump to search


Author Matrix Ltd
Version 1.2 (Release)
Category Mechatronics


Image Formula AllCode API component

A simulation only component to allow the Formula AllCode robot to be controlled via it's API interface and Bluetooth data connection without having to compile or re-program the robot.

Examples

The COM port for the Formula AllCode can be set via the panel properties which can be exposed to the SCADA runtime user.


LED Control

Controls the LEDs on the Formula AllCode by collecting the analogue value of a potentiometer on the simulation panel and sending the value to the robot.

FC6 Icon.png LED Control Example


Motor Control Using Keypad

Uses the keypad on the simulation panel to control the speed and direction of the motors. Key 2 drives the robot forwards, 8 drives backwards, 4 and 6 turn the robot on the spot.

FC6 Icon.png Motor Control Example


Motor Control Using Joystick

A simple example showing how to drive the Formula AllCode robot around in API mode using a panel based joystick control.

FC6 Icon.png Formula AllCode Bluetooth


Proximity Alarm

Reads the front IR sensor on the Formula AllCode from the Flowcode simulation. If a near object is sensed then the Flowcode simulation will speak the word "Hello" using the Speech component.

FC6 Icon.png Proximity Alarm Example


Driving Simulation using the API component

An example showing how to use the API component to drive the Formula AllCode robot component on the simulation panel.

FC6 Icon.png FA API Sim Demo


JCB Bot Blog

Blog with example code showing how to drive the Formula AllCode robot using Key Mappings and how to add extra features such as a 3D printed cover and servo motors to operate a digger arm and bucket.

JCB Bot

Downloadable macro reference

This component does not contain any downloadable macros

Simulation macro reference

PlayNote

Plays a note using the speaker on the FA

Parameters

UINT Note
Range 1 to 65535 in Hz
UINT Delay
Number of milliseconds to play the note for


Return value

This call does not return a value


LEDOn

Sets a single LED 0-7

Parameters

BYTE index
Range: 0-7


Return value

This call does not return a value


LCDPrintString

Prints a string to the LCD

Parameters

BYTE X
X Pixel 0-127
BYTE Y
LCD Y Coordinate 0-31
<- STRING Data
This parameter may be returned back to the caller


Return value

This call does not return a value


ReadLight

Reads the light sensor 0-4095 - 4095 = Max Brightness

Parameters

This macro has no parameters


Return value

UINT


Right

Rotates the robot right - waits for the angle to be traversed before returning

Parameters

UINT Angle
Angle to turn in degrees


Return value

This call does not return a value


SetLogoSpeed

Sets the speed of logo movements

Parameters

BYTE Speed
Logo Speed 1-100 - Default 40


Return value

This call does not return a value


ReadAllSensors

Samples all of the robot's sensors at once, storing the values locally

Parameters

This macro has no parameters


Return value

This call does not return a value


SampleMag

Samples the magnetometer

0 = no new data, 1 = new data available

Parameters

This macro has no parameters


Return value

BYTE


CardCreate

Attempts to create a file on the SD card

255=Error, 1=File Already Exists, 0=Create OK

Parameters

<- STRING Filename
This parameter may be returned back to the caller


Return value

BYTE


LCDPrintNumber

Prints a 16-bit signed number to the LCD

Parameters

BYTE X
X Pixel 0-127
BYTE Y
LCD Y coordinate 0-31
<- INT Number
Range -32768 to 32767
This parameter may be returned back to the caller


Return value

This call does not return a value


LEDOff

Clears a single LED 0-7

Parameters

BYTE index
Range: 0-7


Return value

This call does not return a value


LEDWrite

Sets the value of the LEDs as an 8-bit output

Parameters

BYTE Value
LED value 0=All Off, 255 = All On


Return value

This call does not return a value


ReadAxis

Reads a single X/Y/Z axis from the accelerometer sensor.

Parameters

BYTE index
0=X, 1=Y, 2=Z


Return value

INT


ServoSetAutoMoveSpeed

Changes the speed of the auto movements

Default - 1

Parameters

BYTE Speed
Range 1-50


Return value

This call does not return a value


CardPlayback

Plays back a .Wav file audio stream from the card

Parameters

<- STRING Filename
This parameter may be returned back to the caller


Return value

BYTE


ReadMic

Reads the microphone sensor 0 - 4095

Parameters

This macro has no parameters


Return value

UINT


ReadSwitch

Read the switch value

Parameters

BYTE index
0 (left) or 1 (right)


Return value

BYTE


SampleAccel

Samples the accelerometer

0 = no new data, 1 = new data available

Parameters

This macro has no parameters


Return value

BYTE


Left

Rotates the robot left - waits for the angle to be traversed before returning

Parameters

UINT Angle
Angle to turn in degrees


Return value

This call does not return a value


ReadIR

Reads an IR sensor

0=Left, 1=FrontLeft, 2=Front, 3=FrontRight, 4=Right, 5=RearRight,

6=Rear, 7=RearLeft

Parameters

BYTE index
0=Left, 1=FrontLeft, 2=Front, 3=FrontRight, 4=Right, 5=RearRight, 6=Rear, 7=RearLeft


Return value

UINT


LCDDrawPixel

Allows a single pixel on the LCD to be set or cleared

Parameters

BYTE X
X Pixel 0-127
BYTE Y
Y Pixel 0-31
<- BYTE State
0=White (Off), 1=Black (On)
This parameter may be returned back to the caller


Return value

This call does not return a value


ServoSetPosition

Allows one of the servo positions to be assigned

Parameters

BYTE Channel
Range 0-3
BYTE Position
Range 0-255


Return value

This call does not return a value


CardBitmap

Displays a monochrome bitmap read from the card on the LCD

Parameters

BYTE X
Range 0-127
BYTE Y
Range 0-31
<- STRING Filename
This parameter may be returned back to the caller


Return value

BYTE


CardRecordMic

Records an audio stream on the card from the microphone

Parameters

BYTE BitDepth
0=8-bit, 1=16-bit
BYTE SampleRate
Sample Rate 0=8KHz, 1=16KHz
UINT RecordTime
Time to record for in seconds, Range 0-65535
<- STRING Filename
This parameter may be returned back to the caller


Return value

BYTE


CardOpen

Attempts to open an existing file on the SD card

255=Error, 1=File not found, 0=Open OK

Parameters

<- STRING Filename
This parameter may be returned back to the caller


Return value

BYTE


Forwards

Drives the robot forwards - waits for the distance to be traversed before returning

Parameters

UINT Distance
Distance in mm


Return value

This call does not return a value


ReadBearing

Reads the compass bearing based on the degrees clockwise from magnetic north.

Parameters

This macro has no parameters


Return value

INT


GetConsoleHandle

Gets the handle to the console allowing data displaying on the panel etc.

Parameters

This macro has no parameters


Return value

HANDLE


LCDDrawLine

Allows a single pixel width line to be drawn on the LCD

Parameters

BYTE X1
X Pixel 0-127
BYTE Y1
Y Pixel 0-31
<- BYTE X2
X Pixel 0-127
This parameter may be returned back to the caller
BYTE Y2
Y Pixel 0-31


Return value

This call does not return a value


ServoAutoMoveToPosition

Allows one of the servo positions to move gradually to a new position

Parameters

BYTE Channel
Range 0-3
BYTE Position
Range 0-255


Return value

This call does not return a value


ReadAllValue

Reads a single value stored from the read all command

Index dictates which sensor value to read

Parameters

BYTE Index
0=SW, 1-8=IR, 9-10=Line, 11=Light, 12=Mic, 13-15=Accel


Return value

UINT


LCDBacklight

Allows the LCD backlight brighntess to be adjusted

Parameters

BYTE Intensity
Range 0-100, 0=Off, 1=Min Brightness, 100=Max Brightness


Return value

This call does not return a value


LCDDrawRect

Allows a rectangle to be drawn on the LCD

Parameters

BYTE X1
X Pixel 0-127
BYTE Y1
Y Pixel 0-31
<- BYTE X2
X Pixel 0-127
This parameter may be returned back to the caller
BYTE Y2
Y Pixel 0-31


Return value

This call does not return a value


ReadLine

Reads one of the IR line sensors 0-1

0=Left, 1=Right

Parameters

BYTE index
0=Left, 1=Right


Return value

UINT


ServoDisable

Allows one of the servo outputs 0-3 to be disabled

Parameters

BYTE Channel
Range 0-3


Return value

This call does not return a value


ServoEnable

Allows one of the servo outputs 0-3 to be enabled

Parameters

BYTE Channel
Range 0-3


Return value

This call does not return a value


CardReadByte

Reads a byte from the currently open file.

Starts at the beginning of the file and auto increments to the end

Parameters

This macro has no parameters


Return value

BYTE


CardErase

Attempts to delete an existing file on the SD card

255=Error, 1=File not found, 0=Delete OK

Parameters

<- STRING Filename
This parameter may be returned back to the caller


Return value

BYTE


CardWriteByte

Appends a byte to the end of the currently open file

Parameters

<- BYTE Data
This parameter may be returned back to the caller


Return value

This call does not return a value


EncoderRead

Reads one of the motor encoder counters.

Approx 0.328296mm of travel per encoder unit.

Parameters

BYTE index
0=Left, 1=Right


Return value

UINT


SetMotors

Sets the motor speeds without feedback

Range -100 to 100

Parameters

INT Left
Range -100 to 100
INT Right
Range -100 to 100


Return value

This call does not return a value


Backwards

Drives the robot backwards - waits for the distance to be traversed before returning

Parameters

UINT Distance
Distance in mm


Return value

This call does not return a value


EncoderReset

Resets the motor encoder counters

Parameters

This macro has no parameters


Return value

This call does not return a value


LCDVerbose

Allows the LCD to automatically report the API commands as they get processed.

Default - verbose on

Parameters

BYTE State
0=Off 1=On


Return value

This call does not return a value


SetProp

Allows the COM port property to be set from a parent component.

Parameters

<- STRING PropName
This parameter may be returned back to the caller
ULONG PropVal


Return value

This call does not return a value


CardInit

Attempts to startup the SD card

255=No Card, 254=Init Fail, 0=Init OK

Parameters

This macro has no parameters


Return value

BYTE


GetProp

Allows the property filter for the COM port list to be copied to a parent component.

Parameters

<- STRING PropName
This parameter may be returned back to the caller


Return value

STRING


LCDClear

Clears the LCD

Parameters

This macro has no parameters


Return value

This call does not return a value



Property reference

COM Port

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

Selects which port to communicate with, only lists ports which are currently available.

Refresh COM Ports

This property is of type True or false and can be referenced with the variable name Refresh.

When set to yes the COM port list is rescanned for newly connected or available ports.

Note that refreshing the ports list may take a few seconds depending on the number of connected ports.

Baud

This property is of type Signed integer and can be referenced with the variable name baud_rate.

Baud rate passed to the COM port to control the rate of data.

Label

This property is of type Line of text and can be referenced with the variable name label.

No additional information