-
Notifications
You must be signed in to change notification settings - Fork 1
cpp_classes
The C++ API, available via the header ft.hpp, implements classes for all devices defined by the C interface.
Classes |
---|
Device |
InputDevice |
Switch |
Digital |
Resistor |
Voltmeter |
Ultrasonic |
NCTTermistor |
ColorSensor |
TrailFollower |
Counter |
Lamp |
Servo |
MotorDevice |
Motor |
Encoder |
TXT |
Base class for all devices.
Method | Description |
---|---|
int getConn() | Return device connector. |
Returns the device's connection number. See ftobjects_connection for details.
Base class for various sensors.
Method | Description |
---|---|
int getState() | Return value or state. |
void extendRange(unsigned int mode) | Set input range mode. |
Inherited Methods | |
int getConn() | Return device connector. |
Returns the 'state' for universal input devices. For digital devices, the state is returned, for analog devices, the analog value is returned and for counters the current step count is returned.
Sets the inputs detection range. Pass 0 for normal detection range (0 - 5 V) and 1 for extended range (0 - 9 V).
Parameter | Description |
---|---|
mode | input range |
Implementation of a generic switch.
Method | Description |
---|---|
Switch(TXT &txt, int input) | Constructor |
Inherited Methods | |
int getState() | Return value or state. |
void extendRange(unsigned int mode) | Set input range mode. |
int getConn() | Return device connector. |
Constructor for the Switch class. Takes a reference to a TXT instance and an input pin number as arguments. For the switch instance to be usable, one has to call the update_config method on the TXT.
Note: The pin number starts at 1!
Parameter | Description |
---|---|
txt | reference to TXT object |
input | pin number [1-8] |
Implementation of a generic digital sensor.
Method | Description |
---|---|
Digital(TXT &txt, int input) | Constructor |
Inherited Methods | |
int getState() | Return value or state. |
void extendRange(unsigned int mode) | Set input range mode. |
int getConn() | Return device connector. |
Constructor for the Digital class. Takes a reference to a TXT instance and an input pin number as arguments. For the digital instance to be usable, one has to call the update_config method on the TXT.
Note: The pin number starts at 1!
Parameter | Description |
---|---|
txt | reference to TXT object |
input | pin number [1-8] |
Implementation of a generic resistor.
Constructor for the Resistor class. Takes a reference to a TXT instance and an input pin number as arguments. For the resistor instance to be usable, one has to call the update_config method on the TXT.
Note: The pin number starts at 1!
Parameter | Description |
---|---|
txt | reference to TXT object |
input | pin number [1-8] |
Calculates and returns the resistance in Ω.
Implementation of a generic voltmeter.
Constructor for the Voltmeter class. Takes a reference to a TXT instance and an input pin number as arguments. For the voltmeter instance to be usable, one has to call the update_config method on the TXT.
Note: The pin number starts at 1!
Parameter | Description |
---|---|
txt | reference to TXT object |
input | pin number [1-8] |
Returns the voltage in mV.
Implementation of fischertechnik's ultrasonic distance sensor.
Constructor for the Ultrasonic class. Takes a reference to a TXT instance and an input pin number as arguments. For the ultrasonic instance to be usable, one has to call the update_config method on the TXT.
Note: The pin number starts at 1!
Parameter | Description |
---|---|
txt | reference to TXT object |
input | pin number [1-8] |
Returns the current distance in cm.
Implementation of the fischertechnik 1,5 kΩ NTC.
Constructor for the NCTTermistor class. Takes a reference to a TXT instance and an input pin number as arguments. For the ncttermistor instance to be usable, one has to call the update_config method on the TXT.
Note: The pin number starts at 1!
Parameter | Description |
---|---|
txt | reference to TXT object |
input | pin number [1-8] |
Calculates and returns the temperature in °C for the fischertechnik 1,5 kΩ NTC using the beta-model.
Note: This calculation provides correct results for THIS NTC only. For different thermistors, the user must implement their own function to calculate the temperature from the resistance.
Calculates and returns the resistance in Ω.
Implementation of the fischertechnik color sensor.
Note: The color sensor does NOT implement a special functions to return the color; use getState() to obtain the analog value in mV.
Method | Description |
---|---|
ColorSensor(TXT &txt, int input) | Constructor |
Inherited Methods | |
int getState() | Return value or state. |
void extendRange(unsigned int mode) | Set input range mode. |
int getConn() | Return device connector. |
Constructor for the ColorSensor class. Takes a reference to a TXT instance and an input pin number as arguments. For the color sensor instance to be usable, one has to call the update_config method on the TXT.
Note: The pin number starts at 1!
Parameter | Description |
---|---|
txt | reference to TXT object |
input | pin number [1-8] |
Implenentation of fischertechnik's trail sensor.
Method | Description |
---|---|
TrailFollower(TXT &txt, int input) | Constructor |
Inherited Methods | |
int getState() | Return value or state. |
void extendRange(unsigned int mode) | Set input range mode. |
int getConn() | Return device connector. |
Constructor for the TrailFollower class. Takes a reference to a TXT instance and an input pin number as arguments. For the trail follower instance to be usable, one has to call the update_config method on the TXT.
Note: The pin number starts at 1!
Parameter | Description |
---|---|
txt | reference to TXT object |
input | pin number [1-8] |
Implementation of a fast counter device.
Method | Description |
---|---|
Counter(TXT &txt, int input) | Constructor |
int getState() | Return counter state. |
int getDistance() | Return distance. |
void reset() | Reset counter. |
Inherited Methods | |
int getConn() | Return device connector. |
Constructor for the Counter class. Takes a reference to a TXT instance and an input pin number as arguments. For the counter instance to be usable, one has to call the update_config method on the TXT.
Note: The pin number starts at 1!
Parameter | Description |
---|---|
txt | reference to TXT object |
input | pin number [1-4] |
Returns the counter's state. Returns 0 if the switch is pressed (cuircit is closed) and 1 if the switch is released (cuircit is open).
Returns the distance. The distance is the number of pulses (counts) since the last reset.
Resets the count number.
Note: This reset is not in effect immediately since this function requires communication with the M4.
Implementation of an output device.
Method | Description |
---|---|
Lamp(TXT &txt, int output) | Constructor |
void setBrightness(unsigned int brightness) | Set output (brightness) to new value. |
Inherited Methods | |
int getConn() | Return device connector. |
Constructor for the Lamp class. Takes a reference to a TXT instance and an output pin number as arguments. For the lamp instance to be usable, one has to call the update_config method on the TXT.
Note: The pin number starts at 1!
Parameter | Description |
---|---|
txt | reference to TXT object |
output | pin number [1-8] |
Sets the PWM value (brightness) for outputs.
Parameter | Description |
---|---|
brightness | new PWM value [0, 512] |
Implementation of a servo motor.
Method | Description |
---|---|
Servo(TXT &txt, int output) | Constructor |
void setPwm(int pwm) | Set the PWM value. |
Inherited Methods | |
int getConn() | Return device connector. |
Constructor for the Servo class. Takes a reference to a TXT instance and an output pin number as arguments. For the servo instance to be usable, one has to call the update_config method on the TXT.
Note: The pin number starts at 1!
Parameter | Description |
---|---|
txt | reference to TXT object |
output | pin number [1-3] |
Sets the PWM value for servo. PWM = 256 sets the servo to its central position.
Parameter | Description |
---|---|
pwm | new PWM value [0, 512] |
Base class for motors.
Sets a new speed value for the motor but DOES NOT start the motor.
Parameter | Description |
---|---|
speed | new speed value [-512, 512] |
Starts the motor immediately at new speed.
Parameter | Description |
---|---|
speed | new speed value [-512, 512] |
Stops the motor immediately.
Returns the motor number [0-3].
Sets the motor in coast mode. This will not stop the motor immediately, but it will be turned off with the next update cycle of the M4.
Implementation of a regular motor.
Constructor for the Motor class. Takes a reference to a TXT instance and an output pin number as arguments. For the motor instance to be usable, one has to call the update_config method on the TXT.
Note: The pin number starts at 1!
Parameter | Description |
---|---|
txt | reference to TXT object |
output | pin number [1-4] |
Implementation of an encoder motor.
Constructor for the Encoder class. Takes a reference to a TXT instance and an output pin number as arguments. The encoders counter has to be connected to the counter pin with the same number as the output pin. For the encoder instance to be usable, one has to call the update_config method on the TXT.
Note: The pin number starts at 1!
Parameter | Description |
---|---|
txt | reference to TXT object |
output | pin number [1-4] |
Starts the encoder immediately to run for the given distance. A pointer to a second encoder instance can be passed optionally. If the second encoder is provided, both motors run sychronously.
The speed at which the motor(s) run must be set in advance by calling the setSpeed method.
Parameter | Description |
---|---|
distance | distance in impulses |
e | optional pointer for 2nd encoder |
Starts the encoders immediately to run synchronously for the given distance. The encoders to be controlled are specified by the bit mask. The lowest 4 bits are used to control the motor. If the n-th bit is 1, the encoder connected at the n-th motor pin will be controlled. If the n-th bit is 0, the motor is ignored.
The speed at which the motor(s) run must be set in advance by calling the setSpeed method.
Parameter | Description |
---|---|
distance | distance in impulses |
mask | bit mask of up to 4 encoder motors |
Stops all motors selected by the bit mask immediatly.
Parameter | Description |
---|---|
mask | bit mask of up to 4 encoder motors |
Returns the remaining distance in impulses to finish the current action.
Returns whether or not the encoder motor is currently running.
Note: This DOES NOT mean the motor's cureent speed is non-zero! It checks whether or not the last motor command has been excecuted or not.
Implementation of the TXT 4.0.
Constructor for the TXT class. The pararmeters host and port have default arguments and don't need to be provided. As of now, they are discarded without being used!
Parameter | Description |
---|---|
host | optional host string (has no usage) |
port | optional port number (has no usage) |
Constructor for the TXT class. Used to construct a slave TXT. Takes a reference to the master TXT and a slave number as arguments.
Note: The slave number is NOT the number set in the settings of the controller! The TXTs are numbered by the order they are connected to the network!
Parameter | Description |
---|---|
txt | reference to master TXT |
slave | slave number |
Returns the TXT name.
Returns the TXT version.
Returns the firmware version.
Sets or changes the TXT's mode. Pass 0 for single mode, 1 for master mode and 2 for slave mode (see txt mode enum).
Parameter | Description |
---|---|
mode | new TXT mode |
Sets new name for the TXT. A name is a 16 character string. The name can shorter.
Parameter | Description |
---|---|
name | new name |
Returns the number of slaves attached to this TXT.
Returns the uid of the selected slave. Slave with the number 0 is the master TXT.
Note: The slave number is NOT the number set in the settings of the controller! The TXTs are numbered by the order they are connected to the network!
Parameter | Description |
---|---|
number | slave number |
Returns the name of the selected slave. Slave with the number 0 is the master TXT.
Note: The slave number is NOT the number set in the settings of the controller! The TXTs are numbered by the order they are connected to the network!
Parameter | Description |
---|---|
number | slave number |
Returns the serial number of the selected slave. Slave with the number 0 is the master TXT.
Note: The slave number is NOT the number set in the settings of the controller! The TXTs are numbered by the order they are connected to the network!
Parameter | Description |
---|---|
number | slave number |
Allocates a new Lamp instance on the heap connected to the pin specified by output and returns the pointer.
Note: The instance is NOT allocated as a smart pointer! To avoid memory leaks, you have to delete the pointer manually when it's no longer needed.
Parameter | Description |
---|---|
output | output pin number [1-8] |
Allocates a new Motor instance on the heap connected to the pin specified by output and returns the pointer.
Note: The instance is NOT allocated as a smart pointer! To avoid memory leaks, you have to delete the pointer manually when it's no longer needed.
Parameter | Description |
---|---|
output | motor pin number [1-4] |
Allocates a new Encoder instance on the heap connected to the pin specified by output and returns the pointer. The counter must be connected to the same pin number as the motor. (e.g. motor connected to M1, counter connected to C1).
Note: The instance is NOT allocated as a smart pointer! To avoid memory leaks, you have to delete the pointer manually when it's no longer needed.
Parameter | Description |
---|---|
output | motor & counter pin number [1-4] |
Allocates a new Servo instance on the heap connected to the pin specified by output and returns the pointer.
Note: The instance is NOT allocated as a smart pointer! To avoid memory leaks, you have to delete the pointer manually when it's no longer needed.
Parameter | Description |
---|---|
output | servo pin number [1-3] |
Allocates a new Resistor instance on the heap connected to the pin specified by input and returns the pointer.
Note: The instance is NOT allocated as a smart pointer! To avoid memory leaks, you have to delete the pointer manually when it's no longer needed.
Parameter | Description |
---|---|
input | universal input pin number [1-8] |
Allocates a new NCTTermistor instance on the heap connected to the pin specified by input and returns the pointer.
Note: The instance is NOT allocated as a smart pointer! To avoid memory leaks, you have to delete the pointer manually when it's no longer needed.
Parameter | Description |
---|---|
input | universal input pin number [1-8] |
Allocates a new Switch instance on the heap connected to the pin specified by input and returns the pointer.
Note: The instance is NOT allocated as a smart pointer! To avoid memory leaks, you have to delete the pointer manually when it's no longer needed.
Parameter | Description |
---|---|
input | universal input pin number [1-8] |
Allocates a new Digital instance on the heap connected to the pin specified by input and returns the pointer.
Note: The instance is NOT allocated as a smart pointer! To avoid memory leaks, you have to delete the pointer manually when it's no longer needed.
Parameter | Description |
---|---|
input | universal input pin number [1-8] |
Allocates a new Voltmeter instance on the heap connected to the pin specified by input and returns the pointer.
Note: The instance is NOT allocated as a smart pointer! To avoid memory leaks, you have to delete the pointer manually when it's no longer needed.
Parameter | Description |
---|---|
input | universal input pin number [1-8] |
Allocates a new ColorSensor instance on the heap connected to the pin specified by input and returns the pointer.
Note: The instance is NOT allocated as a smart pointer! To avoid memory leaks, you have to delete the pointer manually when it's no longer needed.
Parameter | Description |
---|---|
input | universal input pin number [1-8] |
Allocates a new TrailFollower instance on the heap connected to the pin specified by input and returns the pointer.
Note: The instance is NOT allocated as a smart pointer! To avoid memory leaks, you have to delete the pointer manually when it's no longer needed.
Parameter | Description |
---|---|
input | universal input pin number [1-8] |
Allocates a new Ultrasonic instance on the heap connected to the pin specified by input and returns the pointer.
Note: The instance is NOT allocated as a smart pointer! To avoid memory leaks, you have to delete the pointer manually when it's no longer needed.
Parameter | Description |
---|---|
input | universal input pin number [1-8] |
Allocates a new Counter instance on the heap connected to the pin specified by input and returns the pointer.
Note: The instance is NOT allocated as a smart pointer! To avoid memory leaks, you have to delete the pointer manually when it's no longer needed.
Parameter | Description |
---|---|
input | counter pin number [1-4] |
Updates the TXT's input/output configuration. This function must be called after allocating new sensors and actuators for them to become usable. Since this functions requires communication with the M4, the update is not in effect immediatly after the function returns, so a sleep might be used to make sure the peripheral is usuable. For updating the master TXT, 10 ms is sufficient, updating slave TXT takes up to 70 ms.
Sets a new CAN bitrate.
Parameter | Description |
---|---|
bitrate | new CAN bitrate (in Hz) |
Toggels whether or not to use a termitator for FDCAN.
mode = 0 disabels the terminator, mode = 1 enabels it.
Parameter | Description |
---|---|
mode | new mode |
Powers down the M4.
Resets the M4. As of now, this method does nothing.