We need to send two different values to the same servo motor based on the button pushed.

We have previously used EasyC to program our VEX Controller. The construct works fine using an if Else statement.

We use GetJoyStickDigital in EasyC and based on the response(which button is pushed) from the Joystick we then jump into a If Else control structure. 

If 6U then open servo -10
else if 6D then open servo -127
else close servo

We tried to implement this in Simulink but were not successful. I am not sure we have the If Else construct concept down in Simulink.

We can get a single Button signal to work fine but we need the ability to send more than one Button signal to the same motor.


Quote 0 0
Try the SWITCH block in the Utilities group of the VEX library. It will act like the IF-THEN-ELSE.  
The middle wire is the value being checked by the IF {condition},
the top wire is the result if {condition} is TRUE and
the bottom wire is the result passed if {condition} is FALSE


Study this and you'll see how to implement the nested IF-THEN-ELSE as well.

Try adding a "Latch" block to the control wire (i.e., the IF {condition}) and see what else happens. 
Quote 0 0
As gyoung mentioned, a combination of the Switch blocks (2 in this case) could be used to design an IF-ELSE IF-ELSE condition routine. 

You could also consider using the MATLAB Function block (in the Utilities library) for designing a condition-based routine. The code to be included in the MATLAb Fcn block  would look something like this:

y = fcn(up, down)

if up == 1

y = -10;

elseif dn ==1

y = -127;


y = 0;


You will see 2 input (up, down) and 1 output (y) ports to the MATLAb Fcn block after you include this code. Connect these ports appropriately to your other blocks in the model. 

Hope that helps.

Quote 0 0
Thank you for your suggestions.  I think I am on the right path but I am still not quite there yet. 
I have attached examples of the "code" I have implemented.  
When pressing Channel 6 down button, 10 and -10 are passed through as I expect. 
However, when I press Channel 6 Up button, 127 nor -127 are passed through, I get a zero and -zero response. I believe I have the logic correct but something is definitely not working. Could you review the screen shots and point out my errors or point me in the right direction? 
Thank you. If Else - 10.jpg  If Else - 127.jpg 
Quote 0 0
The use if if the Switch block is not accurate in your a Simulink model. The second input port for the switch blocks are the IF condition checks- which means you need to wire the button blocks to these ports. In your case, they are left unconnected. When you connect the button value to this port, the Switch block will use this value I.e. 1 (button pressed) or 0 (button not pressed), to make decisions whether to pass what is connected to first port (if value 1) else the third port (if value 0). The criteria for Switch in this case needs to be set to U2 > 0. If you need more explanation on this let me know. Also, do go through the documentation for the Switch block to understand it better and review examples. Hoot this helps. Sh
Quote 0 0

Below is a sample of what you are looking for using Switch blocks and also 'Add blocks'. The Add blocks allow combining signals from the two buttons and send them as one value to the servo. That way wither it is 10 deg or 60 deg at a given point of time. Note that, however, if you press both buttons at the same time you will get the summation value (unexpected behavior), so avoid doing that.

Quote 0 0