Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation

by

 

06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

tharbprobjwriteprofileconfig(tharBPRObj, profileName, kp, ki, kd, maxOut, profile)
function tharbprobjwriteprofileconfig(tharBPRObj, profileName, kp, ki, kd, maxOut, profile)
% THARBPROBJWRITEPROFILECONFIG writes a full profile config to a Thar BPR
% tharbprobjwriteprofileconfig(tharBPRObj, profileName, kp, ki, kd, maxOut,
% profile) writes the name, kp, ki, kd and maxOut (PID constants) to a Thar
% BPR. tharBPRObj is the BPR serial object (generated by tharbproj), and
% profile is either 'A' or 'B'.  If the profile is not supplied, the
% current profile is written to.  The profileName is a string, kp, ki and
% kd are integers from 0-1000, and maxOut is an integer from 0 to 30000.


% first pass error handling - only checks the arguments if they are not
% empty - if they are empty, those values will not be entered later -
% num2str([]) returns '' - which is exactly what we want
if nargin < 6
    % errors
    error('Insufficient arguments')
elseif ~isempty(profileName) && (~ischar(profileName) || isempty(profileName) || length(profileName) > 7 || any(profileName > 126) || any(profileName < 32))
    % errors
    error('profileName must be a string no longer than 7 characters only using printable characters with ASCII codes less than 127.')
elseif ~isempty(kp) && (~isnumeric(kp) || ~isscalar(kp) || isnan(kp) || ~isreal(kp) || kp < 0 || kp > 300)
    % errors
    error('kp must be a scalar integer between 0 and 300.')
elseif ~isempty(ki) && (~isnumeric(ki) || ~isscalar(ki) || isnan(ki) || ~isreal(ki) || ki < 0 || ki > 1000)
    % errors
    error('ki must be a scalar integer between 0 and 1000.')
elseif ~isempty(kd) && (~isnumeric(kd) || ~isscalar(kd) || isnan(kd) || ~isreal(kd) || kd < 0 || kd > 1000)
    % errors
    error('kd must be a scalar integer between 0 and 1000.')
elseif ~isempty(maxOut) && (~isnumeric(maxOut) || ~isscalar(maxOut) || isnan(maxOut) || ~isreal(maxOut) || maxOut < 0 || maxOut > 30000)
    % errors
    error('maxOut must be a scalar integer between 0 and 30000.')
end

% if profile wasn't defined, fetch the current one, otherwise, error check
% the supplied profile
if nargin < 7
    % gets the current profile
    profile = tharbprobjreadcurrentprofile(tharBPRObj);
elseif numel(profile) ~= 1 || ~any(strcmp(profile, {'A', 'B'}))
    % errors
    error('Profile must be either A or B.')
else
    % navigates to the display menu
    tharbprobjdisplaymenu(tharBPRObj);
end

% rounds the kp
roundkp = round(kp);

% checks the kp
if kp ~= roundkp
    % rounds the number
    kp = roundkp;
    
    % display a warning
    warning('TharBPRWriteProfileConfig:ValueTooPrecise', 'Supplied Kp was not an integer so has been rounded off.')
end

% rounds the ki
roundki = round(ki);

% checks the ki
if ki ~= roundki
    % rounds the number
    ki = roundki;
    
    % display a warning
    warning('TharBPRWriteProfileConfig:ValueTooPrecise', 'Supplied Ki was not an integer so has been rounded off.')
end

% rounds the kd
roundkd = round(kd);

% checks the kd
if kd ~= roundkd
    % rounds the number
    kd = roundkd;
    
    % display a warning
    warning('TharBPRWriteProfileConfig:ValueTooPrecise', 'Supplied Kd was not an integer so has been rounded off.')
end

% rounds the maxOut
roundMaxOut = round(maxOut);

% checks the maxOut
if maxOut ~= roundMaxOut
    % rounds the number
    maxOut = roundMaxOut;
    
    % display a warning
    warning('TharBPRWriteProfileConfig:ValueTooPrecise', 'Supplied maxOut was not an integer so has been rounded off.')
end

% sends all the values (this could take some time)
tharbprobjcomm('writesave', tharBPRObj, [char(21), profile, profileName, char(13), num2str(kp), char(13), num2str(ki), char(13), num2str(kd), char(13), num2str(maxOut), char(13), 'Y'])

Contact us