-
Notifications
You must be signed in to change notification settings - Fork 0
Working with Hardware
The VexOS hardware abstraction layer (HAL) is a set of classes that make it easier to work with VEX hardware. While the easyC libraries provide low-level access that is friendly to easyC block-diagrams, the overall API has a number of weaknesses:
- Pin numbers must be repeated on each call, requiring the use of macros to minimize changes if ports are rearranged
- The "Controller Configuration" dialog must be kept in sync with any code changes
- Procedural calls without objects do not model the actual hardware
- Most calls are write-only, there is no way to determine what state hardware is in, this makes generic/reactive routines more difficult to implement
- Minimal error checking
- Inconvenient data types and ranges (motor power is -127 to 127 instead of -1.0 to 1.0, analog output is 0 to 4096)
- Some API calls are unwieldy to type
The VexOS HAL addresses all of these issues. The key features are:
- Hardware objects encapsulate the pin assignments and easyC calls, providing a clean API that directly models the physical hardware on the robot
- Cortex controller digital I/O, motor types and IME addresses are automatically configured based on the objects that are constructed
- Rich exceptions alert you immediately of hardware errors or configuration issues
- Better, more consistent method names
While the system is designed to be used Commnand-based Subsystems, the HAL works just as well for a simple event-based robot.
VexOS defines the following physical hardware objects:
Accelerometer - accelerometer
AnalogIn - Potentiometer, Light Sensor, Line Sensor
DigitalIn - Limit and Bump switches, Jumpers
DigitalOut - Pneumatic valve and LED
Encoder - Quadrature and legacy rotary encoder
Gyro - yaw rate gyro
LCD - LCD display
Motor - a motor, always used through a MotorGroup
PowerExpander - power expander
Servo - servo
Speaker - speaker
Sonar - ultrasonic range finder
It also defines the following logical objects:
MotorGroup - generic motor control system with automatic ganging, feedback and PID
SerialPort - serial port for debugging and custom hardware