Follow
From DGC Wiki
|
Detailed Overview/Implementation Description
follow can be used for essentially two tasks: controlling vehicle motion, and taking logged data on vehicle state for use when developing controllers.
follow controls vehicle motion in two ways:
- First, longitudinal motion (e.g. motion in the direction of the trajectory) is controlled using the built-in PID controller used during the 2005 DGC. (Note that it isn't pure PID as it contains additional modifications, such as integrator reset.) Once a reference velocity is determined, it is passed to the PID controller, which then returns an acceleration command (normalized from -1, full brake, to 1, full acceleration). That command is passed onto the driving software. Typically, the user does not have to worry much about this part.
- Second, lateral motion (e.g. motion perpendicular to the direction of the trajectory) is controlled using a user-provided controller that is loaded in via a .mat file. The full state is available to the user for his or her controller.
follow estimates vehicle motion using an EKF at discrete time steps:
- The Q and R matrices come from a user-provided .mat file which contains two matrices, Q and R.
Important files needed for running follow:
- *.mat - A controller file, necessary for loading up a lateral controller
- *.mat - An observer file, necessary for loading up an observer
- *.traj - A trajectory file, necessary for loading up a reference trajectory to follow
- *.log - Log files saved by follow
Logging Format
follow has the ability to log state data in an ASCII format to a file for later use. The format of the file is:
unixtime t1 enabled? v1 φ1
x1 y1 θ1
obsv_enabled?
γ1
x1 y1 θ1
unixtime t2 enabled? v2 φ2
x2 y2 θ2
obsv_enabled?
γ2 x2 y2 θ2
...
A listing of variables, column positions, and descriptions is below:
| # | Var | Description |
| 1 | unixtime | Unix timestamp, generally you can ignore this |
| 2 | t1 | Time since the controller was enabled |
| 3 | enabled? | 0 if control is disabled, 1 if paused, 2 if enabled |
| 4 | v1 | Current desired velocity |
| 5 | φ1 | Current steering angle; read in from actuator state |
| 6 | ![]() | Feed-forward velocity |
| 7 | ![]() | Current commanded steering angle (what is being sent to ADrive) |
| 8 | x1 | x position (either from AState, or estimated using follow's internal estimator) |
| 9 | y1 | y position (either from AState, or estimated using follow's internal estimator) |
| 10 | θ1 | theta position (either from AState, or estimated using follow's internal estimator) |
| 11 | ![]() | x velocity (either from AState, or estimated using follow's internal estimator) |
| 12 | ![]() | y velocity (either from AState, or estimated using follow's internal estimator) |
| 13 | ![]() | theta rate (either from AState, or estimated using follow's internal estimator) |
| 14 | ![]() | x acceleration (either from AState, or estimated using follow's internal estimator) |
| 15 | ![]() | y acceleration (either from AState, or estimated using follow's internal estimator) |
| 16 | ![]() | theta acceleration (either from AState, or estimated using follow's internal estimator) |
| 17 | ![]() | x position desired |
| 18 | ![]() | y position desired |
| 19 | ![]() | theta position desired |
| 20 | ![]() | x velocity desired |
| 21 | ![]() | y velocity desired |
| 22 | ![]() | theta rate desired |
| 23 | ![]() | x acceleration desired |
| 24 | ![]() | y acceleration desired |
| 25 | ![]() | theta acceleration desired |
| 26 | obsv_enabled? | 0 if follow's internal observer is disabled, 2 if the observer is enabled (affects whether the states above are from astate or from follow's observer) |
| 27 | ![]() | raw x position from GPS |
| 28 | ![]() | raw y position from GPS |
| 29 | ![]() | raw theta rate from IMU |
| 30 | γ1 | "Goodness" measure of the raw GPS data |
| 31 | x1 | x position (from AState only) |
| 32 | y1 | y position (from AState only) |
| 33 | θ1 | theta position (from AState only) |
| 34 | ![]() | x velocity (from AState only) |
| 35 | ![]() | y velocity (from AState only) |
| 36 | ![]() | theta rate (from AState only) |
| 37 | ![]() | x acceleration (from AState only) |
| 38 | ![]() | y acceleration (from AState only) |
| 39 | ![]() | theta acceleration (from AState only) |
| ... | ||
| 49 | φFF | phi feed-forward |
Designing a Controller for Follow
As mentioned above, follow determines what controller to use by reading one in from a .mat file, saved using Matlab. (For ease of reference, we will call this controller .mat file controller.mat from now on, although you can specify specifically which file follow should load its controller from.) controller.mat file should contain four matrices, named A, B, C, and D, which describe a state-space realization of the controller follow will implement.
One tricky thing to note is that for follow, the inputs to the state-space system described by A, B, C, and D in controller.mat are the outputs of the plant, while the outputs of the state-space system described in controller.mat are the inputs to the plant. For a more concrete example, assume we can model Alice in open-loop as:

Then we need to make our controller of the form:

A simple state-feedback controller, for example, would have the form:

so A, B, and C would be zero matrices (of the correct dimensions), and D = − K. Note: please check that the signs of your gains and matrices are correct! follow will not do any additional sign-changing -- it will simply implement what you give it!
If we wanted to have a feed-forward term, then we need only specify some non-zero ud (see below about how to construct a trajectory file for follow) and then follow would implement:

The inputs to follow (e.g. the outputs of the plant, y) are, in this order:
[x y θ
xd yd θd
where state elements with the subscript d correspond to reference (e.g. desired) values (and may be zero if they are unspecified -- see below about trajectories). The outputs (e.g. u) is φ, the steering angle.
Designing an Observer for Follow
As mentioned above, follow determines what observer to use by reading one in from a .mat file, saved using Matlab. (For ease of reference, we will call this observer .mat file observer.mat from now on, although you can specify specifically which file follow should load its observer from.) observer.mat file should contain two matrices, named Q, and R, which describe correlation matrices of the disturbances and noise sources for follow's observer to use.
Q should be 2x2 (since there could be disturbances in v or phi) and similarly, R should be 3x3 (since we measure x, y, and theta_dot).
Designing a Reference Trajectory for Follow
As mentioned above, follow determines what sort of reference trajectory to follow by reading one in from a .traj file. The general format of the file is as follows:
n 11
t1 v1 φ1 x1 y1 θ1
t2 v2 φ2 x2 y2 θ2
...
tn vn φn xn yn θn
Where n is the number of points you've plotted along your trajectory, and ti is the time at which the system should achieve the configuration described by the state variables in the ith row. follow will perform a linear interpolation between each configuration, so you will want to make sure that your configurations are spaced relatively closely. (A good rule of thumb is to make your time step similar to the frequency at which you expect to run your controller.)
Also, note that if your controller doesn't use a variable (for example, unless you get really fancy, you probably won't be doing much with a feedforward term in
), just set that value to 0 for all times (so you'd have a column of zeros). The only exception to this is the v column, which must be set to some positive value for the vehicle to move forward.
The format of the waypoint file which will be the input to your trajectory generation script is:
0 y1 x1 2.00 4.00
0 y2 x2 2.00 4.00
...
0 ym xm 2.00 4.00
You can ignore all the numbers besides the x and y -- they're just there because this file is designed to also be used by Alice's built-in trajectory generation algorithm to determine a trajectory that satisfies certain constraints (such as staying inside a certain corridor width, in this case the 2.00, or being beneath a certain speed, in this case the 4.0 -- both things you don't have to worry about).
Using Follow
To use follow, follow the following steps:
Transferring Files to Alice
- If you have a computer connected to the network in the shop or directly to Alice (like a laptop), then you can simply use any SSH program you like to connect to Alice, whose IP address is 192.168.0.52. (Use the username cds110b, and the normal password.) Or, you can SCP files over using a program like WinSCP (again, IP address is 192.168.0.52, username cds110b, password is normal.)
- If you can store your files somewhere on the internet, you can access them directly from Alice. To open up a web-browser, follow the directions below to login, and then open the Firefox browser by going to the Applications menu in the upper-left-hand corner of the screen (it's kind of like the Start Menu in this version of Linux), then going to the Internet sub-menu, and choosing the Mozilla Firefox application. Firefox is just a normal web-browser, so as long as Alice is in the shop, you should be able to simply type in a URL and get your files.
- If you're not in the shop but need to get to files stored on Alice, you can do this by:
- SSH to gc.caltech.edu (note that you must have a Caltech IP address to do this)
- Then SSH to 192.168.0.52, and copy the files (using the linux scp command) to gc.caltech.edu
- The scp command works like: scp source_file dest, so you would probably be do scp some_log_file cds110b@gc.caltech.edu:~/my_directory/.
- Then you can copy the files off of gc.caltech.edu just as you would copy them off Alice if you were in the shop
- You can transfer files off of Alice using these same methods (just copy the files in the other direction).
Executables Needed
- For running in any configuration:
- follow - purpose obvious
- gui - Optional, can be used to view what's going on
- You will need the following executables if running in simulation:
- simulator - Simulates the vehicle's dynamics, and returns the appropriate state
- If running on the real vehicle, you will need:
- adrive - Necessary for commanding the vehicle's actuators
- astate - Necessary for returning the vehicle's state
Files Needed
- For running in any configuration
- LongGains.dat - Contains PID gains for longitudinal control
- LatGains.dat - Required as an artifact of how Alice's built-in trajectory following software works -- don't worry about this file
- *.mat - A controller for you to test
- *.mat - An observer (e.g. correlation matrices) for you to test
- *.traj - A trajectory to try
- Additional files needed for running in simulation:
- simInitState.dat - Specifies the initial conditions to be used for the simulator (more detail below)
- Additional files needed for running the real vehicle:
- adrive.config - Configuration file so adrive knows what actuators to use
- parker_steer_config_params.txt - Another configuration file, used to setup the steering actuator
- config/kalman.config - Configuration file for the Kalman filter used by the state estimator
Getting Started
- Login to the computer with the username "cds110b". If you are running on Alice, it is recommended that you login to the computer named skynet2.
- All of the terminals in Alice or connected via a KVM switch (Keyboard, Video, & Monitor) that enables and monitor/keyboard/mouse to connect to any computer. To switch between computers:
- Hit the Ctrl key on your keyboard twice.
- Then, when prompted for a login-name and password, hit enter
- Use the arrow keys to select a computer
- Hit enter to enable control
- Note that if another terminal has that computer selected, you will be able to watch what that terminal is doing on the monitor, but your keybaord and mouse won't work
- All of the terminals in Alice or connected via a KVM switch (Keyboard, Video, & Monitor) that enables and monitor/keyboard/mouse to connect to any computer. To switch between computers:
- Since we will need to run more than one program, we will need more than one terminal. To open a terminal:
- Click on the "Applications" menu in the upper left-hand corner
- Click on the "System Tools" menu (near the bottom)
- Click on "Terminal" (near the bottom)
- The terminal can be tabbed (just like Firefox, for example). To open up a new tab, hit Ctrl+Shift+T
- Some programs must be run on specific computers (since certain hardware is connected to certain computers). To login to another computer (while using the same terminal), use the ssh command as follows:
ssh yourname@computername
- If running the real vehicle, you will need to use at least one terminal to login to skynet1, to run adrive, and one terminal to login to skynet5, to run astate
- If you don't already have a directory to work from, make one by using the "mkdir" (make directory) command as follows:
mkdir yourname
- Then copy the executables (located in the bin directory) to your directory, by using the "cp" (copy) command as follows:
cp -R bin/* yourname/.
- To run the programs, we must be in the correct directory. Use the "cd" (change directory) command as follows:
cd yourname
- If you're not sure which directory you want to switch to, try typing "ls" to list the contents of the current directory
- Then, we want to make sure to use the proper trajectory. This step is mostly useful if you want to see the course the vehicle will try to follow on the gui, and is optional:
- If you are going to use a trajectory file named some_file.traj, type the following command:
ln -fs some_file.rddf rddf.dat
- If you want to start off with some initial error, you can edit the simInitState.dat file:
- The format of the first few lines is as follows:
relative2 0 relative_X_coord relative_Y_coord relative_theta speed
- Where the X, Y, and theta values are relative to the starting point of the trajectory. (So to start off with a 1m offset in the x direction, you would set relative_X_coord to 1, and leave the other entries as 0.)
- Then run the programs in the following order:
./simulator --nonoise (if running in simulation, and you don't want noise) ./astate (if running for real - make sure you run it on skynet5!) ./adrive (if running for real - make sure you run it on skynet1!) ./follow (can use the -c and -t flags to specify controller and trajectory files, or load them using the sparrow display) ./gui (optional - try to run it on the same computer you have the terminal open on, usually skynet2)
As Things Are Running
Most of the programs have "sparrow displays", which is just a name for the terminal-based user interface that appears when you run the program. Sparrow displays can show you dynamically changing data about the program (such as state data, or status information), as well as allow you to interact with the program by changing the values of some variables (such as if you want to increase the gains on a controller).
To change a value in a sparrow display, use the arrow keys to navigate to the value you want to change, hit the equals key, and then type in the value you want.
Simulator
- The simulator has essentially two modes: paused and unpaused. When paused, the simulator ignores any inputs into the system, and the vehicle's state is constant (unless there is noise). When unpaused, the dynamics equations for the vehicle are used to simulate the vehicle's state as it responds to commands in steering and acceleration.
- To change modes, you can either set the PAUSED variable (near the bottom right) to 1 (for paused) or 0 (for unpaused), or use the hotkeys 'P' (for pause) and 'U' (for unpause)
- Additionally, if you want to restart at the beginning of a trajectory, the hotkey 'R' will reset the system to its initial conditions
Follow
- The follow screen is divided up into essentially four sections:
- The control area
- The state area
- The file area
- The button area
- The control area is near the top of the screen. Here you can find:
- Time - the time since the trajectory was started (will be 0 if the controller is disabled)
- Rate - the rate at which you would like the controller to be run
- Actual Rate - the actual rate at which the controller is being run (might be different from Rate if the computer can't keep up)
- Home - since the global coordinate system has its origin at some point on the equator, you can specify a relative origin to make the position numbers smaller (and easier to make sense of)
- Gain - The current gain on control signal sent to the actuators
- Desired - The reference value
- Control - The value your controller is computing based on the state
- Total - The total control signal being sent to the actuators, e.g. gain*(control+desired)
- Ovr? and Override - If you want to override what the controller comes up with, you can pick an Override value (e.g. v=5m/s, or phi=0.1rad) and then set the Ovr? flag to 1 to enable the override
- Actual - The actual current value of v or phi
- The state area is in the middle of the screen. It shows the values of all the states in the system, as well as their reference value (e.g. goal) and the error (value-goal)
- The file area is in the middle of the screen. Here you can find:
- Controller - The file you want to use as a controller. After it is changed, the system will attempt to load up the new controller, and the status message will indicate success or failure
- Gain Scheduler - Not functional yet
- Observer - Not functional yet
- Traj File - The file you want to use as your trajectory. After it is changed, the system will attempt to load up the new controller, and the status message will indicate success or failure
- Log File - The file follow will log to
- Status - Enabled, Paused, or Disabled. When enabled, the controller is running. When paused, time is frozen, and control signals are set to 0. When disbaled, time is reset to 0, and control signals are set to 0.
- The button area contains buttons for each of the main features of follow, as well as a reminder about certain hotkeys. They are:
- Home - Sets the x and y origin to the vehicle's current location
- Toggle Logging - Turns logging on or off
- New Log File - Starts logging to a new log file
- Toggle Autonaming - If autonaming is on, follow will automatically name any log files generated with the current date and time. If autonaming is off, then follow will just use the name given in the file area. (Note that if autonaming is off, and you toggle logging repeatedly, follow will continue to overwrite the same log file unless you change the name.)
- Resume Control - Self-explanatory
- Pause Control - Self-explanatory
- Disable Control - Self-explanatory
- Quit - Self-explanatory
GUI
- Some neat things to try/notice in the GUI are:
- The vehicle will trace out a red line as it moves, so you can see where it's been. You can clear the red line by hitting "Clear Current Layer" at the right of the screen (or using the hotkey Ctrl+K)
- You can zoom in and out by clicking in the Zoom box (near the bottom right) (or using the hotkey Ctrl+M) and then using the arrow keys to scroll up or down (or use PageUp and PageDown)
- Double-clicking anywhere in the map will center on that point
- Right-clicking anywhere in the map will re-center you on the vehicle's position
Logged Data
- 20060219_pasadena - Some test data for computing correlation matrices for your observers
Testing Schedule
| Date | Times | Who | Why/What For? |
| Friday, 26 Jan | 12:00PM - 3:00PM | Tully Foote | Testing at Santa Anita |
| Friday, 26 Jan | 10:30AM - 12:00PM | Matthew Munson | In-shop development |
![[Main Page]](../../../../upload/alice.jpg)