BEST Robotics Forum
Register Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
widerbestrobot

Junior Member
Registered:
Posts: 23
Reply with quote  #1 
Just curios as to why there is a %#codegen at the start of every Matlab function block, and what the point of having the %i.e. u = 4 at the end of the code in the ladder block tread.

If I understand the code properly the %i.e. u = 4 was just for clarification, but my real question is why does Simulink put the %#codegen in all the Matlab function blocks.
0
shiremath

Moderator
Registered:
Posts: 78
Reply with quote  #2 
Great question!

In the MATLAb Function block, %#codegen is what we call a Compilation Directive. It is added to indicate that this MATLAB function is going to go through C-code generation when you hit the 'Deploy to Hardware' button.

For more info on this, see here:
 http://www.mathworks.com/help/simulink/ug/adding-the-compilation-directive-codegen.html

Typically, every MATLAb Function blocks added to a Simulink has this by default. When working with the VEX hardware, make sure to leave this directive as such so that it doesn't affect to 'Deploy to Hardware' behavior later. Do not modify this line!

As for the "%" symbol in MATLAB, this is used to add 'comments' to your code. So yes, in the ladder example, "%i.e. u =4" was a comment that I had added to clarify what that line of code does. Comments have no affect on the function/execution of the code itself. They are merely added for documentation/notation purposes. (In C, you would use // for adding comments)

Example 
Code:
a = 10;  %Adding comment that a is a variable that is assigned a value of 10
b =a +1; %Increment a by 1 and assign it to b



-SH
0
widerbestrobot

Junior Member
Registered:
Posts: 23
Reply with quote  #3 
So your saying i should add back my %#codegen back into all my function blocks?
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.