分类目录归档:EV3DEV

[已解决]win7下使用ev3dev-2015-12-30版本黑屏死机的问题

按照官方关于ev3dev-jessie-2015-12-30版本介绍

There are lots of changes in this release, so even if you are not new to ev3dev check out the Getting Started guide.
这个版本中出现了较大的变化,及时你是一个ev3dev的老玩家最好也看看入门教程。

而在我翻译ev3dev接口文档的过程中,确实发现了许多跟以前不一样的地方。最新版的镜像把之前许多“混乱”的内容进行了整理。因此决定更新到最新版的ev3dev系统。

可就在我安装完镜像,在Windows7也完成了Remote NDIS驱动的安装,当通过ssh远程登录EV3时,系统一片黑屏,死机了。在排除了系统安装问题、USB接口问题、USB线路问题之后,我认为应该是设备驱动出了问题。

而确定这个问题和寻找解决办法的过程异常痛苦,因为关于ev3dev系统使用的搜索内容非常少,而出现这个问题的搜索结果更是没有,更重要的是——每一次尝试都面临着死机、等待、重启。我只能一点一点捋,从设备类型、驱动名称、驱动文件名开始搜索可能的原因。

在这中间我确实放弃了一段时间。

最后终于在升级了的一个文件之后问题得以解决,至少目前为止还没有出现黑屏情况。关于升级的文章链接:https://support.microsoft.com/zh-cn/kb/2719857

ev3dev手册[四]-专用传感器

Special sensor classes/专用传感器类

The classes derive from Sensor and provide helper functions specific to the corresponding sensor type. Each of the functions makes sure the sensor is in the required mode and then returns the specified value.
这些类继承了Sensor,针对相应的传感器类型提供了专门的函数便于使用。所有函数均能够保证所使用的传感器在正确模式下工作,并返回符合规定的值。

Touch Sensor/触碰传感器

class Touch_Sensor/Touch_Sensor

Touch Sensor/触碰传感器

inherits from/父类: sensor

Target driver(s)/目标驱动: lego-ev3-touch, lego-nxt-touch

Special properties/参数

Is_Pressed
boolean, read

A boolean indicating whether the current touch sensor is being pressed.
用于识别触碰传感器是否被按下。

Required mode/模式: TOUCH

Value index/索引值: 0

Color Sensor/颜色传感器

class Color_Sensor/Color_Sensor

LEGO EV3 color sensor.
LEGO EV3 颜色传感器。

inherits from/父类: sensor

Target driver(s)/驱动: lego-ev3-color

ev3dev docs link/ev3dev文档链接: http://www.ev3dev.org/docs/sensors/lego-ev3-color-sensor/

Special properties/参数

Reflected_Light_Intensity
int, read

Reflected light intensity as a percentage. Light on sensor is red.
通过百分比表示反射光强度,此时传感器发出红色光。

Required mode/模式: COL-REFLECT

Value index/索引值: 0

Ambient_Light_Intensity
int, read

Ambient light intensity. Light on sensor is dimly lit blue.
环境光强度。此时传感器发出蓝光。

Required mode/模式: COL-AMBIENT

Value index/索引值: 0

Color
int, read

Color detected by the sensor, categorized by overall value.
传感器所识别的颜色,不同数字表示不同的颜色。

  • 0: No color/无颜色(未识别)
  • 1: Black/黑
  • 2: Blue/蓝
  • 3: Green/绿
  • 4: Yellow/黄
  • 5: Red/红
  • 6: White/白
  • 7: Brown/棕

Required mode/模式: COL-COLOR

Value index/索引值: 0

Red
int, read

Red component of the detected color, in the range 0-1020.
所采集颜色的红色分量,取值范围:0-1020。

Required mode/模式: RGB-RAW

Value index/索引值: 0

Green
int, read

Green component of the detected color, in the range 0-1020.
所采集颜色的绿色分量,取值范围:0-1020。

Required mode/模式: RGB-RAW

Value index/索引值: 1

Blue
int, read

Blue component of the detected color, in the range 0-1020.
所采集颜色的蓝色分量,取值范围:0-1020。

Required mode/模式: RGB-RAW

Value index/索引值: 2

Ultrasonic Sensor/超声波传感器

class Ultrasonic_Sensor/Ultrasonic_Sensor

LEGO EV3 ultrasonic sensor.
LEGO EV3超声波传感器。

inherits from/父类: sensor

Target driver(s)/驱动: lego-ev3-us, lego-nxt-us

ev3dev docs link/ev3dev文档链接: http://www.ev3dev.org/docs/sensors/lego-ev3-ultrasonic-sensor/

Special properties/参数

Distance_Centimeters
float, read

Measurement of the distance detected by the sensor, in centimeters.
传感器的距离测量值,单位:厘米。

Required mode/模式: US-DIST-CM

Value index/索引值: 0

Distance_Inches
float, read

Measurement of the distance detected by the sensor, in inches.
传感器的距离测量值,单位:英寸。

Required mode/模式: US-DIST-IN

Value index/索引值: 0

Other_Sensor_Present
boolean, read

Value indicating whether another ultrasonic sensor could be heard nearby.
用于识别附近是否有其他的超声波传感器。

Required mode/模式: US-LISTEN

Value index/索引值: 0

Gyro Sensor/陀螺仪传感器

class Gyro_Sensor/Gyro_Sensor

LEGO EV3 gyro sensor.
LEGO EV3 陀螺仪传感器。

inherits from/父类: sensor

Target driver(s)/驱动: lego-ev3-gyro

ev3dev docs link/ev3dev文档链接: http://www.ev3dev.org/docs/sensors/lego-ev3-gyro-sensor/

Special properties/参数

Angle
int, read

The number of degrees that the sensor has been rotated since it was put into this mode.
返回在此模式下,传感器转过的角度。

Required mode/模式: GYRO-ANG

Value index/索引值: 0

Rate
int, read

The rate at which the sensor is rotating, in degrees/second.
传感器旋转的速度,单位:角度/秒。

Required mode/模式: GYRO-RATE

Value index/索引值: 0

Infrared Sensor/红外传感器

class Infrared_Sensor/Infrared_Sensor

LEGO EV3 infrared sensor.
LEGO EV3红外传感器。

inherits from/父类: sensor

Target driver(s)/驱动: lego-ev3-ir

ev3dev docs link/ev3dev文档链接: http://www.ev3dev.org/docs/sensors/lego-ev3-infrared-sensor/

Special properties/参数

Proximity
int, read

A measurement of the distance between the sensor and the remote, as a percentage. 100% is approximately 70cm/27in.
返回传感器和信标之间的距离,单位:百分比,当值为100%时距离大约为70cm/27in。

Required mode/模式: IR-PROX

Value index/索引值: 0

Sound Sensor/声波传感器

class Sound_Sensor/Sound_Sensor

LEGO NXT Sound Sensor
LEGO NXT声波传感器

inherits from/父类: sensor

Target driver(s)/驱动: lego-nxt-sound

ev3dev docs link/ev3dev文档链接: http://www.ev3dev.org/docs/sensors/lego-nxt-sound-sensor/

Special properties/参数

Sound_Pressure
float, read

A measurement of the measured sound pressure level, as a percent. Uses a flat weighting.
返回声音强度的测量值,单位:百分比。使用的加权系数保持平衡。

Required mode/模式: DB

Value index/索引值: 0

Sound_Pressure_Low
float, read

A measurement of the measured sound pressure level, as a percent. Uses A-weighting, which focuses on levels up to 55 dB.
返回声音强度的测量值,单位:百分比。使用的加权系数侧重55dB信号范围。

Required mode/模式: DBA

Value index/索引值: 0

Light Sensor/光传感器

class Light_Sensor/Light_Sensor

LEGO NXT Light Sensor
LEGO NXT光传感器

inherits from/父类: sensor

