All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.neuronrobotics.sdk.dyio.sequencer.ServoOutputScheduleChannel Maven / Gradle / Ivy

The newest version!
package com.neuronrobotics.sdk.dyio.sequencer;

import java.util.ArrayList;

import com.neuronrobotics.sdk.dyio.peripherals.AnalogInputChannel;
import com.neuronrobotics.sdk.dyio.peripherals.IAnalogInputListener;
import com.neuronrobotics.sdk.dyio.peripherals.IServoPositionUpdateListener;
import com.neuronrobotics.sdk.dyio.peripherals.ServoChannel;

// TODO: Auto-generated Javadoc
/**
 * The Class ServoOutputScheduleChannel.
 */
public class ServoOutputScheduleChannel implements ISchedulerListener, IAnalogInputListener {
	
	/** The output. */
	private ServoChannel output;
	
	/** The input. */
	AnalogInputChannel input;
	
	/** The input scale. */
	private double inputScale=.25;
	
	/** The input center. */
	private int inputCenter = 128;
	
	/** The input value. */
	private int inputValue;
	
	/** The recording. */
	private boolean recording=false;
	
	/** The interval. */
	private double interval;
	
	/** The current value. */
	private int currentValue;
	
	/** The data. */
	private ArrayList data = new ArrayList();
	
	/** The output max. */
	private int outputMax=255;
	
	/** The output min. */
	private int outputMin=0;
	
	/** The index. */
	private int index=0;
	
	/** The direct tester. */
	private Tester directTester;
	
	/** The analog input channel number. */
	private int analogInputChannelNumber=8;
	
	/**
	 * Instantiates a new servo output schedule channel.
	 *
	 * @param srv the srv
	 */
	public ServoOutputScheduleChannel(ServoChannel srv) {
		output=srv;
		setCurrentValue(output.getValue());

	}
	
	/**
	 * Gets the channel number.
	 *
	 * @return the channel number
	 */
	public int getChannelNumber(){
		return output.getChannel().getChannelNumber();
	}
	
	/**
	 * Pause recording.
	 */
	public void pauseRecording(){
		System.out.println("pausing recording");
		if(input != null)
			input.removeAnalogInputListener(this);
		setRecording(false);
	}
	
	/**
	 * Resume recording.
	 */
	public void resumeRecording(){
		if(input==null)
			initInput();
		System.out.println("resuming recording");
		setRecording(true);
	}
	
	
	
	/**
	 * Adds the analog input listener.
	 *
	 * @param l the l
	 */
	public void addAnalogInputListener(IAnalogInputListener l){
		input.addAnalogInputListener(l);
		input.setAsync(true);
		input.configAdvancedAsyncNotEqual(10);
	}
	
	/**
	 * Inits the input.
	 */
	private void initInput() {
		if(input==null || (input.getChannel().getChannelNumber() != getAnalogInputChannelNumber())){
			input=new AnalogInputChannel(output.getChannel().getDevice().getChannel(analogInputChannelNumber),true);
		}

		if(input.getChannel().getChannelNumber() != analogInputChannelNumber) {
			System.out.println("Re-Setting analog input channel: "+analogInputChannelNumber);
			input.removeAllAnalogInputListeners();
			input=new AnalogInputChannel(output.getChannel().getDevice().getChannel(analogInputChannelNumber),true);
		}
		addAnalogInputListener(this);
	}
	
	/**
	 * Start recording.
	 */
	public void startRecording(){
		initInput();
		resumeRecording();
	}

	/* (non-Javadoc)
	 * @see com.neuronrobotics.sdk.dyio.sequencer.ISchedulerListener#onTimeUpdate(double)
	 */
	@Override
	public void onTimeUpdate(double ms) {
		index = (int) (ms/getInterval());
		while(index>=data.size()){
			data.add(new MapData(getCurrentValue()));
		}
			
		if(isRecording())
			data.get(index).input=getCurrentTargetValue();
		
		setCurrentValue(data.get(index).input);
		
	
		//output.SetPosition(data.get(index).input);
		//System.out.println("Setting servo "+getChannelNumber()+" value="+getCurrentValue());
	}


	/* (non-Javadoc)
	 * @see com.neuronrobotics.sdk.dyio.sequencer.ISchedulerListener#setIntervalTime(int, int)
	 */
	@Override
	public void setIntervalTime(int msInterval, int totalTime) {
		setInterval(msInterval);
		int slices = totalTime/msInterval;
		if(data.size()==0){
			System.out.println("Setting up sample data: "+msInterval+"ms for: "+totalTime);
			data = new ArrayList();
			setCurrentTargetValue(getCurrentValue());
			if(getCurrentTargetValue()>getOutputMax()){
				setCurrentTargetValue(getOutputMax());
			}
			if(getCurrentTargetValue()\n";
		s+="\t\t"+outputMin+"\n";
		s+="\t\t"+getChannelNumber()+"\n";
		s+="\t\t"+isRecording()+"\n";
		s+="\t\t"+inputScale+"\n";
		s+="\t\t"+inputCenter+"\n";
		s+="\t\t"+getAnalogInputChannelNumber()+"\n";
		s+="\t\t";
		for(int i=0;i();
		for(int i=0;i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy