Skip to content

Commit

Permalink
added function deadzone_aplyer to clen up code and added redabilety/m…
Browse files Browse the repository at this point in the history
…odefiabilety
  • Loading branch information
Trobolit committed Sep 26, 2018
1 parent 500d9b9 commit eda7bb5
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions joy/src/joy_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,24 @@ class Joystick
}
}


closedir(dev_dir);
return "";
}

// Aplay deadzone
// Enshore thate the values inside the deadzond is zero
// Allso adapt the scale of val to be consistent whit deadzond
void deadzone_aplyer(double* val, double* unscaled_deadzone){
if (*val > *unscaled_deadzone)
*val -= *unscaled_deadzone;
else if (*val < -*unscaled_deadzone)
*val += *unscaled_deadzone;
else
*val = 0;
}


public:
Joystick() : nh_(), diagnostic_(), ff_fd_(-1)
{}
Expand Down Expand Up @@ -413,20 +427,15 @@ class Joystick
last_published_joy_msg.axes.resize(event.number+1);
sticky_buttons_joy_msg.axes.resize(event.number+1);
for(unsigned int i=old_size;i<joy_msg.axes.size();i++){
joy_msg.axes[i] = 0.0;
joy_msg.axes[i] = 0.0;
last_published_joy_msg.axes[i] = 0.0;
sticky_buttons_joy_msg.axes[i] = 0.0;
}
}
if(default_trig_val_){
// Allows deadzone to be "smooth"
if (val > unscaled_deadzone)
val -= unscaled_deadzone;
else if (val < -unscaled_deadzone)
val += unscaled_deadzone;
else
val = 0;
joy_msg.axes[event.number] = val * scale;
// Aplye deadzone to val
deadzone_aplyer(&val, &unscaled_deadzone);
joy_msg.axes[event.number] = val * scale;
// Will wait a bit before sending to try to combine events.
publish_soon = true;
break;
Expand All @@ -435,13 +444,9 @@ class Joystick
{
if (!(event.type & JS_EVENT_INIT))
{
val = event.value;
if(val > unscaled_deadzone)
val -= unscaled_deadzone;
else if(val < -unscaled_deadzone)
val += unscaled_deadzone;
else
val=0;
// Aplaye deadzone to val
val = event.value;
deadzone_aplyer(&val, &unscaled_deadzone);
joy_msg.axes[event.number]= val * scale;
}

Expand Down

0 comments on commit eda7bb5

Please sign in to comment.