|
Anti-Sway Capstone 1.0
|
Sensor/Actuator (Input/Output) Interfacing Library. More...
#include <stdint.h>#include <stdlib.h>#include <string.h>#include <stdbool.h>#include <math.h>#include <pthread.h>#include "MyRio.h"#include "DIO.h"#include "T1.h"#include "conC_Encoder_initialize.h"#include "discrete-lib.h"#include "error.h"#include "thread-lib.h"#include "io.h"
Macros | |
| #define | X_CONNECTOR_ID 0 |
| X Motor Encoder Connector ID (on Connector C) | |
| #define | Y_CONNECTOR_ID 1 |
| Y Motor Encoder Connector ID (on Connector C) | |
| #define | POTENTIOMETER_SLOPE -2.11 * PI / 180.0 |
| #define | POT_V_LIM_LO -20.0 |
| Lower Potentiometer Voltage Saturation Limit (V) | |
| #define | POT_V_LIM_HI 20.0 |
| Upper Potentiometer Voltage Saturation Limit (V) | |
| #define | ENC_CNT_REV 2000.0 |
| #define | M_PER_REV 0.01267 * PI |
| #define | ENC_2_POS(value) (value) / ENC_CNT_REV * M_PER_REV |
| #define | ENC_2_VEL(value) (value) / (BTI_S * ENC_CNT_REV) * M_PER_REV |
| #define | X_LIM_LO 0.0 |
| Lower X Limit. | |
| #define | Y_LIM_LO 0.0 |
| Lower Y Limit. | |
| #define | X_LIM_HI 0.35 |
| Higher X Limit. | |
| #define | Y_LIM_HI 0.35 |
| Higher Y Limit. | |
| #define | VEL_LIM_ABS 1.0 |
| Absolute Velocity Limit. | |
| #define | CHANNELS 16 |
| Number of Channels. | |
| #define | LCD_KEYPAD_LEN 4 |
| Keypad Length. | |
| #define | UNIT_VEL 0.15 |
| #define | DEL_ROW 7 |
| #define | DEL_COL 3 |
| #define | WAIT_CONST 417000 |
Typedefs | |
| typedef bool | Keymap[9] |
Functions | |
| static void * | KeymapThread (void *resource) |
| static int | HandleEncoderError (Positions *curr_pos, Velocities *curr_vel) |
| static int | HandlePotentiometerError (Angles *curr_ang) |
| static void | wait () |
| int | IOSetup () |
| int | IOShutdown () |
| void | Reset () |
| int | GetReferenceVelocityCommand (Velocities *result) |
| int | GetReferenceAngleCommand (Angles *result) |
| int | GetAngle (Angles *result) |
| int | GetTrolleyPosition (Positions *result) |
| int | GetTrolleyVelocity (Velocities *result) |
| int | GetUserPosition (Angles *angle, Positions *pos, Positions *result) |
| int | GetUserVelocity (Angles *angle, Velocities *vel, Velocities *result) |
| int | SetXVoltage (Voltage voltage) |
| int | SetYVoltage (Voltage voltage) |
| bool | PressedDelete () |
| int | KeyboardControlFork () |
| int | KeyboardControlJoin () |
| char | getkey () |
Variables | |
| static bool | reset |
| Reset Variable for measuring velocity. | |
| static float | potentiometer_v_x_intercept |
| static float | potentiometer_v_y_intercept |
| static MyRio_Aio | x_potentiometer |
| X Potentiometer. | |
| static MyRio_Aio | y_potentiometer |
| Y Potentiometer. | |
| static MyRio_Encoder | x_encoder |
| X Motor Encoder. | |
| static MyRio_Encoder | y_encoder |
| Y Motor Encoder. | |
| static int32_t | first_enc_state [2] |
| static int32_t | prev_enc_state [2] |
| static bool | holding_vel_set |
| Indicator if the holding for velocity is set. | |
| static bool | holding_pos_set |
| Indicator if the holding for position is set. | |
| static Velocities | holding_vel |
| Encoder Holding for velocity. | |
| static Positions | holding_pos |
| Encoder Holding for position. | |
| static const Encoder_StatusMask | enc_st_mask |
| Encoder Error Mask. | |
| MyRio_Aio | x_motor |
| X Motor Voltage Channel. | |
| MyRio_Aio | y_motor |
| Y Motor Voltage Channel. | |
| MyRio_IrqTimer | timer |
| Universal Timer. | |
| static MyRio_Dio | channel [CHANNELS] |
| Keyboard channels. | |
| static pthread_mutex_t | keyboard |
| Keyboard lock. | |
| static Keymap | keymap |
| Our keymap. | |
| static pthread_t | keymap_thread |
| Thread for Keymap Thread. | |
| static ThreadResource | keymap_resource |
| Thread Resource for Keymap Thread. | |
| static int | error |
| Local Error Flag. | |
Sensor/Actuator (Input/Output) Interfacing Library.
| #define ENC_2_POS | ( | value | ) | (value) / ENC_CNT_REV * M_PER_REV |
Converts a BDI quantity to meters
| value | THe BDI to convert |
| #define ENC_2_VEL | ( | value | ) | (value) / (BTI_S * ENC_CNT_REV) * M_PER_REV |
Converts a BDI/BTI quantity to meters per second
| value | The value to convert |
| #define ENC_CNT_REV 2000.0 |
Number of counts in one revolution TODO(nguy8tri): Find this quantity
| #define M_PER_REV 0.01267 * PI |
Meters per revolution Diameter of upper pulley (12 mm) * PI
| #define POTENTIOMETER_SLOPE -2.11 * PI / 180.0 |
Best-Fit Potentiometer Slope (rad/V) TODO(nguy8tri): Find this quantity
| #define UNIT_VEL 0.15 |
The unit velocity stop corresponding to a keypad touch (m/s)
| typedef bool Keymap[9] |
Holds booleans indicating which buttons (1 through 9) are being pressed
| int GetAngle | ( | Angles * | result | ) |
Obtains the angle of the harness
| result | A return parameter, which will become the angle along both directions |

