This example of creating a component from scratch will cover how to encapsulate a modular piece of Flowcode into a component that can be brought into a Flowcode project at will and connected just as you would in practice when physically connecting a linear actuator to a micro-controller (via a relay).
This post is the first of 2 sections which covers this subject and will cover the creating of the project for it to be ready for the creator to begin writing code to provide the functionality (which will be detailed next week)
So, let’s begin…
Firstly, a new project is started and we need to choose a target chip. In this case, “No Chip” has been selected. The first difference to a ‘usual’ Flowcode project is that you make no direct references to specific parts of any type of microcontroller. The component is intended to be a module, with no direct dependencies (and therefore limiting) to a specific core, or µC model.
To obtain the necessary 3D files for the linear actuator we consulted the RS Components website, and used the linear actuator RS: 700-9089. Once downloaded the file was opened with DesignSpark Mechanical and separated into two files, the shaft and the body of the actuator. These files were exported as .OBJ files, which can be imported into Flowcode. Flowcode will then ask the user for a filename and convert the files to .MESH. The mesh files can be generated by any 3D modelling software that can generate the files. We could use shapes from the Flowcode system panel, but in this case, we’re using a mesh file.
The mesh file needs to be added to the system panel by the use of the mesh file shape shown below. The file then has to be linked via the properties menu sub-property “mesh”
This is done twice for each the body and shaft of the linear actuator.
In the next few screenshots, you can see that the mesh file shape boundaries need to be defined, and “normalised” to the mesh it is displaying. This is done by right-clicking on the existing mesh shape (not the model) and selecting “normalise model scale”. The shape boundaries are then correct for the model.
The shaft is put through the same process of correcting the shape boundaries, and positioned manually into the cavity in the body.
For the user to control the linear actuator, a property for the pin connections must be configured. 2 new properties for the panel are created and given the designation “inwards” and “outwards”. Both these connections, will be presented to the user as connection pins when they consult the properties panel for the component when it’s finished.
Next, an object reference needs to be set for the body and shaft of the linear actuator so that properties of these shapes can be referenced and set. 2 object handle variables are created and set the value of the body and shaft shapes.
Finally, before the initial test of the linear actuator, the motor control base component is added to the project. This provides the functionality of moving shapes in the system panel in simulation.
Values for the properties of the motor base are shown below. These are temporary for the time being as the functionality of the linear actuator is not yet created.
The motor base is set to not reset its position when the simulation is stopped, and to move along the Y-axis with instantaneous acceleration.
Finally, to test, a short endless loop that sets the speed of the shaft shape to move back and forth at a set speed every second is created.
When simulated, the shaft shape will move back and forth along the y-axis.
Next week, this component will be built up to include interaction with the parent project and some macros to provide core-functionality of the component.
27,850 total views, 4 views today