Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
Add drivers: Firgelli L12 50/100 Motor
Browse files Browse the repository at this point in the history
  • Loading branch information
mob41 committed Sep 5, 2016
1 parent cc8cd63 commit d99bc89
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 833 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/ev3dev/hardware/Device.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Device(String className){
* Create a new device with a <b>LegoPort</b>, <b>ClassName</b>, <b>classNamePrefix</b>
* @param port A LegoPort delared before.
* @param className Sysfs class name
* @param classNamePrefix The filename inside the "Sysfs class" (I called it sub-class)
* @param classNamePrefix The filename prefix inside the "Sysfs class" (e.g. motor[n], which "motor" is the prefix)
* @throws IOException If I/O goes wrong
*/
public Device(LegoPort port, String className, String classNamePrefix) throws IOException{
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/org/ev3dev/hardware/motors/FirgelliL12100Motor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.ev3dev.hardware.motors;

import java.io.IOException;

import org.ev3dev.exception.InvalidPortException;
import org.ev3dev.hardware.ports.LegoPort;

public class FirgelliL12100Motor extends Motor {

/**
* The Sysfs class's <code>count_per_m</code> property name
*/
public static final String SYSFS_PROPERTY_COUNT_PER_M = "count_per_m";

/**
* The Sysfs class's <code>full_travel_count</code> property name
*/
public static final String SYSFS_PROPERTY_FULL_TRAVEL_COUNT = "full_travel_count";

/**
* This Sysfs's class name prefix (e.g. <code>/sys/class/lego-sensor/sensor0</code>, and <code>sensor</code> is the class name prefix without the [N] value.)
*/
public static final String LINEAR_MOTOR_CLASS_NAME_PREFIX = "linear";

/**
* The driver name for the L12 EV3 100mm by Actuonix
*/
public static final String DRIVER_NAME_100MM = "act-l12-ev3-100";

public FirgelliL12100Motor(int portField) throws InvalidPortException, IOException {
this(new LegoPort(portField));
}

public FirgelliL12100Motor(LegoPort port) throws InvalidPortException, IOException {
super(port, LINEAR_MOTOR_CLASS_NAME_PREFIX);
if (!port.getDriverName().equals(DRIVER_NAME_100MM)){
throw new InvalidPortException("The port does not connect to a Firgelli L12 100 Motor");
}
}

/**
* Do not use this on Firgelli L12 50/100 Motors (Linear motors).<br>
* <code>-1</code> will be returned instead, use <code>getCountPerMetre()</code>
*/
@Override
public int getCountPerRot() throws IOException{
return -1;
}

/**
* Returns the number of tacho counts in one meter of travel of the motor.
* Tacho counts are used by the position and speed attributes, so you can
* use this value to convert from distance to tacho counts. (linear motors only)
* @return Counts per metre
* @throws IOException If I/O goes wrong
*/
public int getCountPerMetre() throws IOException{
if (!this.isConnected()){
return -1;
}
String countpermetre = this.getAttribute(SYSFS_PROPERTY_COUNT_PER_M);
return Integer.parseInt(countpermetre);
}

/**
* Returns the number of tacho counts in the full travel of the motor.
* When combined with the count_per_m attribute, you can use this value
* to calculate the maximum travel distance of the motor.
* (linear motors only)
* @return Full Travel Count
* @throws IOException
*/
public int getFullTravelCount() throws IOException{
if (!this.isConnected()){
return -1;
}
String str = this.getAttribute(SYSFS_PROPERTY_FULL_TRAVEL_COUNT);
return Integer.parseInt(str);
}

}
81 changes: 81 additions & 0 deletions src/main/java/org/ev3dev/hardware/motors/FirgelliL1250Motor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.ev3dev.hardware.motors;

import java.io.IOException;

import org.ev3dev.exception.InvalidPortException;
import org.ev3dev.hardware.ports.LegoPort;

public class FirgelliL1250Motor extends Motor {

/**
* The Sysfs class's <code>count_per_m</code> property name
*/
public static final String SYSFS_PROPERTY_COUNT_PER_M = "count_per_m";

/**
* The Sysfs class's <code>full_travel_count</code> property name
*/
public static final String SYSFS_PROPERTY_FULL_TRAVEL_COUNT = "full_travel_count";

/**
* This Sysfs's class name prefix (e.g. <code>/sys/class/lego-sensor/sensor0</code>, and <code>sensor</code> is the class name prefix without the [N] value.)
*/
public static final String LINEAR_MOTOR_CLASS_NAME_PREFIX = "linear";

/**
* The driver name for the L12 EV3 50mm by Actuonix
*/
public static final String DRIVER_NAME_50MM = "act-l12-ev3-50";

public FirgelliL1250Motor(int portField) throws InvalidPortException, IOException {
this(new LegoPort(portField));
}

public FirgelliL1250Motor(LegoPort port) throws InvalidPortException, IOException {
super(port, LINEAR_MOTOR_CLASS_NAME_PREFIX);
if (!port.getDriverName().equals(DRIVER_NAME_50MM)){
throw new InvalidPortException("The port does not connect to a Firgelli L12 50 Motor");
}
}

/**
* Do not use this on Firgelli L12 50/100 Motors (Linear motors).<br>
* <code>-1</code> will be returned instead, use <code>getCountPerMetre()</code>
*/
@Override
public int getCountPerRot() throws IOException{
return -1;
}

/**
* Returns the number of tacho counts in one meter of travel of the motor.
* Tacho counts are used by the position and speed attributes, so you can
* use this value to convert from distance to tacho counts. (linear motors only)
* @return Counts per metre
* @throws IOException If I/O goes wrong
*/
public int getCountPerMetre() throws IOException{
if (!this.isConnected()){
return -1;
}
String countpermetre = this.getAttribute(SYSFS_PROPERTY_COUNT_PER_M);
return Integer.parseInt(countpermetre);
}

/**
* Returns the number of tacho counts in the full travel of the motor.
* When combined with the count_per_m attribute, you can use this value
* to calculate the maximum travel distance of the motor.
* (linear motors only)
* @return Full Travel Count
* @throws IOException
*/
public int getFullTravelCount() throws IOException{
if (!this.isConnected()){
return -1;
}
String str = this.getAttribute(SYSFS_PROPERTY_FULL_TRAVEL_COUNT);
return Integer.parseInt(str);
}

}

0 comments on commit d99bc89

Please sign in to comment.