Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

problem outputting serial commands via simulink

dbhellmithdbhellmith Posts: 14Member
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

Comments

  • giuggiug Posts: 217Member
    How do you do it in matlab code?
  • dbhellmithdbhellmith Posts: 14Member
    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
  • giuggiug Posts: 217Member
    I don't know if it could be the same but try to see the block [u]to instrument[/u].

    Let me know.
  • dbhellmithdbhellmith Posts: 14Member
    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.
  • giuggiug Posts: 217Member
  • dbhellmithdbhellmith Posts: 14Member
    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.
  • giuggiug Posts: 217Member
    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.

  • dbhellmithdbhellmith Posts: 14Member
    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.
  • henryb12henryb12 Posts: 2Member
    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.
  • henryb12henryb12 Posts: 2Member
    can anyone help steer me on the right direction?
Sign In or Register to comment.