Commit 82e2def9 authored by Lindenberg, Arthur-Vincent's avatar Lindenberg, Arthur-Vincent
Browse files

built classes for different signal generator waveforms.

built rp_sig_gen function to call the new classes.
built SignalGenerator_example to show how to use it.
parent 38315574
%% alter path to your python (3.8 is tested) distribution here
py_path = 'C:\Users\Arthur-Vincent\AppData\Local\Programs\Python\Python38\python.exe';
broker_ip = '169.254.249.197';
addpath('../../lib');
addpath('../../lib/redpitaya');
myMqtt = mqtt_py_matlab(py_path);
myMqtt.connect_mqtt(broker_ip);
%% Init components
rp_name = "RP1"; % Name of used red pitaya
channel = "CH1"; % Name of used red pitaya channel
%% Waveform Sinus
% sigeSin = SigGenSine(); % get an object of the SigGenSine child class
% SiGeSin_proberty_message = sigeSin.get_mqtt_message_sin; % build mqtt message
%sigeSin.magnitude =0.6; % change magnitude
%sigeSin.frequency = 4000; % change frequency
%rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeSin_proberty_message) % Use Mqtt function to generate signal
% %% Waveform Square
%
% sigeSquare = SigGenSquare(); % Build object of child class SigGenSquare
% sigeSquare.magnitude =0.6; % change magnitude
% sigeSquare.frequency = 3000; % change frequency
% SiGeSquare_proberty_message = sigeSquare.get_mqtt_message_square; % build mqtt message
% rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeSquare_proberty_message) % Use Mqtt function to generate signal
%% Waveform Sawtooth
% sigeSawtooth = SigGenSawtooth(); % Build object of child class SigGenSawtooth
% sigeSawtooth.magnitude =0.7; % change magnitude
% sigeSawtooth.frequency = 2000; % change frequency
% SiGeSawtooth_proberty_message = sigeSawtooth.get_mqtt_message_sawtooth; % build mqtt message
% rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeSawtooth_proberty_message) % Use Mqtt function to generate signal
%% Waveform PWM
sigePWM = SigGenPWM(); % Build object of child class SigGenSquare
sigePWM.magnitude =0.6; % change magnitude
sigePWM.frequency = 3000; % change frequency#
sigePWM.duty_cycle = 0.2; % change duty cicle
SiGeSquare_proberty_message = sigePWM.get_mqtt_message_pwm; % build mqtt message
rp_sig_gen(myMqtt, broker_ip, rp_name, channel, SiGeSquare_proberty_message) % Use Mqtt function to generate signal
classdef SigGenPWM < SigGenProperties
properties
frequency = 1000;
duty_cycle = 0.5;
end
methods
%% Constructor
function obj = SigGenPWM()
obj@SigGenProperties();
%SigGenSquare Construct an instance of this class
end
%% Getter methods
function mqtt_message_sig = get_mqtt_message_pwm(obj)
mqtt_message_append =...
{"/WAVE/PWM", "1";...
"/FREQUENCY", num2str(obj.frequency);...
"/DUTYCYCLE",num2str(obj.duty_cycle)};
mqtt_message = obj.get_mqtt_message;
mqtt_message_sig = [mqtt_message; mqtt_message_append];
end
%% Setter methods
end
end
classdef SigGenProperties
properties
magnitude = 1.0;
offset = 0.0;
phase_deg = 0.0;
burst_cnt = 0;
end
methods
%% Constructor
function obj = SigGenProperties()
%SigGenProperties Construct an instance of this class
end
%% Getter methods
function mqtt_message = get_mqtt_message(obj)
mqtt_message = cell(4,2);
mqtt_message(1,1:2) = {"/AMPLITUDE", num2str(obj.magnitude)};
mqtt_message(2,1:2) = {"/OFFSET", num2str(obj.offset)};
mqtt_message(3,1:2) = {"/PHASE", num2str(obj.phase_deg)};
if obj.burst_cnt > 0
mqtt_message(4,1:2) = {"/BURST", num2str(obj.burst_cnt)};
else
mqtt_message(4,1:2) = {"/CONTINUOUS", num2str(obj.burst_cnt)};
end
end
%% Setter methods
end
end
classdef SigGenSawtooth < SigGenProperties
properties
frequency = 1000;
end
methods
%% Constructor
function obj = SigGenSawtooth()
obj@SigGenProperties();
%SigGenSquare Construct an instance of this class
end
%% Getter methods
function mqtt_message_sig = get_mqtt_message_sawtooth(obj)
mqtt_message_append =...
{"/WAVE/SAWTOOTH", "1";...
"/FREQUENCY", num2str(obj.frequency)};
mqtt_message = obj.get_mqtt_message;
mqtt_message_sig = [mqtt_message; mqtt_message_append];
end
%% Setter methods
end
end
classdef SigGenSine < SigGenProperties
properties
frequency = 1000;
end
methods
%% Constructor
function obj = SigGenSine()
obj@SigGenProperties();
%SigGenSine Construct an instance of this class
end
%% Getter methods
function mqtt_message_sig = get_mqtt_message_sin(obj)
mqtt_message_append = {"/WAVE/SINE", "1"; "/FREQUENCY", num2str(obj.frequency)};
mqtt_message = obj.get_mqtt_message;
mqtt_message_sig = [mqtt_message; mqtt_message_append];
end
%% Setter methods
end
end
classdef SigGenSquare < SigGenProperties
properties
frequency = 1000;
end
methods
%% Constructor
function obj = SigGenSquare()
obj@SigGenProperties();
%SigGenSquare Construct an instance of this class
end
%% Getter methods
function mqtt_message_sig = get_mqtt_message_square(obj)
mqtt_message_append =...
{"/WAVE/SQUARE", "1";...
"/FREQUENCY", num2str(obj.frequency)};
mqtt_message = obj.get_mqtt_message;
mqtt_message_sig = [mqtt_message; mqtt_message_append];
end
%% Setter methods
end
end
function rp_sig_gen(mqtt_handler, broker_ip, rp_name, ch, message)
% Init and disable signal generator
mqtt_handler.pub_mqtt(broker_ip, rp_name + "/CONFIGURE/AO/" + ch + "/DISABLE", "1");
mqtt_handler.pub_mqtt(broker_ip, rp_name + "/CONFIGURE/AO/" + ch + "/ENABLE", "1");
mqtt_handler.pub_mqtt(broker_ip, rp_name + "/CONFIGURE/AO/" + ch + "/DISABLE", "1");
% Build signal from message proberty class
len_message = size(message);
len_message_dim1= len_message(1);
for i= 1:len_message_dim1
mqtt_handler.pub_mqtt(broker_ip, rp_name + "/CONFIGURE/AO/" + ch + message(i,1), message(i,2));
end
% Enable signal generator
mqtt_handler.pub_mqtt(broker_ip, rp_name + "/CONFIGURE/AO/" + ch + "/ENABLE", "1");
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment