Регулировка подачи (оборотов) энкодером.

KFlop, KStep, KAnalog, KMotion...
Дмитро
Почётный участник
Почётный участник
Сообщения: 1060
Зарегистрирован: 14 сен 2013, 01:20
Репутация: 1139
Настоящее имя: Дмитрий
Откуда: Киев

Регулировка подачи (оборотов) энкодером.

Сообщение Дмитро »

Еще ни разу не пожалел, что "присел" на kflop :D
Поддерживает очень много функций, сегодня поставил на станок 6М13СН2 Модернизация после модернизации #1 энкодер для регулировки подачи.
И без каких либо танцев :walk: :clap: сразу заработал
Encoder.jpg (8154 просмотра) <a class='original' href='./download/file.php?id=51402&sid=134ca7b3ae90675a6dc3cb1e2b99e9a9&mode=view' target=_blank>Загрузить оригинал (62.54 КБ)</a>
Программу С взял с примеров SetFROwithHWEncoderLog.c
(для просмотра содержимого нажмите на ссылку)

Код: Выделить всё

#include "KMotionDef.h"

// Detects changes in a hardware encoder and raises/lowers the FRO
// accordingly.  Clamp the encoder range so that if the operator
// keeps turning it will only go so far (slip)

#define TMP 10 // which spare persist to use to transfer data
#include "KflopToKMotionCNCFunctions.c"

#define ENCODER_AXIS 4
#define ALLOWED_ENC_RANGE 100 // limit the encoder to this range
#define CHANGE_TOL 1.0  // only update if encoder change is more than this
#define CHANGE_TIME 0.05  // don't update more often then this time
#define FRO_MIN 0.1
#define FRO_MAX 2.0

// solve for mapping relationship between encoder and FRO
// assume the linear relationship (form y=ax+b)
// Determine the a and b values that will map encoder of Zero
// to the minimum desired FRO, and the ALLOWED_ENC_RANGE to the max FRO
// But map encoder to the log of the FRO so it changes exponentially
// 
//
// FRO = a * Encoder + b
//
// Given:  when Encoder = 0                   => FRO = FRO_MIN
//              Encoder = ALLOWED_ENC_RANGE   => FRO = FRO_MAX
//
// b = FRO_MIN
// 
// FRO_MAX = a * ALLOWED_ENC_RANGE + FRO_MIN
// a = (FRO_MAX - FRO_MIN)/ALLOWED_ENC_RANGE
//
// determine Encoder value where FRO = 1.0
//
// 1.0 = a * Encoder + b
// Encoder =  (1.0 - b)/a
//
 
double LastFRO=-1;
double LastFROTime=0;
double LastEncoder=0;
double LastUpdateEncoder=1e30;  // force immediate update
double Encoder;

main()
{
	double Pot,T,FRO;
	CHAN *ch=&chan[ENCODER_AXIS];
	double a = (log(FRO_MAX) - log(FRO_MIN))/ALLOWED_ENC_RANGE;
	double b = log(FRO_MIN);


	// Initialize the encoder to give FRO of 1.0
	
	Encoder = (log(1.0) - b)/a;
	
	LastEncoder = ch->Position;
	
	for (;;)
	{
		T = WaitNextTimeSlice();

		Encoder += (ch->Position - LastEncoder);   // accumulate changes
		LastEncoder = ch->Position;
		

		// send message to KMotionCNC if the pot changed significantly
		// and it has been a while since the last message
		if ((Encoder > LastUpdateEncoder+CHANGE_TOL || Encoder < LastUpdateEncoder-CHANGE_TOL) && 
			T > LastFROTime+CHANGE_TIME)
		{
			// limit the Range
			if (Encoder > ALLOWED_ENC_RANGE) Encoder = ALLOWED_ENC_RANGE;
			if (Encoder < 0) Encoder = 0;

			// map the encoder range to the desired FRO range
			FRO = exp(a * Encoder + b);
			if (FRO > FRO_MAX) FRO=FRO_MAX;
			if (FRO < FRO_MIN) FRO=FRO_MIN;

			DoPCFloat(PC_COMM_SET_FRO,FRO);
			LastUpdateEncoder=Encoder;
			LastFROTime=T;
		}
	}
}
Аватара пользователя
Nick
Мастер
Сообщения: 22776
Зарегистрирован: 23 ноя 2009, 16:45
Репутация: 1735
Заслуга: Developer
Откуда: Gatchina, Saint-Petersburg distr., Russia
Контактная информация:

Re: Регулировка подачи (оборотов) энкодером.

Сообщение Nick »

Demetrius писал(а):Программу С взял с примеров SetFROwithHWEncoderLog.c
В linuxcnc для этого надо в hal дописать:

Код: Выделить всё

setp halui.feed-override.direct-value false
setp halui.feed-override.scale .01
net fo-count => halui.feed-override.counts
+ стандартная настройка энкодера.
(отсюда) http://linuxcnc.org/index.php/english/f ... -overrides
Anton_S
Новичок
Сообщения: 15
Зарегистрирован: 28 май 2017, 12:08
Репутация: 0
Настоящее имя: Антон
Откуда: Самара
Контактная информация:

Re: Регулировка подачи (оборотов) энкодером.

Сообщение Anton_S »

Подскажите не очень опытному пользователю .
Выходы D1-D2 подключать к Kflop или Kanalog?
Ответить

Вернуться в «KFlop»