This is Simulink forum so we should assume that.
Is there an easy way to implement slew control in Simulink? ie gradually decrease or increase servo when down or up button is pressed, respectively.
I just replaced a broken gear servo for a team that is banging heavy claw open and shut without slew control, but you can't do that during a match.
However, I have untested pseudo C code to show some ideas for implementing slew control posted below.
This is pseudo code, you'll have to figure out real code yourself.
test each step as you go.
level 0: joystick digital to servo like you have now.
level1: (similar to C code from DGauntt)
declare int : var1, var2;
var1 = get joystick (button); var2 = get joystick (button2);
if (conditional based on vars )then { setmotor this}
if (conditional based on vars)then {setmotor that }
level2: add slew control, but may not be effective if loop time is very fast.
declare more vars for servostep, timestep, prevtime, nowservo, wantservo
initialize as 1,5,0,0,0
var1 = get joystick (button); var2 = get joystick (button2);
if ( conditional based on vars )then // move positive
{ nowmotor=min(127,nowmotor+servostep) }
if ( conditional based on vars )then // move negative
{ nowmotor=max(-127,nowmotor-servostep) }
setmotor( now motor) // doit
Level3; Add 1ms wait time in the loop, adjust slew speed by changing wait time vs servostep size to get what you want.
Level4; How do you avoid adding wait time? have to keep track of last time you updated nowmotor, and don't update it again until timestep has passed.