Difference between revisions of "Component: Formula AllCode (Mechatronics)"

From Flowcode Help
Jump to navigationJump to search
(XML import)
 
 
Line 20: Line 20:
  
 
==Examples==
 
==Examples==
''<span style="color:red;">No additional examples</span>''
+
 
 +
===Example 1 - LED Knightrider===
 +
 
 +
Everyone remembers the iconic back and forth LED effect on "KIT" the classic TV series Knight Rider.
 +
 
 +
Here is a simple program that replicates the effect using the LEDs on the Formula AllCode.
 +
 
 +
{{Fcfile|LED_Knightrider.fcfx|Knightrider Example}}
 +
 
 +
 
 +
===Example 2 - Drive in a Shape===
 +
 
 +
The logo movement commands combine motor control with encoder feedback to try and ensure that the robot's motors are moving as expected.
 +
 
 +
Here is a simple program that drives the Formula AllCode in a triangle pattern followed by a square pattern using the Logo movement commands.
 +
 
 +
{{Fcfile|DriveShapes.fcfx|DriveShapes Example}}
  
  

Latest revision as of 15:57, 3 August 2016


Author Matrix TSL
Version 1.2 (Release)
Category Mechatronics


Image Formula AllCode component

A component to allow all the features of the Formula AllCode robot to be investigated. Fully simulated component which can interact with simulated objects on the panel as well as control the real hardware.

Examples

Example 1 - LED Knightrider

Everyone remembers the iconic back and forth LED effect on "KIT" the classic TV series Knight Rider.

Here is a simple program that replicates the effect using the LEDs on the Formula AllCode.

FC6 Icon.png Knightrider Example


Example 2 - Drive in a Shape

The logo movement commands combine motor control with encoder feedback to try and ensure that the robot's motors are moving as expected.

Here is a simple program that drives the Formula AllCode in a triangle pattern followed by a square pattern using the Logo movement commands.

FC6 Icon.png DriveShapes Example


Downloadable macro reference

PlayNote

Outputs a single tone from the onboard speaker for the period specified.

Parameters

UINT Note
Sets the pitch of the note in Hz. Range: 1 - 10000
UINT Time
Time period to play the note for in milliseconds. Range: 0 - 65535 ms


Return value

This call does not return a value


LEDOn

Switches on a single LED on the front of the Formula Allcode.

Parameters

BYTE LED
Which LED to switch on, range 0-7


Return value

This call does not return a value


BluetoothTransmit

Sends a byte via the Bluetooth data connection.

Parameters

BYTE Data


Return value

This call does not return a value


LCDPrintString

Prints a string to the graphical LCD.

Parameters

BYTE X
The horizontal start pixel. Range 0-127
BYTE Y
Y coordinate to print the string. Range 0-31
<- STRING Data
This parameter may be returned back to the caller
UINT Transparent


Return value

This call does not return a value


LogoConfigure

The Logo movement may sometimes be slightly off in terms of distance or angle.

Before tweaking the factory values check that the wheels are pushed well onto their shafts but not tight against the FA body. Also check the tyre is on the wheel correctly.

Parameters

FLOAT Distance
mm per encoder step. default = 0.32
FLOAT Angle
mm of travel per degree. default = 0.7295


Return value

This call does not return a value


Stop

Stops both motors.

Parameters

This macro has no parameters


Return value

This call does not return a value


ReadBattery

Reads the current voltage level from the LiPo battery.

Return value is the battery voltage in Volts.

Take care not to run the battery too low.

Voltages lower than 3.4V may damage the battery.

Parameters

This macro has no parameters


Return value

FLOAT


LEDOff

Switches off a single LED on the front of the Formula Allcode.

Parameters

BYTE LED
Which LED to switch on, range 0-7


Return value

This call does not return a value


LCDPrintNumber

Prints a numeric value to the graphical LCD.

Parameters

BYTE X
The horizontal start pixel. Range 0-127
BYTE Y
Y coordinate to print the string. Range 0-31
UINT Number
BYTE Transparent


Return value

This call does not return a value


LEDWrite

Allows control of all 8-LEDs on the front of the Formula Allcode.

Parameters

BYTE LED_Byte
8-bit binary value to write to the 8 LEDs


Return value

This call does not return a value


BluetoothCheckConnection

Checks the status of the Bluetooth connection.

Returns 0 for not paired and 1 for paired.

Parameters

This macro has no parameters


Return value

BYTE


ReadMic

Reads the current audio signal level from the on-board microphone.

Return value range: 0 to 4095

Parameters