Target driver(s)/驱动: lego-nxt-light

ev3dev docs link/ev3dev文档链接: http://www.ev3dev.org/docs/sensors/lego-nxt-light-sensor/

Special properties/参数

Reflected_Light_Intensity
float, read

A measurement of the reflected light intensity, as a percentage.
反射光强度测量值,单位:百分比。

Required mode/模式: REFLECT

Value index/索引值: 0

Ambient_Light_Intensity
float, read

A measurement of the ambient light intensity, as a percentage.
环境光强度测量值,单位:百分比。

Required mode/模式: AMBIENT

Value index/索引值: 0

ev3dev手册[三]-类

Classes/类


Device (abstract)/设备(摘要)

class Device/Device

This is the base class that handles control tasks for a single port or index. The class must chose one device out of the available ports to control. Given an IO port (in the constructor), an implementation should:
Device类是一个处理单个端口或索引控制任务的基础类。这个类实现从可用端口中选择一个设备完成控制。当提供一个IO端口时(在构造函数中),将执行以下操作:

  • If the specified port is blank or unspecified/undefined/null, the available devices should be enumerated until a suitable device is found. Any device is suitable when it’s type is known to be compatible with the controlling class, and it meets any other requirements specified by the caller.
  • 如果指定的端口未连接设备或未指定/未定义/为空值,可用设备的枚举值为空,直到找到可用的设备正确连接。任何与控制类相兼容的设备都可以被发现并获得相应的功能。
  • If the specified port name is not blank, the available devices should be enumerated until a device is found that is plugged in to the specified port. The supplied port name should be compared directly to the value from the file, so that advanced port strings will match, such as in1:mux3.
  • 如果指定的端口已连接,当设备插入该端口时,可通过枚举值查看到该设备的可用信息。所提供的端口名称应与端口文件中的名称保持一致,以确保未来端口信息的匹配,比如:in1:mux3。

If an error occurs after the initial connection, an exception should be thrown by the binding informing the caller of what went wrong. Unless the error is fatal to the application, no other actions should be taken.
如果初始化连接出现错误,应抛出异常,说明调用错误的具体信息。只有在应用出现致命错误时,才允许采用其他手段处理。

connected/连接状态

If a valid device is found while enumerating the ports, the connected variable is set to true (by default, it should be false). If connected is false when an attempt is made to read from or write to a property file, an error should be thrown (except while in the consructor).
当可用设备连接到端口上,connected变量值为true(默认为false)。如果connected为false,当试图读取或写入设备属性文件时,应该抛出一个错误(除非在构造函数中)。


Motor/马达

class Motor/Motor

The motor class provides a uniform interface for using motors with positional and directional feedback such as the EV3 and NXT motors. This feedback allows for precise control of the motors. This is the most common type of motor, so we just call it motor.
马达类提供了统一的接口,实现像EV3、NXT马达这种具备位置、方向反馈能力的马达的控制。可以控制得非常精确,这个类提供通用马达的属性,命名为motor。

The way to configure a motor is to set the ‘_sp’ attributes when calling a command or before. Only in ‘run_direct’ mode attribute changes are processed immediately, in the other modes they only take place when a new command is issued.
配置马达的方法是设置‘_sp’属性。只有在’run_direct’模式下可以实时变更属性值,其他模式下只有新的指令发出后属性变更才会生效。

ev3dev docs link/文档链接: http://www.ev3dev.org/docs/drivers/tacho-motor-class/

System properties/系统属性

Address
string, read/字符串,只读

Returns the name of the port that this motor is connected to.
返回马达所连接的端口名称。

Command
string, write/字符串,可写

Sends a command to the motor controller. See commands for a list of possible values.
用于给马达控制器发送指令。commands提供了可用的指令值。

commands
string array, read/字符串数组,只读

Returns a list of commands that are supported by the motor controller. Possible values are run-forever, run-to-abs-pos, run-to-rel-pos, run-timed, run-direct, stop and reset. Not all commands may be supported.
返回当前所使用马达支持的所有控制指令,包括:run-forever,run-to-abs-pos,run-to-rel-pos,run-timed,run-direct,stop,reset。这些指令对于你所使用的马达也许未必都支持。

  • run-forever will cause the motor to run until another command is sent.
  • run-forever指令让马达一直运转直到下一条指令。
  • run-to-abs-pos will run to an absolute position specified by position_sp and then stop using the action specified in stop_action.
  • run-to-abs-pos指令使马达运行到一个绝对位置,位置由position_sp值决定,停止的方式由stop_command值决定。
  • run-to-rel-pos will run to a position relative to the current position value. The new position will be current position + position_sp. When the new position is reached, the motor will stop using the action specified by stop_action.
  • run-to-rel-pos指令使马达运行到据当前位置的一个相对位置,最终的位置由当前位置加上相对位置变化值决定,position+position_sp,马达到达新的位置后按照stop_command的值停止运行。
  • run-timed will run the motor for the amount of time specified in time_sp and then stop the motor using the action specified by stop_action.
  • run-timed指令使马达运行指定的时间,时间参数通过time_sp的值设定。
  • run-direct will run the motor at the duty cycle specified by duty_cycle_sp. Unlike other run commands, changing duty_cycle_sp while running will take effect immediately.
  • run-direct指令使马达按照设定的占空比转动,此时可以实时通过duty_cycle_sp参数修改占空比。
  • stop will stop any of the run commands before they are complete using the action specified by stop_action.
  • stop指令用于停止马达,停止的方式由stop_command的值指定。
  • reset will reset all of the motor parameter attributes to their default value. This will also have the effect of stopping the motor.
  • reset指令用于将马达的所有参数重置为默认值,这条指令也可以用于停止运行中的马达。

Count_Per_Rot
int, read/整型,只读

Returns the number of tacho counts in one rotation of the motor. Tacho counts are used by the position and speed attributes, so you can use this value to convert rotations or degrees to tacho counts. (rotation motors only)
返回马达转一圈所走的步数。马达转动的位置和速度属性都用步数来标示,所以可以用这个参数的返回值来计算马达转了多少圈、多少角度。(只用于转动马达)

Count_Per_M
int, read/整型,只读

Returns the number of tacho counts in one meter of travel of the motor. Tacho counts are used by the position and speed attributes, so you can use this value to convert from distance to tacho counts. (linear motors only)
返回马达每走一厘米所走的步数。马达通过位置和速度属性计算步数,所以可以用这个参数进行距离和步数之间的转换。(只用于直线/推杆马达)

Driver_Name
string, read/字符串,只读

Returns the name of the driver that provides this tacho motor device.
返回所连接马达的驱动名称。

Duty_Cycle
int, read/整数,只读

Returns the current duty cycle of the motor. Units are percent. Values are -100 to 100.
返回马达的占空比,单位百分比%,取值-100到100。

Duty_Cycle_SP
int,read/write /整型,可读写

Writing sets the duty cycle setpoint. Reading returns the current value. Units are in percent. Valid values are -100 to 100. A negative value causes the motor to rotate in reverse.
写入数值设定占空比,读取操作可以查询当前的设定值。单位采用百分比,取值-100到100。负值就是让马达反向旋转。只有当speed_regulation的值为off时,这个参数才生效。

Full_Travel_Count
int, read/整型,只读

Returns the number of tacho counts in the full travel of the motor. When combined with the count_per_m atribute, you can use this value to calculate the maximum travel distance of the motor. (linear motors only)
返回最大传动距离下的马达步数。如果结合count_per_m参数,可以计算出马达的最大传动距离。(仅限线性/推杆马达)

Polarity
string, read/write /字符串,可读写

Sets the polarity of the motor. With normal polarity, a positive duty cycle will cause the motor to rotate clockwise. With inversed polarity, a positive duty cycle will cause the motor to rotate counter-clockwise. Valid values are normal and inversed.
设置马达的极性。设置为normal,占空比为正数时马达以顺时针转动。设置为inversed,占空比为正数时马达以逆时针转动。参数值包括:normal和inversed。

