function control = acc_controller(state, desired_state, P)
% Longitudinal controller that computes an optimal acceleration profile to reach a desired state
% subject to desired nominal velocity and comfortable acceleration/deceleration limits
% all static problem data and configuration is defined in the problem structure P

% get an optimal acceleration profile to the goal state
[states, controls] = acc_profile(state, desired_state, P);

% use the first control as our control
control = controls(1);

% ensure within bounds
control = bound_control(control, P.cars(state.id));