This macro has no parameters


Return value

UINT


AudioQueueLength

Retreives the current length of valid data within the audio queue

Parameters

This macro has no parameters


Return value

UINT


AudioAddToBuffer

Writes a value to the 16-bit audio output buffer.

Parameters

UINT Data


Return value

This call does not return a value


ReadSwitch

Reads the value of one of the switches from the front of the Formula Allcode.

Parameters

BYTE Switch
Which switch do we want to read 0=Left, 1=Right


Return value

BYTE


CheckLine

Checks to see if a line sensor is within the master threshold distance.

Returns 0 if the IR reading is below the threshold.

Returns 1 if the IR reading is greater than or equal to the threshold.

Parameters

BYTE Sensor
Range: 0 to 1 - 0=Left, 1=Right


Return value

BYTE


AudioStreamControl

Allows control of the audio output functionality via the onboard speaker.

Data is loaded into the audio output buffer using the AddToBuffer function.

Parameters

BYTE Mode
0=Off, 8=8-bit Mode, 16=16-bit Mode
BYTE SampleRate
Sets the sample rate 0=8KHz, 1=16KHz


Return value

This call does not return a value


SpinLeft

Spins the formula flowcode on the spot in an anticlockwise direction as seen from above.

Parameters

BYTE Power
Amount of power to use to drive motor. Range 0-100


Return value

This call does not return a value


LogoTurnLeft

Rotates the robot left by a specific angle using the encoders as feedback to ensure

the robot turns evenly. Automatically stops at the specified turn angle.

Parameters

UINT Angle
Angle in degrees you wish to rotate. Range 1-65536


Return value

This call does not return a value


Forward

Drives both motors of the formula flowcode forwards with the power specified.

Parameters

BYTE Power
Amount of power to use to drive motor. Range 0-100


Return value

This call does not return a value


LCDWriteByte

No additional information


Parameters

BYTE Data
BYTE X
BYTE Y


Return value

This call does not return a value


BluetoothReceive

Attempt to read a byte from the Bluetooth receive queue.

Parameters

This macro has no parameters


Return value

BYTE


LCDDrawLine

Draws a line on the LCD.

Parameters

BYTE X1
Range 0-127
BYTE Y1
Range 0-31
BYTE X2
Range 0-127
BYTE Y2
Range 0-31


Return value

This call does not return a value


BluetoothQueueLength

Reads the length of received Bluetooth data in bytes.

Parameters

This macro has no parameters


Return value

UINT


BluetoothTransmitString

Sends a string via the Bluetooth data connection.

Parameters

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


Return value

This call does not return a value


LCDBacklight

Controls the brighness of the LCD backlight

Parameters

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


Return value

This call does not return a value


AudioReadFromBuffer

Allows the audio buffer to be used for other streaming data such as recording the mic.

Parameters

This macro has no parameters


Return value

UINT


ReadLineSensor

Reads the analogue value from the specified IR line sensor.

Return value range: 0 to 4095

4095 represents the object is reflecting the most light.

Parameters

BYTE Channel
Range: 0 to 1 - 0=Left, 1=Right


Return value

UINT


LogoTurnRight

Rotates the robot right by a specific angle using the encoders as feedback to ensure the robot turns evenly. Automatically stops at the specified turn angle.

Parameters

UINT Angle
Angle in degrees you wish to rotate. Range 1-65536


Return value

This call does not return a value


SpinRight

Spins the formula flowcode on the spot in a clockwise direction as seen from above.

Parameters

BYTE Power
Amount of power to use to drive motor. Range 0-100


Return value

This call does not return a value


CheckIR

Checks to see if a IR sensor is within the master threshold distance.

Returns 0 if the IR reading is below the threshold.

Returns 1 if the IR reading is greater than or equal to the threshold.

Parameters

BYTE Sensor
Range: 0 to 7 - 0=Left, 1=Front Left, 2=Front, 3=Front Right, 4=Right, 5=Rear Right, 6=Rear, 7=Rear Left


Return value

BYTE


LCDPlotPixel

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

Parameters

BYTE X
Sets the X coordinate - Range 0-127
BYTE Y
Sets the Y coordinate - Range 0-31


Return value

This call does not return a value


LCDSetBackgroundColour

Sets the pixel colour to drive the LCD.

Default colour is 1 where a set pixel is black and the background is white.

Parameters

BYTE Colour
Range 0-1 : 0=White, 1=Black


Return value

This call does not return a value


ReadIRSensor

Reads the analogue value from the specified IR distance sensor.

Return value range: 0 to 4095

