找回密码
 马上注册

QQ登录

只需一步,快速开始

查看: 6115|回复: 11

求助:NXC编程后超声波传感器不起作用

[复制链接]
发表于 2010-11-1 18:58:06 | 显示全部楼层 |阅读模式
如以下的一个最简单的程序:
task main()
{
  SetSensorLowspeed(IN_1);
if (IN_1<20)
{
  OnFwd(OUT_A, 60);
  Wait(600);
}
}
在检查和下载时都没有问题,可是运行时超声波传感器就像不起作用一样,即使把传感器对着天花板,没有任何障碍电机也会自动运行。
其他的传感器这样编写都没有问题,不知是不是定义传感器时有特殊要求。
初学者,请多帮忙,谢谢!
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
发表于 2010-11-1 19:22:21 | 显示全部楼层
task main()
{
  SetSensorLowspeed(IN_1);
if (SENSOR_1<20)
{
  OnFwd(OUT_A, 60);
  Wait(600);
}
}
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

发表于 2010-11-1 19:30:12 | 显示全部楼层
.................没循环...应该是
while(1)
{
.......(你程序的内容)
}
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

 楼主| 发表于 2010-11-1 19:36:27 | 显示全部楼层
谢谢,回复的这么快,刚才着急写错了,我们用的时候是按if (SENSOR_1<20)写的,可是执行的时候还是没起作用
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

 楼主| 发表于 2010-11-1 19:37:46 | 显示全部楼层
就是想实现后车近了,让前车自动跑起来的效果
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

 楼主| 发表于 2010-11-1 19:52:03 | 显示全部楼层
另外,在看别人的程序时发现很多程序里面都写SensorUS(IN_1) ,这个和写Sensor(IN_1) 或SENSOR_1有什么区别吗
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

发表于 2010-11-1 21:48:58 | 显示全部楼层
3楼写了,缺少循环,我也写块了,没有看清楚,你自己补上吧
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

 楼主| 发表于 2010-11-1 23:14:14 | 显示全部楼层
好的,十分感谢
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

发表于 2010-11-2 14:59:36 | 显示全部楼层
回复 xiaoyu9555 的帖子

byte SensorUS (const byte port) [inline]
Read ultrasonic sensor value. Return the ultrasonic sensor distance value. Since an ultrasonic sensor is an I2C digital sensor its value cannot be read using the standard Sensor(n) value. The port must be configured as a Lowspeed port before using this function.
Parameters:
port The port to which the ultrasonic sensor is attached. See the Input port constants group. You may use a constant or a variable.
Returns:
The ultrasonic sensor distance value (0..255)
Examples:
ex_sensorus.nxc.

void SetSensorLowspeed (const byte & port, bool bIsPowered = true)[inline]
Configure an I2C sensor. Configure the sensor on the specified port as an I2C digital sensor for either powered (9 volt) or unpowered devices.
Parameters:
port The port to configure. See Input port constants. bIsPowered A boolean flag indicating whether to configure the port for powered or unpowered I2C devices. The default value for this optional parameter is true.

来源:NXT_Guide.pdf
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

发表于 2010-11-2 15:04:25 | 显示全部楼层
void SetSensorLowspeed (const byte & port, bool bIsPowered = true)
[inline]
Configure an I2C sensor. Configure the sensor on the specified port as an I2C digital sensor for either powered (9 volt) or unpowered devices.
Parameters:
port The port to configure. See Input port constants. bIsPowered A boolean flag indicating whether to configure the port for powered or unpowered I2C devices. The default value for this optional parameter is true.

byte SensorUS (const byte port) [inline]

Read ultrasonic sensor value. Return the ultrasonic sensor distance value. Since an ultrasonic sensor is an I2C digital sensor its value cannot be read using the standard Sensor(n) value. The port must be configured as a Lowspeed port before using this function.
Parameters:
port The port to which the ultrasonic sensor is attached. See the Input port constants group. You may use a constant or a variable.
Returns:
The ultrasonic sensor distance value (0..255)
来源:NXC_Guide.pdf
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

发表于 2011-8-11 10:38:00 | 显示全部楼层
学习一下。
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

发表于 2013-5-6 11:15:36 | 显示全部楼层
nanzheng 发表于 2010-11-2 14:59
回复 xiaoyu9555 的帖子

byte SensorUS (const byte port)

我将取到的超声波值显示在屏幕上了,但显示的数很奇怪,越近数越大,越远数越小。怎么能变成厘米?
  1. task main()
  2. {
  3.   SetSensorUltrasonic(IN_4);
  4. while(1)
  5.   NumOut(20,20,SensorUS(IN_4));
  6. }

  7. }
复制代码
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|中文乐高 ( 桂ICP备13001575号-7 )

GMT+8, 2024-4-29 01:11 , Processed in 0.283696 second(s), 18 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表