Full Code: https://github.com/Team-2502/ezAuton
package com.team2502.ezauton.actuators;
/**
* A motor. Takes in an input and runs the motor.
*/
public interface IMotor
{
}
package com.team2502.ezauton.actuators;
/**
* A motor which can be run at a certain velocity
*/
public interface IVelocityMotor extends IMotor
{
void runVelocity(double velocity);
}
package com.team2502.ezauton.actuators;
/**
* A motor which can be run at a certain voltage
*/
public interface IVoltageMotor extends IMotor
{
void runVoltage(double voltage);
}
package com.team2502.ezauton.localization.sensors;
/**
* A sensor which can record revolutions/s and revolutions as a distance
*/
public interface IEncoder extends ITachometer
{
/**
* @return revolutions
*/
double getPosition();
}
package com.team2502.ezauton.localization.sensors;
/**
* A sensor which can measure revolutions / s
*/
public interface ITachometer extends ISensor
{
/**
* @return revolutions / s
*/
double getVelocity();
}
- right now all
IMotor
subclasses (implementations of interfacesIVelocityMotor
,IVoltageMotor
) are basically maps of(input -> action)
(they are effectively interfaces which act as setters for a motor). - As I am further decoupling logic, I am making a group of
SimulationEncoders ⊆ IEncoder
which can be useful for...- simulations
- fake encoders (i.e. if someone is using voltage drive without encoders but still wants to be able to estimate position)
- The problem is how to link the group of implemented
SimulationEncoders
toIMotor
implementations.- I could possibly have
SimulatedEncoder1(ITachometer)
andSimulatedEncoder2(IVoltmeter)
forIVelocityMotor
andIVoltageMotor
, respectively.SimulatedEncoder
s would implement an interfaceUpdateable
and be called every x seconds to readITachometer
andIVoltometer
inputs. The problem with this is it is clunky and theSimulatedEncoder
s might work better knowing every time a method ofIMotor
is called instead of periodically checking the last call. - I could use the Observer pattern to add
SimulationEncoder
s which listen to setVelocity(...), setVoltage(...) - I could try to couple these into one class which acts as a wrapper and forwards velocity/voltage to a
SimulatedEncoder
and anIVelocityMotor
/IVoltageMotor
... the problem with this is I don't see any easy way to link specific types ofSimulatedEncoder
s to their respective type of motor.
- I could possibly have
Any help resolving this dilemma would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire