// Resets the gyro sensor func (self *GyroSensor) Reset() { snr := findSensor(self.port, TypeGyro) path := fmt.Sprintf("%s/%s", baseSensorPath, snr) utilities.WriteStringValue(path, "mode", "GYRO-G&A") utilities.WriteStringValue(path, "mode", "GYRO-ANG") }
// 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 Run(port OutPort, speed int16) { folder := findFolder(port) regulationMode := utilities.ReadStringValue(folder, regulationModeFD) switch regulationMode { case "on": utilities.WriteIntValue(folder, speedSetterFD, int64(speed)) utilities.WriteStringValue(folder, runFD, "run-forever") case "off": if speed > 100 || speed < -100 { log.Fatal("The speed must be in range [-100, 100]") } utilities.WriteIntValue(folder, powerSetterFD, int64(speed)) utilities.WriteStringValue(folder, runFD, "run-forever") } }
// Reads the distance (in centimeters) reported by the ultrasonic sensor. func (self *UltrasonicSensor) ReadDistance() uint16 { snr := findSensor(self.port, TypeUltrasonic) path := fmt.Sprintf("%s/%s", baseSensorPath, snr) utilities.WriteStringValue(path, "mode", "US-SI-CM") value := utilities.ReadUInt16Value(path, "value0") return (value / 10) }
// 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 { snr := findSensor(self.port, TypeInfrared) path := fmt.Sprintf("%s/%s", baseSensorPath, snr) utilities.WriteStringValue(path, "mode", "IR-PROX") value := utilities.ReadUInt8Value(path, "value0") return value }
// Reads the ambient light intensity in range [0, 100]. func (self *ColorSensor) ReadAmbientLightIntensity() uint8 { snr := findSensor(self.port, TypeColor) path := fmt.Sprintf("%s/%s", baseSensorPath, snr) utilities.WriteStringValue(path, "mode", "COL-AMBIENT") value := utilities.ReadUInt8Value(path, "value0") return value }
// Reads one of seven color values. func (self *ColorSensor) ReadColor() Color { snr := findSensor(self.port, TypeColor) path := fmt.Sprintf("%s/%s", baseSensorPath, snr) utilities.WriteStringValue(path, "mode", "COL-COLOR") value := utilities.ReadUInt8Value(path, "value0") return Color(value) }
// Provides access to a gyro sensor at the given port. func FindGyroSensor(port InPort) *GyroSensor { snr := findSensor(port, TypeGyro) s := new(GyroSensor) s.port = port path := fmt.Sprintf("%s/%s", baseSensorPath, snr) utilities.WriteStringValue(path, "mode", "GYRO-ANG") return s }
// Looks for other nearby ultrasonic sensors and returns true if one is found. func (self *UltrasonicSensor) Listen() bool { snr := findSensor(self.port, TypeUltrasonic) path := fmt.Sprintf("%s/%s", baseSensorPath, snr) utilities.WriteStringValue(path, "mode", "US-LISTEN") value := utilities.ReadUInt8Value(path, "value0") if value == 1 { return true } return false }
// SetStopMode sets the brake mode to ether Coast, Brake or Hold. func SetStopMode(port OutPort, mode StopMode) { utilities.WriteStringValue(findFolder(port), stopModeFD, string(mode)) }
// DisableRegulationMode disables regulation mode. Regulation mode is off by default. func DisableRegulationMode(port OutPort) { utilities.WriteStringValue(findFolder(port), regulationModeFD, "off") }
// Stop stops the motor at the given port. func Stop(port OutPort) { utilities.WriteStringValue(findFolder(port), runFD, "stop") }
func run(folder string, speed int16, command RunCommand) { setSpeed(folder, speed) utilities.WriteStringValue(folder, runFD, string(command)) }
// Resets motor func Reset(port OutPort) { folder := findFolder(port) utilities.WriteStringValue(folder, runFD, "reset") }
// Disables brake mode, causing the motor at the given port to coast to stops. Brake mode is off by default. func DisableBrakeMode(port OutPort) { utilities.WriteStringValue(findFolder(port), stopModeFD, "coast") }
// Enables brake mode, causing the motor at the given port to brake to stops. func EnableBrakeMode(port OutPort) { utilities.WriteStringValue(findFolder(port), stopModeFD, "brake") }
// Turns on the remote control mode. func (self *InfraredSensor) RemoteModeOn() { snr := findSensor(self.port, TypeInfrared) path := fmt.Sprintf("%s/%s", baseSensorPath, snr) utilities.WriteStringValue(path, "mode", "IR-REMOTE") }