| char getkey | ( | ) |
Keypad characters
Locking style allows for getkey() to take precedence over all other keyboard commands

| int GetReferenceAngleCommand | ( | Angles * | result | ) |
Obtains the user command (for tracking)
| result | A return parameter, which will become the desired angle requested by the user |
| int GetReferenceVelocityCommand | ( | Velocities * | result | ) |
Obtains the user command (for anti-sway)
| result | A return parameter, which will become the change in position requested by the user |
Setup discrete velocity commands, -1, 0, and 1
| int GetTrolleyPosition | ( | Positions * | result | ) |
Obtains the Trolley Position
| result | A return parameter, which will become the position of the trolley |

| int GetTrolleyVelocity | ( | Velocities * | result | ) |
Obtains the Trolley Velocity
| result | A return parameter, which will become the velocity of the trolley |

Obtains the User Position
| angle | The rope angle |
| pos | The trolley position |
| result | A return parameter, which will become the position of the user |
| int GetUserVelocity | ( | Angles * | angle, |
| Velocities * | vel, | ||
| Velocities * | result ) |
Obtains the User Velocity
| angle | The rope angle |
| vel | The trolley velocity |
| result | A return parameter, which will become the velocity of the user |

|
inlinestatic |
Handles Error Processing from Position/Velocity Measurements
| curr_pos | The current position |
| curr_vel | The current velocity |
Check Positional Limits first
Now, check velocity limits
Now, check if there is an encoder error
u_error = EENCR; conC_Encoder_initialize(myrio_session, &x_encoder, X_CONNECTOR_ID);
u_error = EENCR; conC_Encoder_initialize(myrio_session, &y_encoder, Y_CONNECTOR_ID);
Output Error

|
inlinestatic |
Handles Error Processing for Potentiometer Measurements
| curr_ang | The current angle reading |

| int IOSetup | ( | ) |
Sets up the System-Sensor/Actuator Interface
Setup Timer
Setup Encoders Channels
Setup Potentiometer Voltage Channels (are swapped)
Setup Motor Channels
Setup Keyboard Channels & Resources
Setup Reset flag
Calibration Message
Set Reference Positions
Setup the holding
Calibrate voltage intercepts for potentiometer

| int IOShutdown | ( | ) |
Shutsdown the System-Sensor/Actuator Interface
Dissasociate with Encoders
Dissasociate with Potentiometers
Disassociate with Motor
Destroy Keyboard Lock
| int KeyboardControlFork | ( | ) |
Enables Keyboard Control for Anti-Sway (concurrently)
Begin Keyboard Thread

| int KeyboardControlJoin | ( | ) |
Stops Keyboard Control for Anti-Sway (concurrent process)
Destroy Keymap Thread
|
inlinestatic |
Obtains the numerical buttons pressed (1 through 9)
| bool PressedDelete | ( | ) |
Detects if the DEL key is pressed on the keyboard
| void Reset | ( | ) |
Resets GetTrolleyPosition and GetTrolleyVelocity by setting the velocity to zero
| int SetXVoltage | ( | Voltage | voltage | ) |
Sets the voltage of the X motor
| int SetYVoltage | ( | Voltage | voltage | ) |
Sets the voltage of the Y motor
|
inlinestatic |
Waits for approximate 5 ms
Wait Constant
|
static |
Encoder Error Mask.
|
static |
First Encoder state for both the X and Y Encoders
|
static |
Calibrated Voltage Intercept (x-intercept) for X Potentiometer
|
static |
Calibrated Voltage Intercept (x-intercept) for Y Potentiometer
|
static |
Previous Encoder state (from the last time either GetTrolleyPosition or GetTrolleyVelocity is caled), for both the X and Y Encoders
| MyRio_IrqTimer timer |
Universal Timer.
The Timer.