Ejemplo n.º 1
0
Archivo: leds.go Proyecto: jermon/GoEV3
// Turns off the given LED with the specified color.
func TurnOff(color Color, position Position) {
	if color == Amber {
		utilities.WriteIntValue(findFilename(Green, position), "brightness", 0)
		utilities.WriteIntValue(findFilename(Red, position), "brightness", 0)
	} else {
		utilities.WriteIntValue(findFilename(color, position), "brightness", 0)
	}
}
Ejemplo n.º 2
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")
	}
}
Ejemplo n.º 3
0
// Set the position of the motor at the given port.
func (self Motor) InitializePosition(value int32) {
	utilities.WriteIntValue(self.folder, positionFD, int64(value))
}
Ejemplo n.º 4
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)
}