position_velocity.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, The Regents of the University of California (Regents).
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer in the documentation and/or other materials provided
15  * with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Please contact the author(s) of this library if you have any questions.
34  * Authors: David Fridovich-Keil ( dfk@eecs.berkeley.edu )
35  */
36 
38 //
39 // Class for purely geometric (position + velocity) state.
40 //
42 
43 #ifndef FASTRACK_STATE_POSITION_VELOCITY_H
44 #define FASTRACK_STATE_POSITION_VELOCITY_H
45 
47 #include <fastrack/state/state.h>
48 
49 namespace fastrack {
50 namespace state {
51 
52 class PositionVelocity : public State {
53  public:
55  explicit PositionVelocity()
56  : position_(Vector3d::Zero()), velocity_(Vector3d::Zero()) {}
57  explicit PositionVelocity(double x, double y, double z, double vx, double vy,
58  double vz);
59  explicit PositionVelocity(const Vector3d& position, const Vector3d& velocity);
60  explicit PositionVelocity(const fastrack_msgs::State& msg);
61  explicit PositionVelocity(const VectorXd& x);
62 
63  // Accessors.
64  inline double X() const { return position_(0); }
65  inline double Y() const { return position_(1); }
66  inline double Z() const { return position_(2); }
67  inline double Vx() const { return velocity_(0); }
68  inline double Vy() const { return velocity_(1); }
69  inline double Vz() const { return velocity_(2); }
70 
71  inline Vector3d Position() const { return position_; }
72  inline Vector3d Velocity() const { return velocity_; }
73  inline VectorXd Configuration() const {
74  VectorXd config(3);
75  config(0) = position_(0);
76  config(1) = position_(1);
77  config(2) = position_(2);
78 
79  return config;
80  }
81 
82  // Setters.
83  inline double& X() { return position_(0); }
84  inline double& Y() { return position_(1); }
85  inline double& Z() { return position_(2); }
86  inline double& Vx() { return velocity_(0); }
87  inline double& Vy() { return velocity_(1); }
88  inline double& Vz() { return velocity_(2); }
89 
90  inline Vector3d& Position() { return position_; }
91  inline Vector3d& Velocity() { return velocity_; }
92 
93  // Set non-configuration dimensions to match the given config derivative.
94  void SetConfigurationDot(const VectorXd& configuration_dot);
95 
96  // What are the positions that the system occupies at the current state.
97  // NOTE! For simplicity, this is a finite set. In future, this could
98  // be generalized to a collection of generic obstacles.
99  std::vector<Vector3d> OccupiedPositions() const;
100 
101  // Convert from/to VectorXd. Assume State is [x, y, z, vx, vy, vz]
102  void FromVector(const VectorXd& x);
103  VectorXd ToVector() const;
104 
105  // Convert from/to ROS message. Assume State is [x, y, z, vx, vy, vz]
106  // or configuration only.
107  void FromRos(const fastrack_msgs::State& msg);
108  fastrack_msgs::State ToRos() const;
109 
110  // Dimension of the state and configuration spaces.
111  static constexpr size_t StateDimension() { return 6; }
112  static constexpr size_t ConfigurationDimension() { return 3; }
113 
114  // Set/get bounds of the state/configuration space.
115  static void SetBounds(const PositionVelocity& lower,
116  const PositionVelocity& upper);
117  static void SetBounds(const std::vector<double>& lower,
118  const std::vector<double>& upper);
119  static const PositionVelocity& GetLower();
120  static const PositionVelocity& GetUpper();
121  static VectorXd GetConfigurationLower();
122  static VectorXd GetConfigurationUpper();
123 
124  // Sample from the configuration space associated with this state space.
125  static VectorXd SampleConfiguration();
126 
127  // Sample from the state space itself.
128  static PositionVelocity Sample();
129 
130  // Samples within a box of the given position, intersected with the state
131  // space bounds.
132  static PositionVelocity SampleCloseTo(const Vector3d& pos, double d);
133 
134  // Compound assignment operators.
137  PositionVelocity& operator*=(double s);
138  PositionVelocity& operator/=(double s);
139 
140  // Binary operators.
142  const PositionVelocity& rhs);
144  const PositionVelocity& rhs);
145  friend PositionVelocity operator*(PositionVelocity lhs, double s);
146  friend PositionVelocity operator*(double s, PositionVelocity rhs);
147  friend PositionVelocity operator/(PositionVelocity lhs, double s);
148  friend PositionVelocity operator/(double s, PositionVelocity rhs);
149 
150  private:
151  Vector3d position_;
152  Vector3d velocity_;
153 
154  // Static state space bounds for this state space.
157 }; //\class PositionVelocity
158 
159 } // namespace state
160 } // namespace fastrack
161 
162 #endif
static void SetBounds(const PositionVelocity &lower, const PositionVelocity &upper)
static PositionVelocity Sample()
void SetConfigurationDot(const VectorXd &configuration_dot)
PositionVelocity & operator+=(const PositionVelocity &rhs)
friend PositionVelocity operator/(PositionVelocity lhs, double s)
static const PositionVelocity & GetUpper()
PositionVelocity & operator-=(const PositionVelocity &rhs)
friend PositionVelocity operator+(PositionVelocity lhs, const PositionVelocity &rhs)
static const PositionVelocity & GetLower()
PositionVelocity & operator*=(double s)
std::vector< Vector3d > OccupiedPositions() const
Definition: box.h:53
void FromRos(const fastrack_msgs::State &msg)
fastrack_msgs::State ToRos() const
static constexpr size_t StateDimension()
PositionVelocity & operator/=(double s)
friend PositionVelocity operator*(PositionVelocity lhs, double s)
static constexpr size_t ConfigurationDimension()
static PositionVelocity SampleCloseTo(const Vector3d &pos, double d)
friend PositionVelocity operator-(PositionVelocity lhs, const PositionVelocity &rhs)


fastrack
Author(s): David Fridovich-Keil
autogenerated on Mon Aug 3 2020 21:28:37