Position
int, read/write /整型,可读写

Returns the current position of the motor in pulses of the rotary encoder. When the motor rotates clockwise, the position will increase. Likewise, rotating counter-clockwise causes the position to decrease. Writing will set the position to that value.
反馈马达当前的位置,位置的表示按照译码器中脉冲数计算。当马达按照顺时针转动时,马达的位置值是增长的。同样,逆时针转动,马达的位置值就减少。写入值可以设置位置值。

Position_P
int, read/write /整型,可读写

The proportional constant for the position PID.
PID中的比例值表示。

Postion_I
int, read/write /整型,可读写

The integral constant for the position PID.
PID中的积分值表示。

Position_D
int, read/write /整型,可读写

The derivative constant for the position PID.
PID中的微分值表示。

Position_SP
int, read/write /整型,可读写

Writing specifies the target position for the run-to-abs-pos and run-to-rel-pos commands. Reading returns the current value. Units are in tacho counts. You can use the value returned by counts_per_rot to convert tacho counts to/from rotations or degrees.
用于为run-to-abs-pos和run-to-rel-pos指令设置目标值。读取参数将返回当前值。单位是马达步数。我们可以通过这个值配合counts_per_rot的值来计算马达转动角度或转动圈数。

Max_Speed
int, read/整型,只读

Returns the maximum value that is accepted by the speed_sp attribute. This may be slightly different than the maximum speed that a particular motor can reach – it’s the maximum theoretical speed.
返回speed_sp参数设置下的马达最大速度值。这个值只是一个理论值,与实际马达达到的结果会稍微有一些偏差。

Speed
int, read/整型,只读

Returns the current motor speed in tacho counts per second. Note, this is not necessarily degrees (although it is for LEGO motors). Use the count_per_rot attribute to convert this value to RPM or deg/sec.
返回当前马达的速度,单位:步数/秒。马达转一圈的步数不一定是360步(尽管对于LEGO马达一圈就是360步),但可以通过计算count_per_rot的值,来对当前所使用马达的速度与RPM或角度/秒等单位之间进行转换。

Speed_SP
int, read/write /整型,可读写

Writing sets the target speed in tacho counts per second used for all run-* commands except run-direct. Reading returns the current value. A negative value causes the motor to rotate in reverse with the exception of run-to-*-pos commands where the sign is ignored. Use the count_per_rot attribute to convert RPM or deg/sec to tacho counts per second. Use the count_per_m attribute to convert m/s to tacho counts per second.
当speed_regulation_enabled值为on时,写入该参数,将设定马达的速度,单位:步数/秒,用于除了run-direct之外的所有run-*指令。读取该参数返回当前值。可以借助count_per_rot的值进行与RPM或角度/秒单位之间的转换。

Ramp_Up_SP
int, read/write /整型,可读写

Writing sets the ramp up setpoint. Reading returns the current value. Units are in milliseconds and must be positive. When set to a non-zero value, the motor speed will increase from 0 to 100% of max_speed over the span of this setpoint. The actual ramp time is the ratio of the difference between the speed_sp and the current speed and max_speed multiplied by ramp_up_sp.
匀速加速,写入参数可以设定加速值,读取参数返回当前值。单位是毫秒。当设定的值非0,马达的占空比在设定时间内从0上升到100%。如果通过duty_cycle_sp设定了最大占空比限制,那么加速时间相对设定值会等比例减少。

Ramp_Down_SP
int, read/write /整型,可读写

Writing sets the ramp down setpoint. Reading returns the current value. Units are in milliseconds and must be positive. When set to a non-zero value, the motor speed will decrease from 0 to 100% of max_speed over the span of this setpoint. The actual ramp time is the ratio of the difference between the speed_sp and the current speed and max_speed multiplied by ramp_down_sp.
匀速减速,写入参数可以设定减速值,读取参数返回当前值。单位是毫秒,值为负。当设定的值非0,马达的占空比在设定时间内从100%下降为0。如果初始的占空比不足100%,那么减速时间相对设定值会等比例减少。

Speed_P
int, read/write /整型,可读写

The proportional constant for the speed regulation PID.
PID速度管理中的比例常数P。

Speed_I
int, read/write /整型,可读写

The integral constant for the speed regulation PID.
PID速度管理中的积分常数I。

Speed_D
int, read/write /整型,可读写

The derivative constant for the speed regulation PID.
PID速度管理中的微分常数I。

State
string array, read/字符串数组,只读

Reading returns a list of state flags. Possible flags are running, ramping, holding, overloaded and stalled.
返回状态标签,包括:running(运行中)、ramping(斜坡)、holding(固定)、overloaded(超载)以及stalled(停滞)。

Stop_Action
string, read/write /字符串,可读写

Reading returns the current stop action. Writing sets the stop action. The value determines the motors behavior when command is set to stop. Also, it determines the motors behavior when a run command completes. See stop_actions for a list of possible values.
读取参数返回当前的停止方式,写入参数来设定停止方式。该参数的值决定了马达停止的方式,stop_actions给出所有可用的值。

Stop_Actions
string array, read /字符串,只读

Returns a list of stop actions supported by the motor controller. Possible values are coast, brake and hold. coast means that power will be removed from the motor and it will freely coast to a stop. brake means that power will be removed from the motor and a passive electrical load will be placed on the motor. This is usually done by shorting the motor terminals together. This load will absorb the energy from the rotation of the motors and cause the motor to stop more quickly than coasting. hold does not remove power from the motor. Instead it actively tries to hold the motor at the current position. If an external force tries to turn the motor, the motor will ‘push back’ to maintain its position.
返回当前马达可用的停止模式列表,包括:coast、brake、hold。coast模式:马达得到停止指令时,随惯性再转会停止。brake模式:马达得到停止指令时,立刻停止转动,制动距离较coast模式要短得多。hold模式:马达得到停止指令时,马达并不会停止供电,而是将马达稳稳的保持在停止时的位置(position),此时如果你用外力强制改变他的位置,马达会强有力的跟你较劲,还是会转回它的位置。

Time_SP
int, read/write /整型,可读写

Writing specifies the amount of time the motor will run when using the run-timed command. Reading returns the current value. Units are in milliseconds.
当使用run-timed指令运行马达的时候,写入该值会设定运行时间。读取该值返回当前值。单位:毫秒ms。


Large Motor/大型马达

class Large_Motor/Large_Motor

EV3 large servo motor/EV3大型伺服马达

inherits from/父类: motor

Target driver(s): lego-ev3-l-motor
目标驱动:lego-ev3-l-motor


Medium Motor/中型马达

class Medium_Motor/ Medium_Motor

EV3 medium servo motor/EV3中型伺服马达

inherits from: motor
父类:motor

Target driver(s): lego-ev3-m-motor
目标驱动:lego-ev3-m-motor


NXT Motor/NXT马达

class NXT_Motor/ NXT_Motor

NXT servo motor/NXT伺服马达

inherits from: motor
父类:motor

Target driver(s): lego-nxt-motor
目标驱动:lego-nxt-motor


Firgelli L12 50 Motor/50刻度推杆马达

class Firgelli_L12_50_Motor/ Firgelli_L12_50_Motor

Firgelli L12 50 linear servo motor/50刻度推杆(线性)伺服马达

inherits from/父类: motor

Target driver(s)/目标驱动: fi-l12-ev3-50


Firgelli L12 100 Motor/100刻度推杆马达

class Firgelli_L12_100_Motor/ Firgelli_L12_100_Motor

Firgelli L12 100 linear servo motor/100刻度推杆(线性)伺服马达

inherits from/父类: motor

Target driver(s): fi-l12-ev3-100
目标驱动:fi-l12-ev3-100


DC Motor/直流马达

