Overview
The objective of the driver input system is to wait on the events generated by the attached input devices and use those events to broadcast the relevant message to the correct subsystem. Since the events will, for the most part, be user-initiated, using interrupts is the ideal way to handle incoming events. A series of finite state machines will be used to monitor the current state of the vehicle based on the actions generated by each event.
Driver Inputs
IO Initialization
To simplify device setup, two separate modules have been created to take care of IO initialization for both digital and analog inputs. A configuration file has also been set up to define the addresses used for each device.
In addition, since the type of ISR needed to handle an input event will depend on whether the input is digital or analog, the responsibility for handling the events for particular device will fall onto either the digital or analog module, depending on the device.
Input Handling
Since input commands are to be made by the user, the events will be handled through the ISRs.
CAN Data Scheme
Until a sufficient protocol can be defined for sending driver input data over CAN, we will be using the following dummy scheme for the event data field:
Bits | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Contents | Device identifier | Device | ||||||||||||||
the
Pin Assignments
Input Device | Pin | Type |
---|---|---|
Power | PC0 | Digital |
Gas Pedal | PA1 | Analog |
Mechanical Brake | PA2 | Analog |
Direction Selector Forward | PB2 | Digital |
Direction Selector Reverse | PB3 | Digital |
Cruise Control | PC4 | Digital |
Cruise Control Increase | PC5 | Digital |
Cruise Control Decrease | PC6 | Digital |
Turn Signal Right | PC7 | Digital |
Turn Signal Left | PC8 | Digital |
Hazard Light Switch | PC9 | Digital |
Finite State Machine
The program will be controlled through the use of multiple Finite State Machines to ensure that inputs are only serviced at the appropriate periods.
Within the state machines used in this system, there exist transitions that depend on the current states of other state machines. As a result, an event must be ok'd by all active FSMs before a transition can be made. This way, dependencies between different FSMs can be supported while keeping separate the implementations of each state machine.
Power State Machine:
Keeps track of the car's functional state.
State | Description | Transition |
---|---|---|
Off | The vehicle is off |
|
On | The vehicle is on |
|
Pedal State Machine:
This state machine governs the running state of the car and defines the conditions under which the driver can turn on and move the vehicle. Transitions for this FSM depend on the state of the directional state machine.
State | Description | Transition |
---|---|---|
Brake | The car is on, but braking is active |
|
Coast | The gas pedal is pressed just enough to allow the car to coast. |
|
Drive | The brakes are engaged and the car is not moving |
|
Cruise Control | The car is currently in cruise control mode |
|
Directional State Machine
This state machine governs the possible gear shifts made by the user. Transitions in the pedal state machine depend on the current state of this FSM.
State | Description | Transition |
---|---|---|
Neutral | The vehicle is in neutral gear |
|
Forward | The vehicle is in forward gear |
|
Reverse | The vehicle is in reverse |
|
Turn Signal State Machine
This state machine governs the states of the turn signals made by the driver. Independent from the other FSMs.
State | Description | Transition |
---|---|---|
No signal | The car is currently not signalling |
|
Left signal | The car has the left signal active |
|
Right signal | The car has the left signal active |
|
Hazard Light State Machine
State | Description | Transition |
---|---|---|
Hazard Light On | Hazard lights are currently active |
|
Hazard Light Off | Hazard lights are currently inactive |
|
Possible State Transition Solutions
Combine pedal state and direction state into one FSM | This option will eliminate the FSM interdependence as well as allow for the elimination of the state IDs. However, the resulting FSMs would become much more complex, and there may exist better solutions. |
Use boolean array to record active states | Would eliminate FSM dependencies and state IDs and allow us to refer to the array to observe the needed states. However, it would make changes could become difficult to make. Also, the boolean would need to be globally exposed for modification by the FSMs |
Give each state a list of forbidden events | Each state's output function will take an event ID as an input and return true if the event ID does not appear in a given list of forbidden IDs. Once an event has been popped from the event queue, all FSMs will run this function. All results must be true for the event to be processed. This solution would eliminate the dependencies between FSMs, as well as the need for state IDs. Additionally, this list of forbidden id would be private to each state, meaning that changing this list would be very easy to do without alterations to any other part of the program. |
Additionally, it may be useful to have the FSMs stored in an array rather than in the fsm_group struct. This will allow us to iterate through the active fsms and make it easier to do operations on multiple ones at once.