Program Listing for File traction_limiter.hpp

Return to documentation for file (include/tricycle_controller/traction_limiter.hpp)

// Copyright 2022 Pixel Robotics.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*
 * Author: Tony Najjar
 */

#ifndef TRICYCLE_CONTROLLER__TRACTION_LIMITER_HPP_
#define TRICYCLE_CONTROLLER__TRACTION_LIMITER_HPP_

#include <cmath>

namespace tricycle_controller
{
class TractionLimiter
{
public:
  TractionLimiter(
    double min_velocity = NAN, double max_velocity = NAN, double min_acceleration = NAN,
    double max_acceleration = NAN, double min_deceleration = NAN, double max_deceleration = NAN,
    double min_jerk = NAN, double max_jerk = NAN);

  double limit(double & v, double v0, double v1, double dt);

  double limit_velocity(double & v);

  double limit_acceleration(double & v, double v0, double dt);

  double limit_jerk(double & v, double v0, double v1, double dt);

private:
  // Velocity limits:
  double min_velocity_;
  double max_velocity_;

  // Acceleration limits:
  double min_acceleration_;
  double max_acceleration_;

  // Deceleration limits:
  double min_deceleration_;
  double max_deceleration_;

  // Jerk limits:
  double min_jerk_;
  double max_jerk_;
};

}  // namespace tricycle_controller

#endif  // TRICYCLE_CONTROLLER__TRACTION_LIMITER_HPP_