Example #1
0
// Runs the motor at the given port.
// The meaning of `speed` parameter depends on whether the regulation mode is turned on or off.
//
// When the regulation mode is off (by default) `speed` ranges from -100 to 100 and
// it's absolute value indicates the percent of motor's power usage. It can be roughly interpreted as
// a motor speed, but deepending on the environment, the actual speed of the motor
// may be lower than the target speed.
//
// When the regulation mode is on (has to be enabled by EnableRegulationMode function) the motor
// driver attempts to keep the motor speed at the `speed` value you've specified
// which ranges from about -1000 to 1000. The actual range depends on the type of the motor - see ev3dev docs.
//
// Negative values indicate reverse motion regardless of the regulation mode.
func (self Motor) Run(speed int16) {
	regulationMode := utilities.ReadStringValue(self.folder, regulationModeFD)

	switch regulationMode {
	case "on":
		utilities.WriteIntValue(self.folder, speedSetterFD, int64(speed))
		utilities.WriteStringValue(self.folder, runFD, "run-forever")
	case "off":
		if speed > 100 || speed < -100 {
			log.Fatal("The speed must be in range [-100, 100]")
		}
		utilities.WriteIntValue(self.folder, powerSetterFD, int64(speed))
		utilities.WriteStringValue(self.folder, runFD, "run-forever")
	}
}
Example #2
0
// Reads the proximity value (in range 0 - 100) reported by the infrared sensor. A value of 100 corresponds to a range of approximately 70 cm.
func (self *InfraredSensor) ReadProximity() uint8 {

	utilities.WriteStringValue(self.path, "mode", "IR-PROX")
	value := utilities.ReadUInt8Value(self.path, "value0")

	return value
}
Example #3
0
func (self *InfraredSensor) ReadIRSEEK(channel int16) (int16, int16) {

	var channel1 string
	var channel2 string

	switch channel {
	case 1:
		channel1 = "value0"
		channel2 = "value1"
	case 2:
		channel1 = "value2"
		channel2 = "value3"
	case 3:
		channel1 = "value4"
		channel2 = "value5"
	case 4:
		channel1 = "value6"
		channel2 = "value7"
	}
	utilities.WriteStringValue(self.path, "mode", "IR-SEEK")
	heading := utilities.ReadInt16Value(self.path, channel1)
	distance := utilities.ReadInt16Value(self.path, channel2)
	return heading, distance
}
Example #4
0
// Reads the ambient light intensity in range [0, 100].
func (self *ColorSensor) ReadAmbientLightIntensity() uint8 {
	utilities.WriteStringValue(self.path, "mode", "COL-AMBIENT")
	value := utilities.ReadUInt8Value(self.path, "value0")

	return value
}
Example #5
0
// Reads the reflected light intensity in range [0, 100].
func (self *ColorSensor) ReadReflectedLightIntensity() uint8 {
	utilities.WriteStringValue(self.path, "mode", "COL-REFLECT")
	value := utilities.ReadUInt8Value(self.path, "value0")

	return value
}
Example #6
0
// Reads one of seven color values.
func (self *ColorSensor) ReadColor() Color {
	utilities.WriteStringValue(self.path, "mode", "COL-COLOR")
	value := utilities.ReadUInt8Value(self.path, "value0")

	return Color(value)
}
Example #7
0
// Disables brake mode, causing the motor at the given port to coast to stops. Brake mode is off by default.
func (self Motor) DisableBrakeMode() {
	utilities.WriteStringValue(self.folder, stopModeFD, "coast")
}
Example #8
0
// Enables brake mode, causing the motor at the given port to brake to stops.
func (self Motor) EnableBrakeMode() {
	utilities.WriteStringValue(self.folder, stopModeFD, "brake")
}
Example #9
0
// Disables regulation mode. Regulation mode is off by default.
func (self Motor) DisableRegulationMode(port OutPort) {
	utilities.WriteStringValue(findFolder(port), regulationModeFD, "off")
}
Example #10
0
// Enables regulation mode, causing the motor at the given port to compensate
// for any resistance and maintain its target speed.
func (self Motor) EnableRegulationMode() {
	utilities.WriteStringValue(self.folder, regulationModeFD, "on")
}
Example #11
0
// Stops the motor at the given port.
func (self Motor) Stop() {
	utilities.WriteStringValue(self.folder, runFD, "stop")
}
Example #12
0
func (self Motor) Turn(command string, data int64) {
	utilities.WriteIntValue(self.folder, powerSetterFD, 50)
	utilities.WriteIntValue(self.folder, "position_sp", data)
	utilities.WriteStringValue(self.folder, runFD, command)
}
Example #13
0
func (self *InfraredSensor) WriteMode(mode string) {
	utilities.WriteStringValue(self.path, "mode", mode)
}
Example #14
0
// Turns on the remote control mode.
func (self *InfraredSensor) RemoteModeOn() {
	utilities.WriteStringValue(self.path, "mode", "IR-REMOTE")
}