BEST Robotics Forum
Register Calendar Latest Topics

  Author   Comment  

Junior Member
Posts: 1
Reply with quote  #1 
i need help trying to move a servo from left to right with the GamePads 8 "L" and 8"R"
("8L" going left and "8R" going right). I need to to slowly turn, like(when "8R" is pressed subtract 3 from servos current position) to make it a precise turn. any help?

Posts: 112
Reply with quote  #2 
For slew rate control, you'd have to have different variables for "current servo setting", "target servo setting".
As you go through the while(1) loop, check the time, and only update the "current servo setting" toward the target by your increment, no more rapidly than 50ms apart.
  For your jog-mode control, you still need a variable to carry the current state,  then use math block to change that variable when you detect that "8R" changes from the un-pressed state to the pressed state.
  If that is not enough help for you, one of the simulink guys will have to comment.


Posts: 59
Reply with quote  #3 
As jgraber mentioned, you need two variables to control the increment rate of the servo angle.

Below is an example using Simulink on how to achieve this. I am using MATLAB Function block to control the increment rate, 5U goes towards +60 degrees and 5D goes to -60 degrees. Also the MATLAB functions checks to make sure that the value going to the Servo block is not going below 0 (you can change this to -127) and not above +127 (60 degrees). Note that the variable counter determines in what increment or decrements the servo moves. To go faster, increase the 'counter' value, to go slow, decrease it.


The two variables that represent the servo angle values are y_new and y_old. When this model is uploaded to the robot, the new servo angle (y_new) is computed at every time instant based on the servo angle (y_old) from the previous instant of time. To achieve the y_old value, we use a Memory block that takes the current servo angle value and feeds it back to the MATLAB function in the next time instance as y_old. 

Use the above example to create your own rate control module in Simulink. Note that the 'Real-Time' block in the above example helps slow down the simulation speed and thus you will be able to see the angle values in the Display block change when running the model in simulation mode. Real-Time block can be found in Utilities in the VEX Library.


Previous Topic | Next Topic

Quick Navigation: