накидал такую рыбу:
(для блок-схемы заюзался софт,имитирующий рисование от руки,притом - наверно стояла галка "исп.левую руку")) -----------------------
так как не оказалось под рукой железного mpg , его работу делал pyvcp-виджет...
https://www.youtube.com/watch?v=KciNb_e ... e=youtu.be
=================
пока не рассчитывается единичный шаг(его длина) - (выставлено константно)...
по идее должно-будет вычисляться от величины подачи (если медленно крутишь) ,и от скорости вращения штурвала(если быстро крутишь)
------------
компонент mpg_go смотрит - крутим ли мы штурвал и если крутим,то в какую сторону...
Код: Выделить всё
/* sudo halcompile --install mpg_go.comp */
component mpg_go ;
pin in float in;
pin out float out;
pin out bit tick; //true if we have a change in couns
variable double old;
function _;
license "GPL";
;;
#include "rtapi_math.h"
FUNCTION(_) {
double tmp = in;
if(!out) out = 1;
if(tmp != old) tick = 1;
else tick = 0;
if(tmp == old) return;
if(tmp < old) out = -1.0;
else out = 1.0;
old = tmp;
}
Код: Выделить всё
/* sudo halcompile --install demux2.comp */
component demux2 "A demultiplexer to select from one of two outputs to connect to the input";
description " This component allows you to connect a single input to one of several outputs. \
This version will connect only one of two outputs." ;
author "Marius D. Liebenberg";
//option singleton yes;
//option default_count = 1;
//option userspace yes;
// Input Pins
pin in float in0 "Any float input value";
pin in bit sel "If HIGH the out1 will be connect to in0, else the out 0 will be connected ";
// Output Pins
pin out float out0 "Follows the value of in0 if sel is FALSE";
pin out float out1 "Follows the value of in0 if sel is TRUE";
// Parameters
// Global Variables
function _;
license "GPL";
;;
#include "rtapi_math.h"
FUNCTION(_) {
if(sel) out1 = in0;
else out0 = in0;
}
Код: Выделить всё
####################################### MPG_go
loadrt mpg_go
addf mpg-go.0 servo-thread
loadrt demux2
addf demux2.0 servo-thread
loadrt oneshot
addf oneshot.0 servo-thread
loadrt timedelay count=1
addf timedelay.0 servo-thread
loadrt mux2 count=2
addf mux2.0 servo-thread
addf mux2.1 servo-thread
loadrt mult2 count=1
addf mult2.0 servo-thread
net mxout mult2.0.in0 mux2.0.out
net mgo mult2.0.in1 mpg-go.0.out
`
net oout oneshot.0.out timedelay.0.in
setp oneshot.0.width 0.01
net slon oneshot.0.in mpg-go.0.tick
setp mux2.0.in0 0
setp mux2.0.in1 1
net mx1 mux2.1.in1 mult2.0.out
setp mux2.1.in0 1
setp timedelay.0.on-delay 0.001
setp timedelay.0.off-delay 0
net lon timedelay.0.out mux2.0.sel
net aset mux2.1.out motion.adaptive-feed
Код: Выделить всё
net md pyvcp.mode-button demux2.0.sel mux2.1.sel
net dm demux2.0.out1 mpg-go.0.in
net wl demux2.0.in0 pyvcp.wheel