Esempio n. 1
0
File: gyro.go Progetto: tthk/GoEV3
// 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")
}
Esempio n. 2
0
File: motors.go Progetto: tthk/GoEV3
// 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")
	}
}
Esempio n. 3
0
// 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)
}
Esempio n. 4
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 {
	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
}
Esempio n. 5
0
// 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
}
Esempio n. 6
0
// 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)
}
Esempio n. 7
0
File: gyro.go Progetto: tthk/GoEV3
// 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
}
Esempio n. 8
0
// 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
}
Esempio n. 9
0
// SetStopMode sets the brake mode to ether Coast, Brake or Hold.
func SetStopMode(port OutPort, mode StopMode) {
	utilities.WriteStringValue(findFolder(port), stopModeFD, string(mode))
}
Esempio n. 10
0
// DisableRegulationMode disables regulation mode. Regulation mode is off by default.
func DisableRegulationMode(port OutPort) {
	utilities.WriteStringValue(findFolder(port), regulationModeFD, "off")
}
Esempio n. 11
0
// Stop stops the motor at the given port.
func Stop(port OutPort) {
	utilities.WriteStringValue(findFolder(port), runFD, "stop")
}
Esempio n. 12
0
func run(folder string, speed int16, command RunCommand) {
	setSpeed(folder, speed)
	utilities.WriteStringValue(folder, runFD, string(command))
}
Esempio n. 13
0
File: motors.go Progetto: tthk/GoEV3
// Resets motor
func Reset(port OutPort) {
	folder := findFolder(port)
	utilities.WriteStringValue(folder, runFD, "reset")
}
Esempio n. 14
0
File: motors.go Progetto: tthk/GoEV3
// 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")
}
Esempio n. 15
0
File: motors.go Progetto: tthk/GoEV3
// Enables brake mode, causing the motor at the given port to brake to stops.
func EnableBrakeMode(port OutPort) {
	utilities.WriteStringValue(findFolder(port), stopModeFD, "brake")
}
Esempio n. 16
0
// 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")
}