problem outputting serial commands via simulink

from matlab code i was able to send commands to control a motor, but my goal is to do it in simulink or mainly in simulink. any advice would be helpful


  • How do you do it in matlab code?
  • i would ruin the program o n the right first and then the program on the left this would connect the ports. if there are any variables missing i will also post them
  • I don't know if it could be the same but try to see the block [u]to instrument[/u].

    Let me know.
  • when i make the same circuit i receive

    Warning: The model 'untitled' does not have continuous states, hence using the solver 'VariableStepDiscrete'
    instead of solver 'ode45'. You can disable this diagnostic by explicitly specifying a discrete solver in the
    solver tab of the Configuration Parameters dialog, or setting 'Automatic solver parameter selection' diagnostic
    to 'none' in the Diagnostics tab of the Configuration Parameters dialog.
    Warning: Using a default value of 0.2 for maximum step size. The simulation step size will be equal to or
    less than this value. You can disable this diagnostic by setting 'Automatic solver parameter selection'
    diagnostic to 'none' in the Diagnostics page of the configuration parameters dialog.

    and i cant fully understand why. this is the same matlab error in both sends.
  • Have you tried to specify a discrete solver or change the max step size?

  • i have tried both but i am willing to admit that i am not to sure what they do exactly. i may have figured out a way to work around this problem which is to call the function "[u]servoVal(sv,servo,value)[/u]"
    where sv is all of the port information
    servo is the choice of servo 1-8
    and value is the pwm output from 1-255
    the actual function is below

    %port is the variable given to the SV203 connection
    %servo is the servo number you would like to move
    %value is the value you would like the servo to move to

    function servoVal(port,servo,value)

    servo = num2str (servo);
    value = num2str (value);
    transmit = strcat('SV',servo,'M',value);
    fprintf(port, transmit);

    i wish to call this in simulink but when i try to place it into a matlab function block there is only one input and one output. there is no output that simulink can read in this function and there needs to be multiple inputs.
  • Are you using the [u]embedded matlab function[/u] block?
    In this case, your function gives 3 inputs and no output. But it gives no output because you don't specify it in thre function declaration.

    If you want an output the function declaration has to be in this way:

    function y=servoVal(port,servo,value)

    and obviously you have to compute y (or whatever else) into the function.

  • no it did not work unfortunately. instead i have decided to send the commands from simulink into matlab as variables. using (to workspace) but it only updates the values in the variable when i stop the simulink simulation is there a way to constantly update the values. when first using the simulink to output to workspace the variable is not even defined until the program is stopped.
  • not to dig up old forums... but I am having the same exact problem and have not been able to get the MS block to work correctly to control the motor via simulink.
  • can anyone help steer me on the right direction?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!