示例#1
0
文件: motors.go 项目: jermon/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 (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")
	}
}
示例#2
0
文件: infrared.go 项目: jermon/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 {

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

	return value
}
示例#3
0
文件: infrared.go 项目: jermon/GoEV3
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
}
示例#4
0
文件: color.go 项目: jermon/GoEV3
// 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
}
示例#5
0
文件: color.go 项目: jermon/GoEV3
// 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
}
示例#6
0
文件: color.go 项目: jermon/GoEV3
// 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)
}
示例#7
0
文件: motors.go 项目: jermon/GoEV3
// 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")
}
示例#8
0
文件: motors.go 项目: jermon/GoEV3
// Enables brake mode, causing the motor at the given port to brake to stops.
func (self Motor) EnableBrakeMode() {
	utilities.WriteStringValue(self.folder, stopModeFD, "brake")
}
示例#9
0
文件: motors.go 项目: jermon/GoEV3
// Disables regulation mode. Regulation mode is off by default.
func (self Motor) DisableRegulationMode(port OutPort) {
	utilities.WriteStringValue(findFolder(port), regulationModeFD, "off")
}
示例#10
0
文件: motors.go 项目: jermon/GoEV3
// 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")
}
示例#11
0
文件: motors.go 项目: jermon/GoEV3
// Stops the motor at the given port.
func (self Motor) Stop() {
	utilities.WriteStringValue(self.folder, runFD, "stop")
}
示例#12
0
文件: motors.go 项目: jermon/GoEV3
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)
}
示例#13
0
文件: infrared.go 项目: jermon/GoEV3
func (self *InfraredSensor) WriteMode(mode string) {
	utilities.WriteStringValue(self.path, "mode", mode)
}
示例#14
0
文件: infrared.go 项目: jermon/GoEV3
// Turns on the remote control mode.
func (self *InfraredSensor) RemoteModeOn() {
	utilities.WriteStringValue(self.path, "mode", "IR-REMOTE")
}