class DC_Motor/类 DC_Motor

The DC motor class provides a uniform interface for using regular DC motors with no fancy controls or feedback. This includes LEGO MINDSTORMS RCX motors and LEGO Power Functions motors.
该类提供了直流马达的统一接口,直流马达比较简单,并没有高级控制和反馈功能,LEGO RCX和动力组的马达都属于这种。

ev3dev docs link: http://www.ev3dev.org/docs/drivers/dc-motor-class/
ev3dev文档链接

System properties

Address
string, read/字符串,只读

Returns the name of the port that this motor is connected to.
返回马达所连接的端口名称

Command
string, write/字符串,可写

Sets the command for the motor. Possible values are run-forever, run-timed and stop. Not all commands may be supported, so be sure to check the contents of the commands attribute.
设置马达指令,包括:run-forever、run-timed和stop。并非所有马达都适用这些指令,因此在使用马达前,需通过commands参数确认可用的指令都有哪些。

Commands
string array, read/字符串数组,只读

Returns a list of commands supported by the motor controller.
返回马达所支持的所有指令。

Driver_Name
string, read/字符串,只读

Returns the name of the motor driver that loaded this device. See the list of [supported devices] for a list of drivers.
返回所连接设备的驱动名称,可以通过[支持设备清单]了解所提供的驱动支持。

Duty_Cycle
int, read/整型,只读

Shows the current duty cycle of the PWM signal sent to the motor. Values are -100 to 100 (-100% to 100%).
显示当前马达PWM(脉冲信号)的占空比,读值范围-100至100(-100%至100%)。

Duty_Cycle_SP
int, read/write /整型,可读写

Writing sets the duty cycle setpoint of the PWM signal sent to the motor. Valid values are -100 to 100 (-100% to 100%). Reading returns the current setpoint.
写入该参数可以设置马达PWM占空比,取值范围-100到100(-100%到100%)。读取该参数可以获取当前的设定值。

Polarity
string, read/write /字符串,可读写

Sets the polarity of the motor. Valid values are normal and inversed.
设置马达的极性,可用的值为normal(正常)和inversed(反向)。

Ramp_Down_SP
int, read/write /整型,可读写

Sets the time in milliseconds that it take the motor to ramp down from 100% to 0%. Valid values are 0 to 10000 (10 seconds). Default is 0.
设置马达速度从100%降到0%的时间(单位:毫秒),取值范围0到10000(10秒),默认是0。

Ramp_Up_SP
int, read/write /整型,可读写

Sets the time in milliseconds that it take the motor to up ramp from 0% to 100%. Valid values are 0 to 10000 (10 seconds). Default is 0.
设置马达速度从0%升到100%的时间(单位:毫秒),取值范围0到10000(10秒),默认是0。

State
string array, read /字符串数组,只读

Gets a list of flags indicating the motor status. Possible flags are running and ramping. running indicates that the motor is powered. ramping indicates that the motor has not yet reached the duty_cycle_sp.
返回马达的状态清单,包括:running(运行)和ramping(变速)。running表示马达已接通,ramping表示马达还未达到duty_cycle_sp设定的速度。

Stop_Action
string, write/字符串,可写

Sets the stop action that will be used when the motor stops. Read stop_actions to get the list of valid values.
设定马达停止的方式,通过stop_actions可以获得所有可用的停止方式。

Stop_Actions
string array, read/字符串数组,只读

Gets a list of stop actions. Valid values are coast and brake.
获得可用的停止方式清单,包括:coast(惯性停止)和brake(立刻停止)。

Time_SP
int, read/write /整型,可读写

Writing specifies the amount of time the motor will run when using the run-timed command. Reading returns the current value. Units are in milliseconds.
当使用run-timed指令运行马达的时候,写入该值会设定运行时间。读取该值返回当前值。单位:毫秒ms。


Servo Motor/伺服马达

class Servo_Motor/类 Servo_Motor

The servo motor class provides a uniform interface for using hobby type servo motors.
该类提供了使用轻量级伺服马达的统一接口。

ev3dev docs link/ev3dev文档链接: http://www.ev3dev.org/docs/drivers/servo-motor-class/

System properties

Address
string, read/字符串,只读

Returns the name of the port that this motor is connected to.
返回马达所连接的端口名称。

Command
string, write/字符串,可写

Sets the command for the servo. Valid values are run and float. Setting to run will cause the servo to be driven to the position_sp set in the position_sp attribute. Setting to float will remove power from the motor.
设定伺服马达的指令,包括:run和float。设置为run可以使得马达运行到通过position_sp参数设定的指定位置。设置为float将停止马达供电。

Driver_Name
string, read/字符串,只读

Returns the name of the motor driver that loaded this device. See the list of [supported devices] for a list of drivers.
返回所加载马达的驱动名称。通过[支持设备清单]可获得所有驱动名称。

Max_Pulse_SP
int, read/write /整型,可读写

Used to set the pulse size in milliseconds for the signal that tells the servo to drive to the maximum (clockwise) position_sp. Default value is 2400. Valid values are 2300 to 2700. You must write to the position_sp attribute for changes to this attribute to take effect.
用于设定信号的脉冲振幅(单位:毫秒),这个信号是用来通知伺服马达达到position_sp的最大值(顺时针)。默认值是2400,取值范围2300到2700。若想使用这个参数,必须先要设置position_sp参数的值。

Mid_Pulse_SP
int, read/write /整型,可读写

Used to set the pulse size in milliseconds for the signal that tells the servo to drive to the mid position_sp. Default value is 1500. Valid values are 1300 to 1700. For example, on a 180 degree servo, this would be 90 degrees. On continuous rotation servo, this is the ‘neutral’ position_sp where the motor does not turn. You must write to the position_sp attribute for changes to this attribute to take effect.
用于设定信号的脉冲振幅(单位:毫秒),这个信号是用来通知伺服马达达到position_sp的中间值。默认值是1500,取值范围1300到1700。例如:在一个180度的伺服马达上,设定此参数相当于转动90度,在持续转动过程中,相当于马达不会达到的position_sp的“中间值”。若想使用这个参数,必须先要设置position_sp参数的值。

Min_Pulse_SP
int, read/write /整型,可读写

Used to set the pulse size in milliseconds for the signal that tells the servo to drive to the miniumum (counter-clockwise) position_sp. Default value is 600. Valid values are 300 to 700. You must write to the position_sp attribute for changes to this attribute to take effect.
用于设定信号的脉冲振幅(单位:毫秒),这个信号是用来通知伺服马达达到position_sp的最小值(逆时针)。默认值是600,取值范围300到700。若想使用这个参数,必须先要设置position_sp参数的值。

Polarity
string, read/write /字符串,可读写

Sets the polarity of the servo. Valid values are normal and inversed. Setting the value to inversed will cause the position_sp value to be inversed. i.e -100 will correspond to max_pulse_sp, and 100 will correspond to min_pulse_sp.
设置伺服马达的极性,包括:normal(正常)和inversed(反向)。设置为inversed会导致position_sp的值取相反的结果,例如:-100将对应max_pulse_sp,而100则对应min_pulse_sp。

Position_SP
int, read/write /整型,可读写

Reading returns the current position_sp of the servo. Writing instructs the servo to move to the specified position_sp. Units are percent. Valid values are -100 to 100 (-100% to 100%) where -100 corresponds to min_pulse_sp, 0 corresponds to mid_pulse_sp and 100 corresponds to max_pulse_sp.
读取该参数返回当前的position_sp值。写入该参数会通知马达转动到position_sp指定的位置。单位:%,取值范围:-100到100(-100%到100%),-100对应min_pulse_sp,0对应mid_pulse_sp,100对应max_pulse_sp。

Rate_SP
int, read/write /整型,可读写

Sets the rate_sp at which the servo travels from 0 to 100.0% (half of the full range of the servo). Units are in milliseconds. Example: Setting the rate_sp to 1000 means that it will take a 180 degree servo 2 second to move from 0 to 180 degrees. Note: Some servo controllers may not support this in which case reading and writing will fail with -EOPNOTSUPP. In continuous rotation servos, this value will affect the rate_sp at which the speed ramps up or down.
在伺服系统0到100.0%(全范围伺服的一半)中设定rate_sp参数值,单位:毫秒。例如:设置rate_sp为1000代表将一个180度的伺服马达在2秒钟内从0达到180度。注意:一些伺服控制器并不支持这个参数,在读写参数时会提示-EOPNOTSUPP错误。在一个持续转动的伺服马达上,这个值会影响速度变化过程中的rate_sp。

State
string array, read/字符串数组,只读

Returns a list of flags indicating the state of the servo. Possible values are: * running: Indicates that the motor is powered.
返回当前伺服马达的状态,其中running代表马达接通。


LED/发光二极管

class LED/ LED

Any device controlled by the generic LED driver. See https://www.kernel.org/doc/Documentation/leds/leds-class.txt for more details.
通用LED驱动详细信息可以访问:https://www.kernel.org/doc/Documentation/leds/leds-class.txt

System properties/系统属性

Max_Brightness
int, read/整型,只读

Returns the maximum allowable brightness value.
返回亮度的最大值。

Brightness
int, read/write /整型,可读写

Sets the brightness level. Possible values are from 0 to max_brightness.
设置亮度值,取值范围:0到max_brightness(可用的最大值)。

Triggers
string array, read/字符串数组,只读

Returns a list of available triggers.
返回可用的触发器清单。

Trigger
string selector, read/write /字符串选择器,可读写

Sets the led trigger. A trigger is a kernel based source of led events. Triggers can either be simple or complex. A simple trigger isn’t configurable and is designed to slot into existing subsystems with minimal additional code. Examples are the ide-disk and nand-disk triggers.
设置led触发器,触发器是led事件的基本核心,有简单的也有复杂的。简单的触发器不支持配置,仅仅通过少量代码插入到当前的子系统中,IDE硬盘和闪存磁盘的触发器就是类似这种。

Complex triggers whilst available to all LEDs have LED specific parameters and work on a per LED basis. The timer trigger is an example. The timer trigger will periodically change the LED brightness between 0 and the current brightness setting. The on and off time can be specified via delay_{on,off} attributes in milliseconds. You can change the brightness value of a LED independently of the timer trigger. However, if you set the brightness value to 0 it will also disable the timer trigger.
复杂的触发器对每一个LED都有单独特定的参数,以定时触发器为例:定时触发器可以定期的调整LED亮度,开启和关闭时间可以通过delay_{on,off}参数设置(单位:毫秒),每一个LED的亮度设定也可以是独立的,当设置亮度值为0后,相当于关闭了定时触发器。

Delay_On
int, read/write /整型,可读写

The timer trigger will periodically change the LED brightness between 0 and the current brightness setting. The on time can be specified via delay_on attribute in milliseconds.
定时触发器会周期性的改变LED亮度,亮度范围介于0到设定值之间。亮起时间可以通过delay_on参数设定,单位:毫秒。

Delay_Off
int, read/write /整型,可读写

The timer trigger will periodically change the LED brightness between 0 and the current brightness setting. The off time can be specified via delay_off attribute in milliseconds.
定时触发器会周期性的改变LED亮度,亮度范围介于0到设定值之间。熄灭时间可以通过delay_off参数设定,单位:毫秒。


Sensor/传感器

class Sensor/类 Sensor

The sensor class provides a uniform interface for using most of the sensors available for the EV3. The various underlying device drivers will create a lego-sensor device for interacting with the sensors.
传感器类为EV3可用传感器提供统一接口。不同的设备驱动与传感器之间通过创建一个lego-sensor设备相连接。

Sensors are primarily controlled by setting the mode and monitored by reading the value<N> attributes. Values can be converted to floating point if needed by value<N> / 10.0 ^ decimals.
传感器主要通过第<N>参数值对模式和状态监控进行控制。这些值可以通过<N>值/10.0^次方的方式转换为浮点格式。

Since the name of the sensor<N> device node does not correspond to the port that a sensor is plugged in to, you must look at the address attribute if you need to know which port a sensor is plugged in to. However, if you don’t have more than one sensor of each type, you can just look for a matching driver_name. Then it will not matter which port a sensor is plugged in to – your program will still work.
若想知道传感器所插入的端口,需要查询address参数,这是因为当传感器连接时其在系统中对应的设备节点<N>并不会立刻响应。如果同一类型的传感器只有一个,那么通过设备驱动名称就可以使用该传感器,而不需要区分具体的端口号。

ev3dev docs link/ev3dev文档链接: http://www.ev3dev.org/docs/drivers/lego-sensor-class/

System properties/系统属性

Address
string, read/字符串,只读

Returns the name of the port that the sensor is connected to, e.g. ev3:in1. I2C sensors also include the I2C address (decimal), e.g. ev3:in1:i2c8.
返回传感器所连接的端口名称,例如:ev3:in1。I2C传感器同时包含I2C地址(十进制),例如:ev3:in1:i2c8。

Command
string, write/字符串,可写

Sends a command to the sensor.
向传感器发送指令。

Commands
string array, read/字符串数组,只读

Returns a list of the valid commands for the sensor. Returns -EOPNOTSUPP if no commands are supported.
返回传感器可用的指令列表。如果没有可用指令,返回-EOPNOTSUPP。

Decimals
int, read/整型,只读

Returns the number of decimal places for the values in the value<N> attributes of the current mode.
返回当前模式下参数值<N>的小数点位数。

Driver_Name
string, read/字符串,只读

Returns the name of the sensor device/driver. See the list of [supported sensors] for a complete list of drivers.
返回传感器驱动名称。通过[已支持传感器列表]可以获得所有驱动名称。

Mode
string, read/write /字符串,可读写

Returns the current mode. Writing one of the values returned by modes sets the sensor to that mode.
返回当前的模式。写入该参数可以改变模式,通过modes参数可以获得所有的模式。

Modes
string array, read/字符串数组,只读

Returns a list of the valid modes for the sensor.
返回当前传感器支持的所有模式。

Num_Values
int, read/整型,只读

Returns the number of value<N> attributes that will return a valid value for the current mode.
返回参数值<N>的有效值数量。

Units
string, read/字符串,只读

Returns the units of the measured value for the current mode. May return empty string.
返回当前模式下测量值的单位。有可能返回字符串为空。


I2C Sensor/I2C传感器

class I2C_Sensor/类 I2C_Sensor

A generic interface to control I2C-type EV3 sensors.
EV3 I2C传感器统一接口。

inherits from/父类: sensor

Target driver(s)/目标驱动: nxt-i2c-sensor

System properties/系统属性

FW_Version
string, read/字符串,只读

Returns the firmware version of the sensor if available. Currently only I2C/NXT sensors support this.
返回传感器的固件版本。目前只支持I2C/NXT的传感器。

Poll_MS
int, read/write /整型,可读写

Returns the polling period of the sensor in milliseconds. Writing sets the polling period. Setting to 0 disables polling. Minimum value is hard coded as 50 msec. Returns -EOPNOTSUPP if changing polling is not supported. Currently only I2C/NXT sensors support changing the polling period.
返回传感器的轮询周期,单位:毫秒。写入该参数设置轮询周期,值为0时关闭轮询。最小值为硬编码50毫秒。当改变轮询失败时返回-EOPNOTSUPP。当前只支持I2C/NXT传感器。


Power Supply/供电

class Power_Supply/类 Power_Supply

A generic interface to read data from the system’s power_supply class. Uses the built-in legoev3-battery if none is specified.
提供读取系统供电数据的统一接口。若不特殊指定,使用内建的legoev3-battery方案。

System properties/系统属性

Measured_Current
int, read/整型,只读

The measured current that the battery is supplying (in microamps)
当前电池的测量电流,单位:微安。

Measured_Voltage
int, read/整型,只读

The measured voltage that the battery is supplying (in microvolts)
当前电池的测量电压,单位:微伏。

Max_Voltage
int, read/整型,只读

Min_Voltage
int, read/整型,只读

Technology
string, read/字符串,只读

Type
string, read/字符串,只读


Lego Port

class Lego_Port/类 Lego_Port

The lego-port class provides an interface for working with input and output ports that are compatible with LEGO MINDSTORMS RCX/NXT/EV3, LEGO WeDo and LEGO Power Functions sensors and motors. Supported devices include the LEGO MINDSTORMS EV3 Intelligent Brick, the LEGO WeDo USB hub and various sensor multiplexers from 3rd party manufacturers.
该类为输入输出端口提供了统一接口,该接口兼容于LEGO MINDSTORMS RCX/NXT/EV3、LEGO WeDo和LEGO动力组的传感器和马达。所支持的设备包括LEGO MINDSTORMS EV3控制器(智能砖),第三方平台提供的LEGO WeDo传感器集成器件。

Some types of ports may have multiple modes of operation. For example, the input ports on the EV3 brick can communicate with sensors using UART, I2C or analog validate signals – but not all at the same time. Therefore there are multiple modes available to connect to the different types of sensors.
部分端口可能支持多种运行模式。比如:EV3的控制器的输入端口与UART、I2C或模拟信号的传感器都可以进行通信,但不是同时的。因此,不同类型的传感器对应着不同的运行模式。

In most cases, ports are able to automatically detect what type of sensor or motor is connected. In some cases though, this must be manually specified using the mode and set_device attributes. The mode attribute affects how the port communicates with the connected device. For example the input ports on the EV3 brick can communicate using UART, I2C or analog voltages, but not all at the same time, so the mode must be set to the one that is appropriate for the connected sensor. The set_device attribute is used to specify the exact type of sensor that is connected. Note: the mode must be correctly set before setting the sensor type.
通常端口能够自动识别所连接的传感器和马达。特殊情况下可以通过set_device参数进行模式的手动配置。模式的属性影响了端口与设备连接的通信方式。比如:EV3控制器的输入端口可以与URT、I2C或模拟电压信号进行异步通信,所使用的模式必须设置为适用于当前传感器的模式。set_device参数主要用于设置额外类型的传感器。注意:在设置传感器类型之前必须将端口模式正确配置。

Ports can be found at /sys/class/lego-port/port<N> where <N> is incremented each time a new port is registered. Note: The number is not related to the actual port at all – use the address attribute to find a specific port.
端口信息保存在:/sys/class/lego-port/port<N> ,其中<N>随着注册新端口而增加。注意:此处的数字并不代表物理上的端口号,若想查找具体的端口号可以通过address参数获得。

System properties/系统属性

Address
string, read/字符串,只读

Returns the name of the port. See individual driver documentation for the name that will be returned.
返回端口名称。通过驱动文档可以获得所返回的端口名称。

Driver_Name
string, read/字符串,只读

Returns the name of the driver that loaded this device. You can find the complete list of drivers in the [list of port drivers].
返回加载设备的驱动名称。[端口驱动列表]提供了完整的驱动名称。

Modes
string array, read/字符串数组,只读

Returns a list of the available modes of the port.
返回端口可用的所有模式。

Mode
string, read/write /字符串,可读写

Reading returns the currently selected mode. Writing sets the mode. Generally speaking when the mode changes any sensor or motor devices associated with the port will be removed new ones loaded, however this will depend on the individual driver implementing this class.
读取该参数获得当前模式。写入该参数可设置模式。通常,当端口模式修改时,与之相关的传感器或马达设备会被新的加载项替换,取决于执行这个类的具体驱动。

Set_Device
string, write/字符串,可写

For modes that support it, writing the name of a driver will cause a new device to be registered for that driver and attached to this port. For example, since NXT/Analog sensors cannot be auto-detected, you must use this attribute to load the correct driver. Returns -EOPNOTSUPP if setting a device is not supported.
针对所支持的端口模式,写入驱动名称会为此驱动注册一个新的设备和所对应的端口。比如:由于NXT/模拟传感器无法被自动设别,就必须利用此参数加载正确的驱动。若设置的设备不支持,将返回-EOPNOTSUPP。

Status
string, read/字符串,只读

In most cases, reading status will return the same value as mode. In cases where there is an auto mode additional values may be returned, such as no-device or error. See individual port driver documentation for the full list of possible values.
通常读取status的返回值与mode相同。在自动模式下读取该参数会返回其他值,比如:no-device或error。可以通过端口驱动文档获得完整的参数值。

通用设备

类名称 ev3dev.device

通用设备

attr_int:读写整数属性。示例:

d.attr_int.speed_sp = 100 #设置d的速度为100

attr_line:读取线性属性。示例:

print (d.attr_line.modes) #输出d的所有模式

attr_set:读取配置属性。示例:

print (d.attr_set.commands) #输出d的所有指令

attr_string:读写字符串属性。示例:

d.attr_string.mode = 'IR-PROX' #设置d的模式为IR-PROX

connect():对象定义

connect(tuple args, dict kwds)

connect(path, pattern, attr1=val1, …)

按照设定参数尝试连接设备

参数定义:path: 路径,指定搜索设备的路径。示例:

'/sys/class/tacho-motor/'

pattern:模式,设备名称。示例:

'motor'

keyword arguments:搜索设备时所匹配的设备属性值

示例(连接一个EV3的大型马达):

d = device ()
d.connect ('/sys/class/tacho-motor/', 'motor', driver_name='lego-ev3-motor')

get_attr_from_set ((device)arg1, (str)arg2) -> str从配置属性中读取当前的运行模式

get_attr_int ((device)arg1, (str)arg2) -> int读取整数属性

get_attr_line((device)arg1, (str)arg2) -> str:读取线性属性

get_attr_set((device)arg1, (str)arg2[, (str)name]) -> mode_set读取配置属性

get_attr_string((device)arg1, (str)arg2) -> str读取字符串属性

set_attr_int((device)arg1, (str)arg2, (int)arg3) -> None写入整数属性

set_attr_string((device)arg1, (str)arg2, (str)arg3) -> None写入字符串属性

ev3dev手册[二]-内容

ev3dev Language Wrapper Specification

ev3dev 语言封装规范

This is an unofficial specification that defines a unified interface for language wrappers to expose the ev3dev device APIs.

这是一套非官方的规范,规范定义了针对ev3dev设备封装后的API唯一接口。

General Notes

一般性说明

Because this specification is meant to be implemented in multiple languages, the specific naming conventions of properties, methods and classes are not defined here. Depending on the language, names will be slightly different (ex. “touchSensor” or “TouchSensor” or “touch-sensor”) so that they fit the language’s naming conventions.

因为这套规范旨在支持多种编程语言,所以对于属性、方法、类的特殊命名约定并未定义。针对不同的编程语言,命名可能会有些许差异(比如:“touchSensor”、“TouchSensor”、“touch-sensor”),但不会影响使用。

Some concepts that apply to multiple classes are described as “abstracts”. These abstract sections explain how the class should handle specific situations, and do not necessarily translate in to their own class in the wrapper.

“摘要”用于描述适用于多个类的概念。这些摘要部分解释了类如何处理一些特定的情况,这种情况下可以直接使用,而无需封装为各个编程语言自身的类。

Implementation Notes (important)

使用说明(重要)

  • File access. There should be one class that is used or inherited from in all other classes that need to access object properties via file I/O. This class should check paths for validity, do basic error checking, and generally implement as much of the core I/O functionality as possible.
  • 文件访问。在封装里应该定义一个类,这样当有其他类需要通过文件I/O访问对象属性时,可以使用或继承这个类。所定义的类应该确保路径可用、完成基本的错误检测、充分提供核心I/O功能。
  • Errors. All file access and other error-prone calls should be wrapped with error handling. If an error thrown by an external call is fatal, the wrapper should throw an error for the caller that states the error and gives some insight in to what actually happened.
  • 报错。在进行封装时,所有文件访问和其他容易发生错误的调取方式均应考虑异常处理。当外部调用可能引发致命错误时,应该能够向调用方抛出异常,并说明所发生错误的具体原因。
  • Naming conventions. All names should follow the language’s naming conventions. Keep the names consistent, so that users can easily find what they want.
  • 命名约定。所有名称均应遵循编程语言的命名约定。尽量时名称易读,以便于使用者更容易的找到所需信息。
  • Attribute types. int and string attributes are read-write files containing a single value that is representable either as an integer or as a single word. Astring array attribute is a readonly file that contains space-separated list of words, where each word is a possible value of some other string atribute. And a string selector attribute is a read-write file that contains space-separated list of possible values, where the currently selected value is enclosed in square brackets. Another value may be selected by writing a single word to the file.
  • 属性类型。整型(int)和字符串(string)属性是一个可读写文件,其包含了对应的数字或单词作为属性值;字符串数组(string array)属性是一个只读文件,其包含了若干个以空格分开的单词作为属性值,每个单词都是其他字符串属性的一个值;字符串选择(string selector)属性是一个可读写文件,其包含若干个以空格分开的值,当前所使用的值用中括号标识;还有一种通过向文件写入单词的方式使用的属性值。

Contents

目录

  • Classes/类
    • Device (abstract)/设备(摘要)
    • Motor/马达
    • Large Motor/大型马达
    • Medium Motor/中型马达
    • NXT Motor/NXT 马达
    • Firgelli L12 50 Motor/Firgelli L12 50 推杆马达
    • Firgelli L12 100 Motor/Firgelli L12 100 推杆马达
    • DC Motor/直流马达
    • Servo Motor/伺服马达
    • LED/LED
    • Button/按键
    • Sensor/传感器
    • I2C Sensor/I2C 传感器
    • Power Supply/供电
    • Lego Port/乐高端口
  • Special sensor classes/专用传感器类
    • Touch Sensor/触碰传感器
    • Color Sensor/颜色传感器
    • Ultrasonic Sensor/超声波传感器
    • Gyro Sensor/陀螺仪传感器
    • Infrared Sensor/红外传感器
    • Sound Sensor/声音传感器
    • Light Sensor/光传感器
  • Constants / Enums/枚举值
    • Ports/端口

红外传感器

红外传感器和远程红外信标

红外传感器可以检测从固体物体反射回来的红外光,也可以检测到从远程红外信标发送来的红外光信号。红外传感器包含两种模式:距离模式和信标模式。

距离模式

在近程模式下,红外传感器利用物体表面反射回来的光波来估计该物体与传感器之间的距离,取值范围从0(很近)到100(很远),这个值不是具体的厘米或英寸数。传感器可以检测出远至70厘米的物体,实际范围取决于物体的尺寸和形状。

infrared sensor

信标模式

从遥控器中远程红外信标四个频道里选择一个,红外传感器会检测与程序里指定的频道相匹配的信标信号,在其面对的方向最远检测距离可达约200厘米。一旦检测到,传感器就可以估计大致方向(标头)及与信标的距离(近程)。例如可以对机器人编程来玩捉迷藏,使用远程红外信标作为搜索目标。标头值在-25到25之间,0表示信标在红外传感器正前方。近程值在0到100之间。

controlor
Python编程

# 连接红外传感器
irsens = infrared_sensor()

# 设定距离模式
irsens.mode = 'IR-PROX'
# 获得传感器扫描的具体 距离范围0~100
distance = irsens.value()

# 设定信标模式 需将遥控器中间的按钮按下 遥控器亮灯
irsens.mode = 'IR-SEEK'
# 获得角度范围-25~25 左边为负 中间为0 右边为正
angle = irsens.value(0)
# 获得距离范围0~100
distance = irsens.value(1)
# 遥控器可以通过拨片切换4个不同位置 irsens.value(0-8)代表4个位置的读值

# 设定遥控模式
irsens.mode = 'IR-REMOTE'
# 遥控器可以通过拨片切换4个不同位置 irsens.value(0-3)代表4个位置的控制值
# 获得所按下的遥控器按键 0-3分别代表4个按键
button = irsens.value(0)

 

ev3dev手册[一]-介绍

ev3dev language bindings

ev3dev语言封装

This repository stores the utilities and metadata information for the ev3dev-lang family of libraries. These libraries are easy-to-use interfaces for the APIs that are available on ev3dev-based devices.

这套存储仓包含了为ev3dev-lang函数库提供支持的工具和数据信息。这些函数库可以容易的通过API接口应用于基于ev3dev设备的项目中。

The complete documentation is hosted at http://ev3dev-lang.readthedocs.org.

完整的手册发布在http://ev3dev-lang.readthedocs.org

We support multiple libraries for various programming languages using a centralized “specification” which we keep updated as kernel changes are made. We don’t have the actual library code here (see below) – instead we use this repo to facilitate the maintenance of our bindings.

为了满足对不同编程语言提供多种库函数的支持,我们使用一套统一的“规范”,并且当核心内容变更时保持更新。我们不会实际编写库函数代码(如下),而是使用这套存储仓维护我们的语言封装。

We currently support libraries for the following languages:

当前提供函数库支持的编程语言如下:

Each binding is written based on our central spec, so each has a uniform interface which is kept close to the ev3dev API surface while still encouraging language-specific enhancements.

每种语言封装的编写都基于统一规范,因此ev3dev接口内容都是唯一的,同时鼓励继续增强这种语言规范的支持。

 

源代码及项目地址:https://github.com/rhempel/ev3dev-lang-python

安装

首先安装依赖包:

apt-get install libboost-python1.55.0 python-setuptools python-pil

这些安装包应该足够用了,但是如果你想把他们安装到你的主机上(比如当你想用IDE去选择库的时候),或者从源代码编译函数库,还得安装libboost-python1.55-dev

现在安装ev3dev模块:

easy_install -U python-ev3dev

模块版本升级同样使用这条指令。

如何使用

项目提供的演示程序地址:https://github.com/ddemidov/ev3dev-lang-python/tree/master/demo

使用手册原文地址:http://ev3dev-lang.readthedocs.io/en/latest/index.html

下面我们来看一个简单的演示程序,程序实现驱动一个连接在A端口的大型EV3马达。

>>> import ev3dev #加载ev3dev模块
>>> m = ev3dev.large_motor('outA') #读取A端口的大型马达
>>> m.connected #确认马达已经驱动
True
>>> m.run_timed(time_sp=3000, duty_cycle_sp=75) #让马达以75%占空比的速度运行3000毫秒(3秒)

远程操作

有两种方式可以在EV3上面运行远程的python程序(就是说不用一直ssh登录到EV3里面):

第一种方法

安装Ipython Notebookhttp://ipython.org/):

apt-get install ipython-notebook

然后从主机登录notebook服务器:

https://coderwall.com/p/ohk6cg/remote-access-to-ipython-notebooks-via-ssh

Laurens Valk对这种操作方式做了个不错的说明:http://robotsquare.com/2014/06/12/linux-ev3/

然而,IPython进程对EV3来说太占系统资源了,运行起来很耗时。

第二种方法

使用RPyCPython呼叫)模块:

pip install rpyc

EV3机器人和远程主机都需要安装这个模块。这样,当EV3上运行rpyc_classic.py启动RPyC服务后,就可以从主机远程连接EV3了,主机上运行:

>>> import rpyc
>>> c = rpyc.classic.connect("192.168.137.3")#connect()函数的参数是EV3ip地址。