4095 represents the object is very close.

Parameters

BYTE Channel
Range: 0 to 7 - 0=Left, 1=Front Left, 2=Front, 3=Front Right, 4=Right, 5=Rear Right, 6=Rear, 7=Rear Left


Return value

UINT


SetMotors

Sets the speed and direction of the Formula Allcode motors.

Parameters

INT Left
Valid Range = -100 to 100
INT Right
Valid Range = -100 to 100


Return value

This call does not return a value


LogoBackwards

Drives the robot backward using the encoders as feedback to ensure

the robot drives straight. Automatically stops at the specified distance.

Parameters

UINT Distance
Distance you want to robot to drive in mm. Range 1-65535


Return value

This call does not return a value


EncoderReset

Resets the encoder counters to 0

Parameters

This macro has no parameters


Return value

This call does not return a value


Reverse

Drives both motors of the formula flowcode backwards with the power specified.

Parameters

BYTE Power
Amount of power to use to drive motor. Range 0-100


Return value

This call does not return a value


WaitForSwitch

Waits for the specified switch to be pressed.

Parameters

BYTE Switch
Which switch do we want to wait for 0=Left, 1=Right, 2=Either, 3=Both


Return value

This call does not return a value


ReadLDR

Reads the current light level from the on board light sensor.

Return value range: 0 to 4095

4095 represents the maximum level of light and 0 represents the minimal level of light.

Parameters

This macro has no parameters


Return value

UINT


LCDDrawRectangle

Draws a rectange on the LCD.

Parameters

BYTE X1
Range 0-127
BYTE Y1
Range 0-31
BYTE X2
Range 0-127
BYTE Y2
Range 0-31
BYTE Transparent
Sets the transparency of the box, 0=Box contains background colour, 1=Box contains previous pixel data
BYTE Solid
Chooses to fill the box with colour, 0=Box contains transparency data, 1=Box contains foreground colour


Return value

This call does not return a value


EncoderReadCount

Reads one of the motor encoder counters.

Each encoder count is equal to 0.314159 mm.

Parameters

BYTE Channel
0 = LeftCount, 1=RightCount


Return value

UINT


CheckUSB

Checks to see if a USB cable is connected to the robot.

Returns 0 for no connection and 1 for an active connection.

Parameters

This macro has no parameters


Return value

BYTE


LCDSetForegroundColour

Sets the pixel colour to drive the LCD.

Default colour is 1 where a set pixel is black and the background is white.

Parameters

BYTE Colour
Range 0-1 : 0=White, 1=Black


Return value

This call does not return a value


Initialise

Starts up the Formula Allcode PWM for motor control and performs the wait for button press if enabled.

Parameters

This macro has no parameters


Return value

This call does not return a value


LogoForwards

Drives the robot forward using the encoders as feedback to ensure

the robot drives straight. Automatically stops at the specified distance.

Parameters

UINT Distance
Distance you want to robot to drive in mm. Range 1-65535


Return value

This call does not return a value


LogoSetSpeed

Sets the cruise speed for LOGO type macros.

Default speed 20%.

Parameters

BYTE Speed
Range 1-100, Default 60


Return value

This call does not return a value


LCDClear

Clears the contents of the graphical LCD.

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

Wait For Button

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

Determines if the program will automatically wait for one of the front switches to be pressed before executing the program.

Ran as part of the initialise function after the various components have been initialised.

Show Creation Info

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

Specifies what information is shown to the user on calling the initialise function.

The time and date shown are the compilation time and date to help pinpoint the firmware version.

Bluetooth Reset

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

Decides if the Bluetooth data connection can reset the Formula AllCode.

Used by mLoader when programming via Bluetooth to allow reprogramming without having to physically touch the robot.

To ensure programming security set this option to No.

Use Motor Feedback

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

Controls when the motor feedback is used.

No - Speed control feedback is not used for SetMotors commands.

Yes - Speed control feedback is used for the SetMotors commands.

SetMotors commands include Forward, Backward, SpinLeft, SpinRight as well as SetMotors itself.

Logo functions always use feedback.

IR Distance

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

IR Threshold used with the CheckIR macro

Line Sensitivity

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

No additional information


Sim Speed (1 - 100)

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

Sets the simulated amount of movement relative to the speed of the Formula Allcode.

Timer Interval (ms)

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

Interval in milliseconds between each simulated movement of the Formula Allcode robot.

Collision Method

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

Select which objects the robot sensors will interact with.

Light Source

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

Panel object specified as the simulation light source.

Used when simulating "find the light" type tasks.