-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AutomationShield API Style Guide #42
Labels
AutomationShield common
Common functionality for the entire library
readme
Important "sticky" posts.
software
Mostly software issue
Comments
gergelytakacs
added
the
AutomationShield common
Common functionality for the entire library
label
Apr 25, 2018
@rkoplinger - mainly to you at the moment. :) |
gergelytakacs
changed the title
Stick to Arduino API style gude
Stick to Arduino API style guide / AutomationShield API Style guide
Oct 23, 2018
gergelytakacs
changed the title
Stick to Arduino API style guide / AutomationShield API Style guide
AutomationShield API Style guide
Oct 23, 2018
gergelytakacs
changed the title
AutomationShield API Style guide
AutomationShield API Style Guide
Oct 23, 2018
This was referenced May 5, 2019
Closed
@EvaVargova, @corleone68, @lukasvadovic2 you should read these... |
gergelytakacs
referenced
this issue
Jun 25, 2019
@gergelytakacs I would like you to review the changes I made to the FloatShield library files. I have changed most of the things, but I believe that it is now, if nothing else, more easily readable. I am also including modified FloatShield example that already uses my version of library. I will be grateful for any form of feedback.
gergelytakacs
referenced
this issue
Jun 27, 2019
@gergelytakacs error() and serialPrint() functions sometimes throw a warning message: "ISO C++ forbids converting a string constant to 'char*'" when used like they were meant to - serialPrint("text"). Sketch is compilable even without this change, this is just to satisfy the compiler by using the "more correct" argument type.
MagnetoShield: If the linearization point is defined as y0 in Arduino IDE and Arduino DUE is used we get the following compilation error: 'float y0' redeclared as different kind of symbol'. Solution: use y_0 for linearization point. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
AutomationShield common
Common functionality for the entire library
readme
Important "sticky" posts.
software
Mostly software issue
Development
Put an empty
.development
in the root folder in order to edit the examples and while working. Don't itegrate the file into the Gi repo!Build status
Naming conventions
Please stick to the Arduino API style guide that can be found here when writing the shield API's.
Namely:
begin()
to initialize a library instance, usually with some settings. Use end() to stop it.read()
to read inputs, and write() to write to outputs, e.g.digitalRead()
,analogWrite()
, etc.According to this the AutomationShield library will use:
begin()
to initialize the board.sensorRead()
to read the outputs "y",referenceRead()
to read reference "r" (if there is one) andactuatorWrite()
to send input ''u".calibration()
to perform optional calibration tasks before moving into the loop.bool _wasCalibrated
is a Boolean flag to read calibration status.All boards should use these basic functions so that the library remains consistent. Determine which type of input/output will be likely most used by the user and use those in these functions. If you want to use more types of sensor readings (voltage, physical units etc.) then it is suggested to get creative based on this. Such as
sensorReadVoltage()
to read the outputs "y" in V,sensorReadCelsius()
to read the outputs "y" in degrees Celsius, etc.Pins locations for the inputs and outputs should be stored as
#define
tokens. Use all capitals and begin the token with the name of the device, continue with an underscore, variable symbol of the quantity and the word pin. So, for example the output pin of the Opto shield will beOPTO_YPIN
. Other examples of these tokens are:Header files for hardware API are named after the hardware, contain capitals. For example for the Magneto device the full name will be MagnetoShield, thus the API for the device will be initialized in the
MagnetoShield.h
header notmagnetoshield.h
. Similarly, the API will have the class, methods and other things in theMagnetoShield.cpp
source file.The API for the particular hardware will use the common header
AutomationShield.h
, which in turn will load other basic headers such asSampling.h
andPID.h
. Thus, in the end, the user should just load the particular header in the example file, such asMagnetoShield.h
.The header (
*.h
) should just contain forward declarations of programming entities (e.g.void function()
) but not the actual functions, these go into the source (*.cpp
)For naming functions use camel case, not snake case. Avoid underscores, if possible. Thus, you should use -
myAwesomeFunction()
, instead ofmy_awesome_function()
. This is a thing of preference and consistence.3.3 V compatibilty
begin()
method:analogReference(EXTERNAL)
. See more here.MATLAB
If you want to include experimental measurements, use the following naming conventions for the
mat
files:C_
- from controlID_
- from identificationuse any other information next and finish with the sampling rate. Thus a control experiment by PID sampled at 3000 microseconds will be
C_PID_3000us.mat
.myFile.mat
will work on Windows if you refer to it with lower casemyfile.mat
, it won't on Linux (e.g. when testing CI).clc
andclear
usestartScript
in the beginning, otherwise the continuous integration will fail, since theclear
command clears those variables needed for CI. (startScript
defines some exceptions forclear
).CI_Test
. You can test its existence withexist()
to run CI specific parts of your code.CI_Test
, which will limit solver iterations, optimization runtime, etc. (this is really specific to your application).*.mat
file. For example modeling runs, but the model is saved and loaded in control examples. Don't just assume that a variable exists in the workspace.Library file and folder structure
Printing to serial
The primary point of any example is to output dynamic measurements to the plotter or for logging. Therefore any kind of diagnostic data is subject to conditional compilation, enabled by flags of the user. This functionality inside the header and cpp files is realized by the
AutomationShield.serialPrint("Message");
method. Please DO NOT USE the regular
Serial.print()
function inside header and realization files.Shield releases
#define SHIELDRELEASE n
to distinguish between different versions. Then
should represent release order of specific version.ATSAMD Compatibility
Serial
works without changes. The board does not reset upon accessing serial link, unlike in the case of AVR. Push reset button manually.analogRead
works without changes (but tolerates only 3.3 V!). Unless changed, the resolution is still 10bit. So by default 1023 level is 3.3 V.ARDUINO_ARCH_SAMD
and notARDUINO_ARCH_SAM
. So the following example worksor to a more C standard
in this case of course you may employ
#ifndef
etc. preprocessor directives.You may consult this tutorial for a decent start on C preprocessor basics for the Arduino IDE.
Others
Serial
and do not useSerial
within the source code, only in examples..h
) and implementation (.cpp
) file. Since the IDE tries to build every implementation file in the library, this will cache the Servo library, which will then conflict with other AS devices. The solution is, in this case, just use a header file - it will not be included anywhere else but the examples.Useful Arduino API environment variables
VARIANT_MCK
Clock speed in Hz for ATSAMD, does not seem to work for AVRJust for fun
TIME_WASTED_HERE
that shall express the time in hours wasted in finding bugs. :) (Thanks @AnnaVargova)The text was updated successfully, but these errors were encountered: