LeJOS OSEK C++ Library v0.4
API
Robert W. Kramer,
[Translated
By Li Yan]
声明
Lejos OSEK C++ 库和该文档版权归属于 © 2008 Robert W.Kramer.。它遵循Mozilla Public License(version
1.0) 许可证。你可以在 http://www.mozilla.org/MPL/ 得到许可证的复本。
探讨
LeJOS OSEK C++ 库提供 一系列应用Lego Mindstorms NXT 的
伺服马达和传感器的抽象类,以及对LeJOS OSEK软件的修改使得C++程序正常编译运行。
当前C++函数(v0.4) 的版本已实现如下功能:
这是库和支持代码的第一个版本。因此,它可能存在一些bug。(货既售出概不退换)注意,您的测试结果可能有所不同,因此所有的免责声明都适用于这个类库。
如果您遇到bug,请发邮件给作者snowyow1000@gmail.com,描述bug。
已知问题:
致谢
作者感谢以下帮助这个项目实现的人员:
API
可用类
|
类名 |
头文件 |
|
AccelSensor |
AccelSensor.h |
|
ColorSensor |
ColorSensor.h |
|
CompassSensor |
CompassSensor.h |
|
LightSensor |
LightSensor.h |
|
SonarSensor |
SonarSensor.h |
|
SoundSensor |
SoundSensor.h |
|
TouchSensor |
TouchSensor.h |
|
PrototypeSensor |
PrototypeSensor.h |
|
Motor |
Motor.h |
可用的枚举量
|
符号 |
值 |
描述 |
|
S1 |
0 |
Sensor port 1 |
|
S2 |
1 |
Sensor port 2 |
|
S3 |
2 |
Sensor port 3 |
|
S4 |
3 |
Sensor port 4 |
|
MOTOR_A |
0 |
Motor port A |
|
MOTOR_B |
1 |
Motor port B |
|
MOTOR_C |
2 |
Motor port C |
注意:
加速度传感器(AccelSensor)方法
|
方法原型 |
描述 |
|
AccelSensor(unsigned
char _port) |
构造函数 |
|
~AccelSensor( ) |
析构函数 |
|
void
activate(void) |
打开传感器,给传感器供电。 |
|
void passivate(void) |
关闭传感器, 关闭传感器电源。 |
|
short int getXAccel(void) |
返回x轴方向的加速度。 |
|
short int getYAccel(void) |
返回y轴方向的加速度。 |
|
short int getZAccel(void) |
返回z轴方向的加速度。 |
|
void getAccel(short int axes[3]) |
返回三个轴向的加速度。 |
|
void getAccel(short int &x, short int &z) |
返回三个轴向的加速度。 |
|
bool isActivated(void) |
返回true 如果传感器有电。 |
注意:
颜色传感器(ColorSensor)方法
|
方法原型 |
描述 |
|
ColorSensor(unsigned
char _port) |
构造函数 |
|
~ColorSensor( ) |
析构函数 |
|
void
activate(void) |
打开传感器 |
|
void passivate(void) |
关闭传感器 |
|
bool isActivated(void) |
返回true 如果传感器有电。 |
|
unsigned char
getColorNumber(void) |
返回 颜色数 |
|
unsigned getColorIndex(void) |
返回6-bit值,32-bit R/G/B 层。 |
|
void getColor(unsigned short rgb[3]) |
获取颜色数据。 |
|
void getColor(short int &r, short int &g, short int &b) |
获取颜色数据。 |
|
short int getRed(void) |
获取红色阶。 |
|
short int getGreen(void) |
获取绿色阶。 |
|
short int getBlue(void) |
获取蓝色阶值。 |
|
void getRawColor(unsigned short rgb[3]) |
获取原始颜色数据。 |
|
void getRawColor(short int &r, short
int &g, short
int &b) |
获取原始颜色数据。 |
|
short int getRawRed(void) |
获取原始红色阶值。 |
|
short int getRawGreen(void) |
获取原始绿色阶值。 |
|
short int getRawBlue(void) |
获取原始蓝色阶值。 |
|
void getNormalizedColor(unsigned short rgb[3]) |
获取标准颜色数据。 |
|
void getNormalizedColor(short
int &r, short
int &g, short
int &b) |
获取标准颜色数据。 |
|
short int getNormalizedRed(void) |
获取标准红色阶值。 |
|
short int getNormalizedGreen(void) |
获取标准绿色阶值。 |
|
short int getNormalizedBlue(void) |
获取标准蓝色阶值。 |
注意:
陀螺仪传感器(CompassSensor)方法
|
方法原型 |
描述 |
|
CompassSensor(unsigned
char _port) |
构造函数 |
|
~CompassSensor( ) |
析构函数 |
|
void
activate(void) |
打开传感器 |
|
void passivate(void) |
关闭传感器 |
|
bool isActivated(void) |
返回true,如果传感器有电。 |
|
short int getHeading(void) |
返回方向角度。 |
|
void beginCalibration(void) |
将传感器置于校准模式 |
|
bool endCalibration(void) |
将传感器置于普通模式。返回true 如果校准成功。 |
注意:
光感器(LightSensor )方法
|
方法原型 |
描述 |
|
LightSensor( unsigned
char _port,bool _lamp=true) |
构造函数,默认打开灯 |
|
~LightSensor( ) |
析构函数 |
|
void setLamp(bool _lamp) |
打开传感器灯当且仅当_lamp 为 true |
|
bool isLit(void) |
返回true 如果传感器有电。 |
|
short int getValue(void) |
返回标准光级别值。 |
|
short int getRawValue(void) |
返回原始光级别值。 |
注意:
声纳传感器(SonarSensor)方法
|
|
描述 |
|
SonarSensor(unsigned
char _port) |
构造函数 |
|
~SonarSensor( ) |
析构函数 |
|
void
activate(void) |
打开传感器 |
|
void passivate(void) |
关闭传感器。 |
|
bool isActivated(void) |
返回true 如果传感器有电。 |
|
short int getDistance(void) |
返回在传感器视觉区域最近物体的距离。 |
注意 :
声感器(SoundSensor)方法
|
方法原型 |
描述 |
|
SoundSensor(unsigned
char _port,bool _dba=false) |
构造函数。默认关闭dBA模式 |
|
~SoundSensor( ) |
析构函数。 |
|
bool isDBA(void) |
返回true 如果传感器在dBA模式下 |
|
short int getValue(void) |
返回标准声音级别值。 |
|
short int getRawValue(void) |
返回原始声音级别值。 |
注意:
触感器(TouchSensor) 方法
|
方法原型 |
描述 |
|
TouchSensor(unsigned
char _port) |
构造函数。 |
|
~TouchSensor( ) |
析构函数。 |
|
bool isPressed(void) |
返回true 如果传感器被按。 |
|
short int getRawValue(void) |
返回原始值。 |
注意:
原型传感器(PrototypeSensor )方法
|
方法原型 |
描述 |
|
PrototypeSensor( unsigned
char _port, |
构造函数。 |
|
~PrototypeSensor( ) |
析构函数。 |
|
void setSampleRate(unsigned int
rate) |
设置采样周期 (4 ≤ rate ≤ 100). |
|
void setDigitalPorts(unsigned char dir) |
设置数字端口的方向。 |
|
void writeDigitalData(unsigned char data) |
向任意数字端口写入bit数据配置为输出。 |
|
unsigned char
readDigitalData(void) |
从任意数据端口读取bit数据配置为输入。 |
|
void readAnalogData(unsigned int analogPorts[5]) |
读取所有ADC端口。 |
|
unsigned int readAnalogData(int analogPort) |
读取给定的ADC端口。 |
注意:
伺伏马达(Motor)方法
|
方法原型 |
描述 |
|
Motor(unsigned
char _port) |
构造函数。 |
|
~Motor( ) |
析构函数。 |
|
void
forward(void) |
启动马达向前运动。 |
|
void
backward(void) |
启动马达向后运动。 |
|
void reverseDirection(void) |
方向当前马达方向。 |
|
void
stop(void) |
使用刹车停止马达。 |
|
void flt(void) |
不使用刹车停止马达。 |
|
int getTachoCount(void) |
返回转动角度值。 |
|
void resetTachoCount(void) |
重置转动角度值为0。 |
|
void setPower(int _power) |
设置马达动力。 |
注意:
其他函数
|
原型 |
描述 |
|
void
sleep(unsigned int duration) |
任务休眠将持续几毫秒。任务中止,允许其他任务执行。 |
注意: .