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