37 #include "ompl/control/spaces/RealVectorControlSpace.h"
38 #include "ompl/util/Exception.h"
39 #include <boost/lexical_cast.hpp>
49 for (
unsigned int i = 0 ; i < dim ; ++i)
62 if (bounds.
low.size() != dimension_)
63 throw Exception(
"Bounds do not match dimension of control space: expected dimension " +
64 boost::lexical_cast<std::string>(dimension_) +
" but got dimension " +
65 boost::lexical_cast<std::string>(bounds.
low.size()));
76 memcpy(static_cast<ControlType*>(destination)->values,
77 static_cast<const ControlType*>(source)->values, controlBytes_);
82 const double *s1 =
static_cast<const ControlType*
>(control1)->values;
83 const double *s2 =
static_cast<const ControlType*
>(control2)->values;
84 for (
unsigned int i = 0 ; i < dimension_ ; ++i)
86 double diff = (*s1++) - (*s2++);
87 if (fabs(diff) > std::numeric_limits<double>::epsilon() * 2.0)
101 rcontrol->
values =
new double[dimension_];
108 delete[] rcontrol->
values;
115 for (
unsigned int i = 0 ; i < dimension_ ; ++i)
117 if (bounds_.low[i] <= 0.0 && bounds_.high[i] >= 0.0)
118 rcontrol->
values[i] = 0.0;
120 rcontrol->
values[i] = bounds_.low[i];
126 return index < dimension_ ? static_cast<ControlType*>(control)->values + index : NULL;
131 out <<
"RealVectorControl [";
135 for (
unsigned int i = 0 ; i < dimension_ ; ++i)
137 out << rcontrol->
values[i];
138 if (i + 1 < dimension_)
144 out <<
']' << std::endl;
149 out <<
"Real vector control space '" << getName() <<
"' with bounds: " << std::endl;
151 for (
unsigned int i = 0 ; i < dimension_ ; ++i)
152 out << bounds_.low[i] <<
" ";
155 for (
unsigned int i = 0 ; i < dimension_ ; ++i)
156 out << bounds_.high[i] <<
" ";
162 return controlBytes_;
std::vector< double > low
Lower bound.
Definition of an abstract control.
A boost shared pointer wrapper for ompl::control::ControlSampler.
const ControlSpace * space_
The control space this sampler operates on.
virtual void setup(void)
Perform final setup steps. This function is automatically called by the SpaceInformation.
virtual void serialize(void *serialization, const Control *ctrl) const
Serializes the given control into the serialization buffer.
virtual unsigned int getSerializationLength(void) const
Returns the serialization size for a single control in this space.
virtual void printControl(const Control *control, std::ostream &out) const
Print a control to a stream.
virtual double * getValueAddressAtIndex(Control *control, const unsigned int index) const
Many controls contain a number of double values. This function provides a means to get the memory add...
virtual void nullControl(Control *control) const
Make the control have no effect if it were to be applied to a state for any amount of time...
virtual Control * allocControl(void) const
Allocate memory for a control.
virtual void deserialize(Control *ctrl, const void *serialization) const
Deserializes a control from the serialization buffer.
virtual void copyControl(Control *destination, const Control *source) const
Copy a control to another.
A control space representing Rn.
std::vector< double > high
Upper bound.
The definition of a control in Rn
double uniformReal(double lower_bound, double upper_bound)
Generate a random real within given bounds: [lower_bound, upper_bound)
virtual void freeControl(Control *control) const
Free the memory of a control.
virtual void setup(void)
Perform final setup steps. This function is automatically called by the SpaceInformation.
virtual void printSettings(std::ostream &out) const
Print the settings for this control space to a stream.
virtual unsigned int getDimension(void) const
Get the dimension of this control space.
void check(void) const
Check if the bounds are valid (same length for low and high, high[i] > low[i]). Throw an exception if...
The exception type for ompl.
virtual ControlSamplerPtr allocDefaultControlSampler(void) const
Allocate the default control sampler.
The lower and upper bounds for an Rn space.
const T * as(void) const
Cast this instance to a desired type.
virtual unsigned int getDimension(void) const =0
Get the dimension of this control space.
RNG rng_
Instance of random number generator.
virtual bool equalControls(const Control *control1, const Control *control2) const
Check if two controls are the same.
void setBounds(const base::RealVectorBounds &bounds)
Set the bounds (min max values for each dimension) for the control.
double * values
An array of length n, representing the value of the control.