-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Acceleration #5
base: master
Are you sure you want to change the base?
Acceleration #5
Changes from 2 commits
b6883a4
105a874
5a9a53e
e3c3fde
73021d8
52f3c81
5708b0c
eb8a8f8
324ffd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,19 +40,58 @@ bool GenericRawToMotion2D::startHook() | |
void GenericRawToMotion2D::updateHook() | ||
{ | ||
RawCommand rcmd; | ||
base::commands::Motion2D mcmd; | ||
if(_raw_command.read(rcmd) == RTT::NewData){ | ||
int trans_axis = _translation_axis.get().at(0); | ||
int trans_subaxis = _translation_axis.get().at(1); | ||
|
||
int rot_axis = _rotation_axis.get().at(0); | ||
int rot_subaxis = _rotation_axis.get().at(1); | ||
double trans_raw = rcmd.axisValue[trans_axis][trans_subaxis]; | ||
double rot_raw = rcmd.axisValue[rot_axis][rot_subaxis]; | ||
|
||
mcmd.translation = fabs(trans_raw) < _translation_axis_deadzone ? 0.0 : trans_raw * _maxSpeed; | ||
double w = (trans_raw < 0.0) ? rot_raw * _maxRotationSpeed : - rot_raw * _maxRotationSpeed; | ||
mcmd.rotation = fabs(rot_raw) < _rotation_axis_deadzone ? 0.0 : w; | ||
if (_raw_command.read(rcmd) == RTT::NewData) { | ||
|
||
double trans_raw = rcmd.axisValue[_translation_axis.get().at(0)][_translation_axis.get().at(1)]; | ||
double rot_raw = rcmd.axisValue[_rotation_axis.get().at(0)][_rotation_axis.get().at(1)]; | ||
|
||
// just use input values when they exceed deadzone | ||
trans_raw = fabs(trans_raw) < _translation_axis_deadzone ? 0.0 : trans_raw; | ||
rot_raw = fabs(rot_raw) < _rotation_axis_deadzone ? 0.0 : rot_raw; | ||
|
||
|
||
if(!_acceleration_mode){ | ||
mcmd.translation = trans_raw * _maxSpeed; | ||
mcmd.rotation = (trans_raw < 0.0) ? rot_raw * _maxRotationSpeed : - rot_raw * _maxRotationSpeed; | ||
_motion_command.write(mcmd); | ||
return; | ||
} | ||
|
||
/* stop if stop button was pressed */ | ||
uint8_t stop_button = rcmd.buttonValue[_stop_button.get()]; | ||
if (stop_button == 1) { | ||
mcmd.translation = 0.0; | ||
mcmd.rotation = 0.0; | ||
_motion_command.write(mcmd); | ||
return; | ||
} | ||
|
||
/* handle the translational part */ | ||
uint8_t stop_translation_button = rcmd.buttonValue[_stop_translation_button.get()]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that not every input device necessarily provides buttons, so this options should be optional and deactivated on default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, that's why they are just used with acceleration mode enabled. Maybe it's a good idea to check the length of the button vector before? |
||
if (stop_translation_button == 1) { | ||
mcmd.translation = 0.0; | ||
} else { | ||
// just accelerate when input values exceed deadzone | ||
mcmd.translation += trans_raw * _maxAcceleration; | ||
|
||
// limit translation speed | ||
mcmd.translation = (mcmd.translation < 0.0) ? std::max(-_maxSpeed.get(), mcmd.translation) : std::min(_maxSpeed.get(), mcmd.translation); | ||
} | ||
|
||
/* handle the rotational part */ | ||
uint8_t stop_rotation_button = rcmd.buttonValue[_stop_rotation_button.get()]; | ||
if (stop_rotation_button == 1) { | ||
mcmd.rotation = 0.0; | ||
} else { | ||
// just accelerate when input values exceed deadzone | ||
double acc = rot_raw * _maxRotationAcceleration.get(); | ||
|
||
// reverse rotation acceleration when going backwards | ||
mcmd.rotation = (trans_raw < 0.0) ? mcmd.rotation + acc : mcmd.rotation - acc; | ||
|
||
// limit rotation speed | ||
mcmd.rotation = mcmd.rotation < 0.0 ? std::max(mcmd.rotation, -_maxRotationSpeed.get()) : std::min(mcmd.rotation, _maxRotationSpeed.get()); | ||
} | ||
_motion_command.write(mcmd); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The buttons are not evaluated in case of the acceleration mode. Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are only evaluated in acceleration mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes. But it might be a nice feature in general.