[新品上市]Line Follower Sensor (LineLeader-v2) EV3/NXT都適用

 

 

 

 

 

 

 

 

 

http://www.mindsensors.com/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=111

LineLeaderw400

MindSensors 的當家產品:Line Follower Sensor 推出新款了,EV3、NXT都可以使用。對應的程式環境也很完整,除了樂高官方環境之外,LabVIEW、NXC與 RobotC 也都直接有函式庫可以用。

“人”如其名,它就是用來解決各種麻煩的彎道:U型彎,直角彎與左右混合彎等等。這些都會讓傳統的二階段(if/else)循跡法很容易出錯。請參考 CAVEDU 的 [實做比例控制方法之循跡機器人],頁面中有 EV3 與NXC的程式碼可以下載。

簡單來說,它是八個光感測器的集合體,除了個別的讀數之外,還內建了 PID 控制器,只要調整Kp, Ki, Kd 等參數就可以了,剩下就讓感測器自己去算吧。還能根據哪些光感測器被遮斷來判斷感測器與軌跡的相對位置(偏左、偏右與剛好在中間),很方便呢。

有興趣的朋友請留言、來信或來電洽詢。 service@cavedu.com / 02 23062900

來看執行影片,主機是用 Arduino + NXShield 擴充板

這是NXT的版本

也可以獨立取得各個光感測器的讀數

也把MindSensors 提供的 NXC 範例程式放上來給大家參考

const byte SensorPort  =  IN_1;
#define ADDR     0x02
#include "LL-lib.nxc"

char last_steering = 0;

task RunAlongLine()
{
	char steering, result;
	int c_speed, a_speed;

  while (true ) {

    steering = LL_ReadSteering(SensorPort, ADDR);

		steering = steering / 2;
		c_speed = 50 + steering;
		a_speed = 50 - steering;

		if ( c_speed > 100 ) c_speed = 100;
		if ( a_speed > 100 ) a_speed = 100;
		if ( c_speed < -100 ) c_speed = -100;
		if ( a_speed < -100 ) a_speed = -100;

		/*
		// print line status
		//
		// WARNING: TextOut functions take too much CPU
		// causing robot to behave sluggish
		//
    result = LL_Read(SensorPort, ADDR, LL_READ_RESULT);
    msg = "bin:             ";
    x = LL_format_bin(result);
    msg = StrReplace(msg, 4, x);
    TextOut(0, LCD_LINE1, msg, false);

		// print power
    msg = "p:               ";
    x = NumToStr(c_speed);
    msg = StrReplace(msg, 2, x);
    x = NumToStr(a_speed);
    msg = StrReplace(msg, 7, x);
    TextOut(0, LCD_LINE2, msg, false);

    msg = "steering:             ";
    x = NumToStr(steering);
    msg = StrReplace(msg, 10, x);
    TextOut(0, LCD_LINE3, msg, false);
		*/

		//c_speed = c_speed /2;
		//a_speed = a_speed /2;
		OnFwdReg(OUT_A, a_speed, OUT_REGMODE_SPEED);
		OnFwdReg(OUT_C, c_speed, OUT_REGMODE_SPEED);
  }

}

task main ()
{

  string msg;
  string x;
	int s, i;

  byte message[];
  unsigned byte buf[20];
  int count, l;
  byte nByteReady = 0;

  SetSensorLowspeed(SensorPort);
  Wait(10);

	/**
	 * The following parameters (kp,ki,kd) are specific
	 * to your robot. They will change based on robot design,
	 * it's traction with mat, weight, wheel size, wheel spacing,
	 * sensor distance from wheels, etc, etc.
	 *
	 * Tune them as best as you can for your robot.
	 * Note, in general,  ki will be zero.
	 *
	 * If you wish to learn more about Kp, Ki, Kd, please
	 * read the user guide.
	 * An excellent explanation of PID is also offered at:
	 * http://en.wikipedia.org/wiki/PID_controller
	 *
	 */

	LL_Write_KP(SensorPort, ADDR, 25, 32);
	LL_Write_KI(SensorPort, ADDR, 0, 200);
	LL_Write_KD(SensorPort, ADDR, 8, 32);

	StartTask (RunAlongLine);

}
NXC LL

About CAVEDU 阿吉 - 雜工 (2520 Articles)
CAVEDU 教育團隊 打雜
Contact: Website

Leave a comment

Your email address will not be published.


*