18CopyPose::CopyPose(
unsigned int control_output,
unsigned int dynamic_output,
double armlength,
double accuracy,
unsigned int maximum_iterations):
21 m_poseCCh(-1),m_poseCTs(0)
23 m_maxerror = armlength/2.0;
24 m_outputControl = (control_output &
CTL_ALL);
25 unsigned int _nc = nBitsOn(m_outputControl);
29 reset(_nc, accuracy, maximum_iterations);
32 int nrot = 0, npos = 0;
33 int nposCache = 0, nrotCache = 0;
34 m_outputDynamic = (dynamic_output & m_outputControl);
35 memset(m_values, 0,
sizeof(m_values));
36 memset(m_posData, 0,
sizeof(m_posData));
37 memset(m_rotData, 0,
sizeof(m_rotData));
38 memset(&m_rot, 0,
sizeof(m_rot));
39 memset(&m_pos, 0,
sizeof(m_pos));
43 m_pos.tolerance = 0.05;
44 m_values[m_nvalues].
alpha = m_pos.alpha;
45 m_values[m_nvalues].
feedback = m_pos.K;
46 m_values[m_nvalues].
tolerance = m_pos.tolerance;
49 m_Wy(_nc) = m_pos.alpha;
56 m_Wy(_nc) = m_pos.alpha;
63 m_Wy(_nc) = m_pos.alpha;
69 m_values[m_nvalues].
number = npos;
70 m_values[m_nvalues++].
values = m_posData;
77 m_rot.tolerance = 0.05;
78 m_values[m_nvalues].
alpha = m_rot.alpha;
79 m_values[m_nvalues].
feedback = m_rot.K;
80 m_values[m_nvalues].
tolerance = m_rot.tolerance;
83 m_Wy(_nc) = m_rot.alpha;
90 m_Wy(_nc) = m_rot.alpha;
97 m_Wy(_nc) = m_rot.alpha;
103 m_values[m_nvalues].
number = nrot;
104 m_values[m_nvalues++].
values = m_rotData;
110 m_poseCacheSize = ((nrotCache)?(3+nrotCache*2):0)+((nposCache)?(3+nposCache*2):0);
136 m_poseCCh = m_cache->
addChannel(
this,
"Xf", m_poseCacheSize*
sizeof(
double));
142double* CopyPose::pushValues(
double* item, ControlState* _state,
unsigned int mask)
144 ControlState::ControlValue* _yval;
147 *item++ = _state->alpha;
149 *item++ = _state->tolerance;
151 for (i=0, _yval=_state->output; i<_state->ny; mask<<=1) {
152 if (m_outputControl & mask) {
153 if (m_outputDynamic & mask) {
155 *item++ = _yval->yddot;
164void CopyPose::pushPose(
CacheTS timestamp)
166 if (m_poseCCh >= 0) {
167 if (m_poseCacheSize) {
177 m_poseCTs = timestamp;
181double* CopyPose::restoreValues(
double* item, ConstraintValues* _values, ControlState* _state,
unsigned int mask)
183 ConstraintSingleValue* _data;
184 ControlState::ControlValue* _yval;
187 _values->alpha = _state->alpha = *item++;
188 _values->feedback = _state->K = *item++;
189 _values->tolerance = _state->tolerance = *item++;
191 for (i=_state->firsty, j=i+_state->ny, _yval=_state->output, _data=_values->values; i<j; mask<<=1) {
192 if (m_outputControl & mask) {
193 m_Wy(i) = _state->alpha;
194 if (m_outputDynamic & mask) {
195 _data->yd = _yval->yd = *item++;
196 _data->yddot = _yval->yddot = *item++;
206bool CopyPose::popPose(
CacheTS timestamp)
209 if (m_poseCCh >= 0) {
213 if (timestamp != m_poseCTs) {
217 item = restoreValues(item, &m_values[i], &m_pos,
CTL_POSITIONX);
223 item = restoreValues(item, &m_values[i], &m_rot,
CTL_ROTATIONX);
227 m_poseCTs = timestamp;
235void CopyPose::interpolateOutput(ControlState* _state,
unsigned int mask,
const Timestamp& timestamp)
237 ControlState::ControlValue* _yval;
240 for (i=0, _yval=_state->output; i<_state->ny; mask <<= 1) {
241 if (m_outputControl & mask) {
242 if (m_outputDynamic & mask) {
243 if (timestamp.substep && timestamp.interpolate) {
244 _yval->yd += _yval->yddot*timestamp.realTimestep;
246 _yval->yd = _yval->nextyd;
247 _yval->yddot = _yval->nextyddot;
286void CopyPose::updateState(
ConstraintValues* _values, ControlState* _state,
unsigned int mask,
double timestep)
289 ControlState::ControlValue* _yval;
295 _state->alpha = _values->
alpha;
306 for (i=_state->firsty, j=_state->firsty+_state->ny, _yval=_state->output; i<j; mask <<= 1,
id++) {
307 if (m_outputControl & mask) {
309 m_Wy(i) = _state->alpha;
311 for (k=0, _data=_values->
values; k<_values->
number; k++, _data++) {
312 if (_data->
id ==
id) {
319 _data->
yd = _yval->yd+_data->
yddot*timestep;
322 _yval->nextyd = _data->
yd;
327 _yval->
yddot = (_data->
yd-_yval->yd)/timestep;
331 _yval->yd = _yval->nextyd;
332 _yval->yddot = _yval->nextyddot;
339 _yval->yd = _data->
yd - _data->
yddot*timestep;
340 _yval->nextyd = _data->
yd;
341 _yval->nextyddot = _data->
yddot;
343 _yval->yddot = (_data->
yd-_yval->yd)/timestep;
345 _yval->yd = _yval->nextyd;
346 _yval->yddot = _yval->nextyddot;
361 while (_nvalues > 0) {
374void CopyPose::updateValues(
Vector& vel,
ConstraintValues* _values, ControlState* _state,
unsigned int mask)
377 ControlState::ControlValue* _yval;
382 for (i=_state->firsty, j=0, _yval=_state->output, _data=_values->
values; j<3; j++, mask<<=1) {
383 if (m_outputControl & mask) {
384 *(
double*)&_data->
y = vel(j);
386 _data->
yd = _yval->yd;
387 _data->
yddot = _yval->yddot;
396void CopyPose::updateOutput(Vector& vel, ControlState* _state,
unsigned int mask)
398 ControlState::ControlValue* _yval;
404 for (j=0, _yval=_state->output; j<3; j++) {
405 if (m_outputControl & (mask<<j)) {
411 if (
len > m_maxerror)
412 coef = m_maxerror/
len;
414 for (i=_state->firsty, j=0, _yval=_state->output; j<3; j++) {
415 if (m_outputControl & (mask<<j)) {
416 m_ydot(i)=_yval->yddot+_state->K*coef*(_yval->yd-vel(j));
void reset()
clear internal cached data and reset random seed
represents a frame transformation in 3D space (rotation + translation)
represents both translational and rotational velocities.
A concrete implementation of a 3 dimensional vector class.
int addChannel(const void *device, const char *name, unsigned int maxItemSize)
double * addCacheVectorIfDifferent(const void *device, int channel, CacheTS timestamp, double *data, unsigned int length, double threshold)
const void * getPreviousCacheItem(const void *device, int channel, CacheTS *timestamp)
KDL::Frame m_internalPose
KDL::Frame m_externalPose
ConstraintCallback m_constraintCallback
virtual void initCache(Cache *_cache)
virtual double getMaxTimestep(double ×tep)
virtual bool initialise(Frame &init_pose)
virtual bool setControlParameters(struct ConstraintValues *_values, unsigned int _nvalues, double timestep)
virtual void updateJacobian()
CopyPose(unsigned int control_output=CTL_ALL, unsigned int dynamic_output=CTL_NONE, double armlength=1.0, double accuracy=1e-6, unsigned int maximum_iterations=100)
virtual void modelUpdate(Frame &_external_pose, const Timestamp ×tamp)
virtual void pushCache(const Timestamp ×tamp)
virtual const ConstraintValues * getControlParameters(unsigned int *_nvalues)
virtual void updateKinematics(const Timestamp ×tamp)
virtual void updateControlOutput(const Timestamp ×tamp)
#define e_identity_matrix
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt=1)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > sqr(const Rall1d< T, V, S > &arg)
double epsilon
default precision while comparing with Equal(..,..) functions. Initialized at 0.0000001.
const unsigned int maxPoseCacheSize
struct ConstraintSingleValue * values