shiremath
Controlling DC Motors  and Servos using the Gamepad Buttons:

The DC Motors are bi-directional and speed varying. Thus by controlling the voltage supply value to the motor you can controlling the speed and direction of rotation. In Simulink, the motor has a linear input value range from -127 (gives max counterclockwise speed) to 127 (gives max clockwise speed). At 0 value, the motor remains stationary. So speed increases in the clockwise direction when motor value goes from 0 to 127, and it increases in counter clockwise when the value goes from 0 to -127.

The VEX Controller buttons produce a digital/boolean value - 1 or 0. It is 1 when button is pressed and 0 when no pressed. 

In Simulink, to control a DC motor using a button, you should map them as shown below. Notice the values displayed in 'button_output1' and 'button_output2' blocks. These are the values output from the button blocks that are being fed to the DC Motor blocks. The values are digital, 0 or 1. This the motor speeds are either 0 or a really small speed equivalent to the value 1 that is fed in to the motor block. Thus, for the model below, when the buttons are pressed (value =1), you do not really notice any physical movement of the motors. button2DCmotor.PNG 


SOLUTION:
To control motors you need to supply the DC Motor block with a value in the range of -127 to 127, but when using the controller/gamepad buttons to control the motors, you need to make sure that the value fed to the motor blocks are large enough to drive the motors. To do this, use a Gain block to multiply the button value by a large factor, say 100, depending on the motor speed that you desire. Thus, the model with Gain blocks will look something like as shown below:
button2DCmotor_correct.PNG 
With this above solution, you can change the Gain values as you desire to obtain a constant motor speed (+ve for clockwise and -ve for counter) when the button is pressed. 

 SOLUTION - Controlling Servos-

Similar to the above solution, you can also control Servo motors angles suing the VEX Controller buttons. The input value range to the motor block remains the same i.e. -127 to 127, but this translates to servo angles in the range -60 to 60 degrees.
button2servo_correct.png 

NOTE: Display blocks are very good debugging tools that you should use to investigate the output values from blocks in your Simulink model. Connect a Display block to an existing line/connection and then 'Run' the model in simulation mode to see the output values displayed in the Display block. For example, notice how in the above examples Display blocks are used to observe the before and after effects of the Gain blocks.
Quote 0 0