Adrive
From DGC Wiki
|
- Adrive requirements - requirements for canonical software architecture implementation
- Gcdrive - GcModule variant of adrive
Adrive is the overall driving software for Alice. Its main role is to take commands from trajFollower and execute them. Adrive also performs checking on the state of the actuators, brings the vehicle to a stop if it senses a problems, and attempts to recover from failures (by resetting actuators). The other function that adrive it serves is to provide feedback on actuator position. The code for adrive can be found in the folder $dgc/modules/adrive.
Adrive works by receiving commands over the network and sending them out over serial connections. Also included into the role of Adrive was to implement physical protections for the hardware to prevent the vehicle from hurting itself.
Adrive Usage
Adrive uses a configuration file (adrive.config by default) that specifies various operating parameters, including what command and status loops should be run. Command line arguments can be used to further refine the operation of adrive.
| -s | turn off steering |
| -b | turn off brake |
| -g | turn off gas (throttle) |
| -t | turn off transmission |
| -o | turn off OBD II |
| -e | turn off estop |
System Design and Analysis
The design of Adrive was to store data in a central location then have multiple threads selectively mutating small segments of the data. There were 2 threads for each actuator, a status thread and a command thread. In addition there were two threads for network connections. One thread listened for incoming commands while the other thread periodically broadcast the current positions of actuators over the network. The network broadcast thread also worked as a logging thread periodically writing the internal data to a file. Two other threads existed, one which was the user interface thread and the other was a supervisory thread to make sure that actuators were healthy and if necessary try to recover them. Overall the system was designed to be interrupt driven. This allows many slow tasks, especially slow speed serial communication ports, to operate in parallel. Minor challenges are that it is much harder to debug and timing is very critical.
The central data structure was called a vehicle struct which was defined globally or passed by reference. The vehicle struct contained individual structs for each of the actuators as well as some general conditions relevant to all operations such as a shutdown flag. The net result was a hierarchical structure which allowed access to data within any part of the program by calling my_vehicle.actuator_name.variable_name.
Each actuator struct contained not only the basic position feedback, but also the last commanded position, the status of the actuator, the handles of the actuators two threads, and the function pointers for the code to execute for an incoming command or how to read back position. Also each actuator has a number of timeout associated with it. The port to which the actuator is connected is also stored in the actuator struct. For flow control pthread mutex bits and a pthread conditional broadcast flag were stored in each actuator struct as well.
The functional flow within Adrive is as follows:
- The first action is to create the vehicle struct filling it in with default values. The default values are mostly zeros and set everything to be disabled.
- Following the initialization the adrive configuration file is read from the local directory. The primary role of the config file is to enable each thread and fill in their associated timeouts. The other critical element of the config file is to define the ports to which the actuators are actually connected.
- After filling in the struct all enabled threads are spawned. Of note the supervisory thread starts with a slight delay to allow the actuators to return from status checks before the supervisory thread reads the default values which are errors for safety.
- Each actuator status thread periodically polls the actuator for its position. The procedure is to lock the mutex for the actuator. Send a request for data. Listen for the response from the actuator. Then release the mutex for the actuator. If the returned value is valid it is filled into the actuator structure and the status is set to VALID. Otherwise the status is set to ERROR.
- The command thread works similarly however it blocks on a pthread conditional flag. After receiving the broadcast flag it will lock the mutex, send a command to the actuator, then wait for confirmation. If this process fails it will set the status to ERROR and wait for another command.
- The network threads are very similar. The receiving thread simply waits for incoming commands. When a command is received first a set of rules are checked, and then the associated actuator’s command is mutated and the actuators broadcast flag is sent. This wakes the actuator’s command thread which executes on the mutated command. The rules provide protection for the actuators on when and how the commands can be mutated. An example is that when stopped the steering is disabled so as not to overheat the hydraulic power steering gearbox by twisting the wheels while stationary. The rules also are based on the position of the E-Stop actuator. The E-Stop actuator is the only external commands coming into the vehicle. There are three states, RUN, PAUSE, and DISABLE. If in RUN the command goes through. If in PAUSE the vehicle will be brought slowly to a stop. And DISABLE causes the vehicle to apply full brake and turn off. A set of rules are defined for each actuator’s response to commands in each of these three states.
- The network broadcast thread simply loops periodically sending out the current data from the vehicle struct. After it broadcasts the data it also checks whether logging is enabled and will write to file the current vehicle data structure.
- The user interface spawns a thread which calls Sparrow an interactive interface which displays most of the vehicle data structure on the screen and can mutate commands and manually send broadcast flags to execute the mutated commands.
- The last a thread is the supervisory one. It is in charge of making sure that everything is working properly. If it’s not working properly it must take corrective action. To achieve this, the thread periodically polls each actuator to confirm that it is operating correctly. If any actuator is reporting an ERROR, the thread will override the E-Stop position to put the vehicle into a PAUSE. Once in PAUSE and stopped the problem will try to be recovered. The easiest case to illustrate this is if the engine stalls. In this case the OBDII actuator will fail to return, thereby causing an error which will call a pause. The supervisory thread will detect that the OBDII failed, and take the corrective action of trying to restart the engine. The OBDII status thread will keep trying to get status and failing. However once the engine is back on, OBDII will succeed and set status to VALID. The next time the supervisory thread runs it will detect that there are no longer any errors. And the supervisory thread will release the overridden PAUSE.
Skynet Actuator State Broadcast
- To use adrive other modules must communicate via skynet. The interface types are all defined in the file ActuatorState.hh which is installed into the include directory automatically.
- everything desired from adrive should be in the m_actuator_state struct now accessable from the CStateClient class
- if additional information is desired it can be added, please request it.
Skynet Command Interface
To use adrive other modules must communicate via skynet. The interface types are all defined in the file adrive_skynet_interface_types.h which is installed into the $dgc/include directory automatically. If you wish to communicate with adrive add $(ADRIVELIB) to your dependancies in yourmodule.mk
General Notes
- include "adrive_skynet_interface_types.h"
- you will probably want to consider using threads for listening for messages
Commands to adrive
- Commands sent to adrive are skynet message type SNdrivecmd
- They are serialized in adrivecmd_t struct.
- The elements of the struct are
- an enumeration of the actuator type
- an enumeration of the command type
- a numerical argument
- a string argument
Returns from adrive
- everything desired from adrive should be in the m_actuator_state struct now accessable from the CStateClient class
- if additional information is desired it can be added, please request it.
Current commands implemented
set accel
- actuator: accel
- command: set_position
- num_arg: (-1,1)
set steering
- actuator: steer
- command: set_position
- num_arg: (-1,1)
Actuator Interfacing
All of adrives interfaces with the hardware in Alice is via serial connections on leela. We have experimented with using a serial device server (SDS) to allow the actuators to be accessed over the network, but we had problems in 2005 with reliability of the SDS hardware and reverted to hardwired conections.
Serial port configuration
Two serial interface cards are installed on leela, in addition to one serial port available from the motherboard. In its present configuration (Dec 06), here is the serial port mapping:
Port Actuator Settings Comments ttyS0 Steering 9600, 8N1, sw flow Connected to Parker motor controller ttyS1-3 Not connected These ports are assigned by udev but don't map to anything ttyS4 Throttle 9600, 8N1, sw flow Custom box; controls programmable resistors ttyS5 Transmission 9600, 8N1, sw flow Custom built interface; Includes ignition ttyS6 Not connected ttys7 OBD II 19200, 8N1, no flow CANbus <-> serial interface; key must be in "run" ttyS8 E-stop 9600, 8N1, sw flow Custom box; sends 'R', 'P' or 'D' ttys9 Brake 9600, 8N2, no flow Custom box; controls pneumatic valves
Build
- Either:
- enter the directory $dgc/alice/adrive
- type
make; make install
- Or
- enter the directory $dgc
- type
make
setup
- in $(DGC)/bin/ edit adrive.config
- see README.TXT for instructions on adrive.config
- but the jist of it is that you add a pound sign infront of anything you want to run
- and set the ports to which the actuators are attached
- Make sure that in all your directories echo $SKYNET_KEY are the same.
- If not type:
source ~/.*shrc
- it will be stored in the above file or .bashrc
- Skynet functionality will not work unless the keys are all the same.
Interlocks
- Adrive has multiple interlocks to protect the vehicle.
- Commands out of range wil be ignored
- Transmission will not shift unless:
- Estop position = pause
- OBDII status = 1
- OBDII velocity = 0 (Acutally currently <.1 m/s)
- Estop position is the minimum of command, darpa, and astop.
- To run set command to 2 if not using SuperCon
- To run also set astop to 2.
- If it ever gets reset down to 1 you will manually need to reset it to 2.
run
- enter the bin directory
cd bin
- execute adrive
./adrive
- In the sparrow interface
- Use the arrow keys to move the interface.
- enter a command for gas, steer, or brake
- by highlighting the field, press =, type number 0-255, enter
- execute brake by pressing b, steer by pressing s, gas with g, trans with t, steering velocity command with v, and steering acceleration command with c
- to reenable steering after using the kill switch press e
- if you want to input skynet commands by hand
- Execute sn_send_commandline
- Follow the prompts
- You can only send positional commands.
- To exit hit Ctrl-C
- Execute sn_send_commandline
- In the sparrow interface
exit
- highlight EXIT
- press enter
- kill the skynetd process when done with it
Adrive Checkout Procedure
- jack up the car and set up the brake actuator
- enter modules/adrive
- type:
make make install
- move to $(DGC)/bin
cd ../../bin
- edit the config file
emacs config/adrive/adrive.config
- comment out the throttle command loop
- Do not test the throttle commands without the car in gear it will overspeed the engine. AKA NOT IN THE SHOP!
- Save and exit
- run adrive
./adrive
- in a new window run sn_send_commandline found in bin
./sn_send_commandline
- watch as you command through sn_send_commandline the adrive fields move
- watch as you move the actuators as the feedback moves and the steering and brake actuator move.
Frequently Asked Questions
- astop goes to 1 after 5 seconds: this happens based on various interlocks that adrive checks. You can turn off the interlocks in the config file. We had some problems doing this in bin and eventually had to run adrive from its source directory to get it to work (not quite sure why). Murray 20:47, 10 Dec 2005 (PST)
- astop is set to 1 (EPAUSE) when
- (1) Steering command is set enabled but steering is not actually enabled.
- (2) Some actuator command loop timed out with interlocks enabled.
- (3) ESTOP status is enabled but ESTOP is not receiving commands.
- (4) Ignition and transmission command are enabled and estop is not disable but the engine is off or the engine condition is not valid.
- (5) estop=RUN, steering status is set enabled, but steering is not actually enabled.
- (6) Steering status is enabled but steering is not receiving commands
- (7) Brake status is set enabled but brake is not receiving commands.
- (8) Gas status is set enabled by gas is not receiving commands.
- (9) Tranmission status is set enabled but transmission is not receiving commands.
- (10) estop = DISABLE.
- Nok is working on making this information displayed on adrive sparrow screen
Additional Information
- vdrive - documentation for Bob's equivalent of adrive (+ parts of follower)
- Tully Foote SURF Report, 2005
![[Main Page]](../../../../upload/alice.jpg)