Is there a way to program a servo to start at -127 (-90 degrees) and have the gain button move the servo completely from -127 to +127? Thank you.
Quote 0 0
Servos only move +-45 degrees, but you can call that -90 to zero degrees if you want.
There is no button called gain, just buttons 5 through 8, with various up down left right adders.
Look at the other thread something like "help for rookie team".
I helped them work out a similar problem.  Maybe that type of solution you can adapt to your problem
Quote 0 0

If all you want to do is just have the servo move from minimum to maximum position with the press of a button. All you should have to do is use a gain and an offset after the Boolean button press. I modified the "button2motor" example shipped in the support package as shown in the picture below to give you an idea. This should move the servo from min to max with the push of a button, and you can decide whether you want to keep or discard the latch behavior. button2motor.PNG 
Hope this helps.

Cheers !


Quote 0 0
What programming environment are you using?

The following is some pseudocode for EasyC showing a main method that does what you have asked for (assuming that the servo is on port 2).

public void main(){


    else if(getJoystickDigital(5,Down)!=0)

The first call to setServo will move the servo to -45deg (approx).  When you push the Up button in channel 5, the servo will move to +45deg.  When you push the Down button in channel 5, the servo will move back to -45deg.  When neither button is pushed, the servo just stays put.  When both buttons are pushed, it will be as if just the Up button is pushed.

- David Gauntt
Quote 0 0
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.

Quote 0 0

Definitely ! That is one of the most important reasons to use Simulink, we have tons of blocks that make life easier. What you guys want to use in this case is a 'Rate Limiter' block.  You can single click on the canvas and type the name or find it under the Library browser Simulink->Discontinuities.

You can define in the options the rising and falling slew rates directly and it will gradually reach the commanded position and save all your gears. You can just place the block in front of the Servo block and run some tests to find a rate you like. See a sample implementation in the figure below based on one of our examples. Rate_limiter1.png If you want to get a little more advanced. The rate at which the blocks limits is dependent on the sample time of the Simulink signal (A property of the line connecting the blocks). You can change the sample time of the servo block (the interval at which a servoWrite command is executed) by placing a 'Rate Transition' in Front of your rate limiter and adjusting the 'Output Port Sample Time'. As a reminder the sample time is in seconds so a number like 0.01 seconds might be a good place to start. See picture below for example.

If you guys want more information the documentation page for the block or clicking the help button on the dialog might be of use. But feel free to ask any other questions you might have.


Hope this helps !



Quote 0 0
In the real world on a robot, the loop time might be < 1ms, the signal to the servo might be updated 13-40ms apart, and the servo might take 300ms to travel end to end.  If we want to slow the end to end transition time from 300ms to 1 second, and the ends are 254 units apart, we would put in a sample time of 1/254 = 0.04 or about 40ms, and use smaller rate times to get faster transitions.  In the real world, the block has access to the real world timer, so the random servo update time of 13-40ms has no effect, and the loop time of 1ms or 1us or 10ms has no effect.  Is that right?
Quote 0 0
In the generated code the servo write statements will execute at the sample time specified by the signal. Basically, the servo write block execution can differ from your loop time if you specify it this way or they can be the same.

Here is a more detailed explanation of the overall workflow. 

1. To achieve end-to-end servo actuation within 1 second:

The units on the slew rate for the rate limiter block can be thought off as 'unit per second (units/sec)'. In this case the units have a range of -127 to 127 (254 total) which is the input to the servo write block. If you want to limit the servo increments to move from -127 to 127 in a minimum of 1 second you would choose a slew rate of 254 (units/sec) or -254 if going the opposite direction. Simulation is really helpful here to fine tune the exact rate if you want to be really precise. Use a scope to see the output over time to check how long it will take the servo to reach a desired position. I attached the image below with the 1 second end-to-end example:

2. Regarding the execution of the servo write block:

The sample time of the signal (set by either a source block or a rate transition) will determine the timing of execution of the servo write statements. This will translate directly to the smoothness of the physical movement. Simulations helps clear things out here also. See the following example:

In the example above you can see the servo programmed with a smaller sample time will move a lot smoother. You guys can try finding a sweet spot for your sample times but something on the lines of 0.01 or 0.02 should give you a very smooth operation.

You can check to make sure everything will be executing at you desired sample times (rates) by showing the Sample time legend, these will be the same rates running in the Cortex once programmed. There is a button in the left side of the canvas with two arrows. 

Hope this helps guys! Feel free to let me know if you all encounter any issues or if you want more examples.

Happy to help [smile]

Quote 0 0

Add a Website Forum to your website.