motorcontroldemo_028/Vsrc/V_MBVarsConvert.c
2019-07-29 08:18:57 +03:00

136 lines
4.8 KiB
C

/*!
Copyright 2017 ÀÎ "ÍÈÈÝÒ" è ÎÎÎ "ÍÏÔ ÂÅÊÒÎÐ"
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
\file v_MBVarsConv.c
\brief Ìîäóëü ïðåîáðàçîâàíèÿ äàííûõ Modbus
\author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru
\version v.1.1. 02/03/2017
\addtogroup v_ModBus */
/*@{*/
#include "main.h"
#include "mbod.h"
#include "math.h" //äëÿ fabs
//! Èíèöèàëèçàöèÿ íå òðåáóåòñÿ
//! \memberof TMBVarsConv
void MBVarsConv_init(TMBVarsConv *p) {
}
//! Îñíîâíàÿ ïðîöåäóðà
//! Âõîä â .input, âûõîä â .output
//! Êðèâàÿ çàäàåòñÿ ìàññèâîì èç NumOfPoints òî÷åê ïî x è ïî y.
//! \memberof TMBVarsConv
void MBVarsConv_calc(TMBVarsConv *p) {
float number, scale, scaled;
long i, index;
if (ModBus.Enabled == 1){ // Åñëè âêëþ÷åí MODBUS
//Äëÿ óìåíüøåíèÿ âû÷èñëèòåëüíîé íàãðóçêè â ñëó÷àå íåîáõîäèìîñòè ìîæíî óáðàòü öèêë for è ïðîâåðÿòü ïî îäíîìó ýëåìåíòó çà îäèí çàõîä
for (i = 0; i < ModBus.MBInternals.NumOfHRs; i++)// Ïðîâåðÿåì âñå ýëåìåíòû ñëîâàðÿ HR (ðåäàêòèðóåìûõ ïàðàìåòðîâ)
if (mbodHR[i].type_or_acc == 1){// Åñëè ïàðàìåòð ìåíÿëñÿ, òî àíàëèçèðóåì, êàê åãî ïðåîáðàçîâàòü
mbodHR[i].type_or_acc = 0; // Ñáðàñûâàåì ôëàã èçìåíåíèÿ ïàðàìåòðà
index = mbodHR[i].index; //êàêîé èíäåêñ ìåíÿëè
if ((index != 2000) && (index != 2001)) //åñëè íå 2000 è íå 2001, òî íóæíî ñîõðàíèòü ïàðàìåòðû
p->NeedForSave = 1;//Íóæíî íå çëîóïîòðåáëÿòü ýòîé êîìàíäîé, èíà÷å âñÿ ïîëüçîâàòåëüñêàÿ ïàìÿòü ñîòðåòñÿ äî äûð!
//Â çàâèñèìîñòè îò òîãî, êàêîé èíäåêñ ñëîâàðÿ ïîìåíÿëñÿ, âûïîëíÿåì íóæíîå ïðåîáðàçîâàíèå.
//Íà êàæäóþ ïðîâåðêó èíäåêñà òðàòèòñÿ 3 òàêòà. Åñëè ïðîâåðîê áóäåò î÷åíü ìíîãî,
//òî ëîãè÷íî äîïîëíèòü äðàéâåð ôóíêöèÿìè îáðàòíîãî âûçîâà ïðè îáðàùåíèè ê ïàðàìåòðó
switch (index){
case 2000://ñëîâî óïðàâëåíèÿ
//åñëè çíà÷åíèå ïîëÿ êîìàíäà èçìåíèëîñü ïî ñðàâíåíèþ ñ ïðåäûäóùèì
if (p->Vars.Command!=p->Vars.CommandPrev){
if (p->Vars.Command & (1<<0))//êîìàíäà íà çàïóñê
cmd.bit.start = 1;
if (p->Vars.Command & (1<<1))//êîìàíäà íà îñòàíîâ
cmd.bit.stop = 1;
if (p->Vars.Command & (1<<2))//êîìàíäà íà ñáðîñ àâàðèè
cmd.bit.trip_reset = 1;
}
p->Vars.CommandPrev=p->Vars.Command;
break;
case 2001: // òåêóùàÿ ÷àñòîòà âðàùåíèÿ
number = (float) p->Vars.speed_ref;
number = fabs(number);
scale = (float) co1_vars.co_scaleNum14; // ×àñòîòà âðàùåíèÿ (îá/ìèí) 16.0
scaled = number / scale;
refs.speed_ref = _IQ(scaled);
break;
case 43116: //íàïðÿæåíèå çàùèòû â âîëüòàõ
number = (float) MBVarsConv.Vars.Umax_protect;
scale = (float) co1_vars.co_scaleNum7; //íàïðÿæåíèå ÇÏÒ áàçîâîå
scaled = number / scale;
sm_prot.Umax_protect = _IQ(scaled);
break;
}
}
}
// Äëÿ íàáëþäàåìûõ ïðåîáðàçîâàíèå çàïóñêàåì âñåãäà
// 40002
number = _IQtoF(cur_par.speed);
scale = (float) co1_vars.co_scaleNum14; // ×àñòîòà âðàùåíèÿ (îá/ìèí)
scaled = scale * number;
p->Vars.CurSpeed = scaled;
// 40007
number = _IQtoF(cur_par.Is);
scale = (float) co1_vars.co_scaleNum4; //Òîê ôàçíûé áàçîâûé
scaled = scale * number;
p->Vars.CurIs = scaled;
// 40054
p->Vars.Main_ErrorCode = sm_prot.Main_ErrorCode; //êîä òåêóùåé àâàðèè (ëèñòàåòñÿ, åñëè íåñêîëüêî)
}
void MBVarsConv_slow_calc(TMBVarsConv *p) {
if (p->NeedForSave) {//êîìàíäà íà ñîõðàíåíèå ïàðàìåòðîâ ïðèâîäà ÷åðåç ìîäáàñ
p->NeedForSave = 0;
//ñîõðàíÿåì ïîñðåäñòâîì äðàéâåðà CANopen (âñå åãî ïàðàìåòðû)
//âûçûâàÿ ôóíêöèþ ñîõðàíåíèÿ ñ ðàçíûìè äèàïàçîíàìè, ïåðåáèðàÿ èõ âñå.
co_ODexpositor_paramConservation(&co1_vars, 1, 1);
co_ODexpositor_paramConservation(&co1_vars, 2, 1);
co_ODexpositor_paramConservation(&co1_vars, 3, 1);
co_ODexpositor_paramConservation(&co1_vars, 1, 2);
co_ODexpositor_paramConservation(&co1_vars, 2, 2);
co_ODexpositor_paramConservation(&co1_vars, 3, 2);
co_ODexpositor_paramConservation(&co1_vars, 1, 3);
co_ODexpositor_paramConservation(&co1_vars, 2, 3);
co_ODexpositor_paramConservation(&co1_vars, 3, 3);
co_ODexpositor_paramConservation(&co1_vars, 1, 4);
co_ODexpositor_paramConservation(&co1_vars, 2, 4);
co_ODexpositor_paramConservation(&co1_vars, 3, 4);
co_ODexpositor_paramConservation(&co1_vars, 1, 5);
co_ODexpositor_paramConservation(&co1_vars, 2, 5);
co_ODexpositor_paramConservation(&co1_vars, 3, 5);
}
}
/*@}*/