连接建立后,可以在主机上加载ev3dev模块:

>>> ev3dev = c.modules.ev3dev
>>> m = ev3dev.large_motor('outA')
>>> m.connected
True
>>> m.run_timed(time_sp=3000, duty_cycle_sp=75)

尽管是从其他设备上通过RPyC服务运行的python代码,但代码内容跟ssh登录到EV3里面是一样一样的。这种方式更适用于内部开发或运行比较复杂的程序。

关于ev3dev的详细介绍手册,可以继续查看。

触碰传感器

触碰传感器介绍

触碰传感器是一种模拟传感器,可以检测红色按钮是否被按下或松开,功能非常简单但很实用,可以对传感器编程实现功能包括:按下、松开或碰撞(按下后再松开)。

touch sensor

利用触碰传感器,机器人可以像盲人那样观察世界,伸出一只“手”触碰到物体后作出反应。也可以将传感器紧贴着地面搭建(保持传感器被按下),当它要离开桌子边缘时(传感器被弹开)作出动作  (停止前进)。

python编程

触动传感器只有“按下”和“松开”两种状态,将触碰传感器安装到EV3任意输入端口上(1-4),使用ev3dev.touch_sensor()函数连接传感器,这里不用指定端口程序可以自动搜索到传感器。

>>> from ev3dev import *
>>> ts = touch_sensor() #连接触碰传感器

这样,ts就是我们的传感器了,可以使用connected()确认是否连接成功

>>> ts.connected()
Tru

python实用01表示触动传感器的两种状态,0代表“松开”,1代表“按下”,使用ev3dev.value()函数读取状态值

让我们来试试,现在不动传感器,让它保持自然弹起的状态,查看传感器ts的返回值:

>>> ts.value()
0

现状我们用一个手按住传感器,再看一下:

>>> ts.value()
1

光传感器

光传感器可以通过检测窗检测到颜色或光强度,光传感器可设定三种模式:环境光模式、反射光模式和颜色模式。

color sensor

环境光模式

光传感器在环境光强度模式下不发光(其实是蓝色的),能够测量从周围环境进入到检测窗的光强度,如太阳光或手电筒的光束,测量范围从0(极暗)到100(极亮)。利用传感器识别环境光的能力可让机器人完成诸如早晨光闹钟,或在灯灭时停止行动等动作。

color sensor ambient

反射光模式

光传感器在反射光强度模式下发出红色的光,能够测量从红灯(即发光灯)反射回来的光强度,测量范围从0(极暗)到100(极亮)。利用传感器识别可见光的能力可让机器人完成诸如在白色表面上移动直到检测到黑线或颜色识别卡的动作等。

color sensor reflect

颜色模式

光传感器在颜色模式下发出彩色的光,EV3官方编程软件可识别七种颜色:黑色、蓝色、绿色、黄色、红色、白色、棕色,和无颜色。利用传感器区别不同颜色的能力可让机器人完成诸如分类彩色球的工作,让机器人说出各种检测到的颜色,或见到红色即停止动作等。

color sensor color

光传感器特性

光传感器采样频率为1 kHz。当处于“颜色模式”或“反射光强度模式”时,为求最精确传感器必须角度正确,尽量靠近但不接触到正在检测的物体表面。另外,在颜色模式下虽然官方编程软件预设七种颜色,但在我们的python库里面在颜色模式下是可以将R、G、B三种颜色值都读出来,就是说可以识别更多的颜色,以及提高识别准确度。

程序设计

分别针对三种模式,我们看看实际的测量值读取结果。首先将光传感器连接在EV3主机1-4的任意接口上,这里我们连接到1口。

ev3dev可以自动匹配到所连接的传感器,我们只需要调取color_sensor()这个函数就可以启动、连接光传感器。

>>>from ev3dev import *
>>>cs = color_sensor()

刚才说的光传感器有三种模式,使用modes,可以列举出ev3dev支持的所有模式。

>>>cs.modes

主要的几种模式分别对应:COL-AMBIENT(环境光模式)、COL-REFLECT(反射光模式)、COL-COLOR(颜色模式)、RGB-RAW(RGB模式)。

环境光模式

使用mode对象,一方面可以读取当前的模式,另一方面可以写入模式名称进行模式转换。将光传感器改为环境光模式:

>>>cs.mode = 'COL-AMBIENT'

接下来可以通过value()函数读取此时的测量值。

>>>cs.value()

你会发现,当用手捂住时可以看到数值接近0,而冲着亮的地方数值会变大。

反射光模式

首先改变传感器模式,此时会发现传感器发出的光变成了红色。在这种模式下进行测量时,传感器要尽量贴近测量物体才能够准确。

>>>cs.mode = 'COL-REFLECT'
>>>cs.value()

当我们对着白色区域和黑色区域进行测量时,会发现数值出现明显的变化。白色区域读值更加接近100,黑色区域读值更加接近0。

color sensor reflect 2

彩色模式

在彩色模式下读取测量值,会发现此时的读值只是0-7的数字,正如前文所说,数字分别对应的无颜色和七种颜色。

>>>cs.mode = 'COL-COLOR'
>>>cs.value()

这8个数字对应的颜色分别是:

  • 0:无颜色
  • 1:黑色
  • 2:蓝色
  • 3:绿色
  • 4:黄色
  • 5:红色
  • 6:白色
  • 7:棕色

现在我们对着魔方的蓝色块测试,获得结果是:2。

color sensor color 1

RGB模式

显然,在颜色模式下,有的时候7种颜色并不能满足我们的需求,比如当我们去检测红色和橘色时,测量的结果都是5(红色)。RGB模式会让我们获得的测量结果的更准确。

当转换为RGB模式后,会发现此时的测量值有三个,反馈测量值数量可以通过num_values对象获得。

>>>cs.mode = 'RGB-RAW'
>>>cs.num_values

这三个反馈值分别对应的R值、G值、B值,可以通过value(0), value(1), value(2)分别获得。

>>>for i in range(3):
...  print cs.value(i)

现在我们来看对魔方上面红色和橘色进行测量的结果:

红色

红色

橘色

橘色

  • 红色:255 30 17
  • 橘色:229 42 18

非常接近,这也难怪颜色模式下区分不开这两种颜色。如果采用RGB模式,我们可以重新定义各个颜色的识别范围,从而将他们进行区分。理论上,RGB模式能够识别的颜色数量为:256 x 256 x 256 = 16777216种。

EV3马达

Mindstorms EV3自带了两种马达,分别是大型(2个)和中型(1个),两种马达都可以编程实现启动或关闭,进行速度控制、运行时间控制以及旋转角度控制。

大型马达

大型马达是一个功能强大的智能马达(伺服电机),为什么说智能呢,因为他不光可以接受转动指令,还能够将转动情况反馈给控制器。大型马达拥有一个内置转速传感器,分辨率为1°,即每转动一下相当于1°(一圈是360°),可实现精确控制。

大型马达

大型马达

大型马达是EV3机器人的基础驱动力,通常我们用2个大型马达组合使用,为机器人实现移动、转向、履带式移动等动作。

中型马达

中型马达与大型马达类似,也包含一个内置转速传感器(分辨率同样为1°),但是更小更轻,这也意味着它比大型马达转得更快。

中型马达

中型马达

两种马达对比

  • 大型马达转速为160-170RPM(每分钟转160-170圈,我在实际测试的时候是120RPM应该跟是否空转也有关系),旋转扭矩为 20 Ncm,失速扭矩为 40 Ncm。特征:速度低但更强劲。
  • 中型马达转速为240-250RPM(转/分钟),旋转扭矩为 8 Ncm,失速扭矩为 12 Ncm。特种:速度更快但劲小一些。

程序设计

程序名称:马达转速测试程序

功能:测试马达运转起来时候的转速

(To Be Continue…)