上星期和上上星期的实验是LEGO机器人

嘛说是机器人,其实准确来说更像是车了啦wwww简单来说就是双马达双驱动轮的自动追踪(?)设备,地图上用黑线标出道路,机器人利用前方的两个探测器检测出黑线并指示车轮沿着黑线走,中途还会遇到一些障碍物w嘛其实基本原理很简单,第一周主要是自由利用各种各样的LEGO提供的零件组装成自己喜欢的样式,第二周输入追踪程序,追踪程序使用的是古典自动控制常用的PID控制(利用当前量、微分量和积分量进行的控制)www嘛说实话最可惜的就是两节课的时间实在是太少了实在是没做出什么好东西,8过勉强还是自动跑完了整个赛道;

总之先晒照片




再晒代码wwww
/* sample.nqc
* nqc -Susb -d sample.nqc
*/

#define LEFT_SENSOR SENSOR_3
#define RIGHT_SENSOR SENSOR_1

#define LEFT_DRIVE OUT_C
#define RIGHT_DRIVE OUT_A

#define VELOCITY 5
#define OFFSET 0
#define K 50 /* Proportion gain */
#define KI 0 /* Integral gain */
#define KD 50 /* Differential gain */

#define THRESHOLD 45

sub init_sensor()
{
SetSensorType(LEFT_SENSOR, SENSOR_TYPE_LIGHT);
SetSensorMode(LEFT_SENSOR, SENSOR_MODE_PERCENT);

SetSensorType(RIGHT_SENSOR, SENSOR_TYPE_LIGHT);
SetSensorMode(RIGHT_SENSOR, SENSOR_MODE_PERCENT);
}

sub Stop()
{
Off(RIGHT_DRIVE);
Off(LEFT_DRIVE);
}

void set_velocity(int x)
{
int l, r;

l = -x + VELOCITY;
r = x + VELOCITY;

if (l > 7) {
l = 7;
}
if (r > 7) {
r = 7;
}
if (l >= 0 && r >= 0) {
SetPower(LEFT_DRIVE, l);
SetPoewr(RIGHT_DRIVE, r);
OnFwd(LEFT_ERIVE + RIGHT_DRIVE);
} else if (l >= 0 && r < 0) { Off(RIGHT_DRIVE); SetPower(LEFT_DRIVE, l); OnFwd(LEFT_DRIVE); } else if (l < 0 && r >= 0) {
Off(LEFT_DRIVE);
SetPower(RIGHT_DRIVE, r);
OnFwd(RIGHT_DRIVE);
} else {
Off(LEFT_DRIVE + RIGHT_DRIVE);
}
}

task trace()
{
int y;
int e, ei, ed, e1;
int p, i, d;

ei = 0;
e1 = 0;
while (true) {
e = RIGHT_SENSOR - LEFT_SENSOR + OFFSET;

ei += e;

ed = e - e1;
el = e

p = (K * e) / 100;
i = (KI * ei) / 100;
d = (KD * ed) / 100;

y = p + i + d;

set_velocity(y);

Wait(3);
}
}

task search()
{
while(true) {
if (LEFT_SENSOR > THRESHOLD && RIGHT_SENSOR > THRESHOLD) {
stop trace;
SetPower(LEFT_DROVE + RIGHT_DRIVE, 2);
OnRev(LEFT_DRIVE + RIGHT_DRIVE);
Wait(10)
start trace;
}
Wait(5);
}
}

task main()
{
init_sensor();
start trace;
start search;
}

p.s. 话说昨天Elsie的衣服到了\(^o^)/于是咱虽然忙的连处理腋毛的时间也没有8过还是总之先试穿了一下——结论:M的衣服对于偶来说腰都有些大了\(^o^)/那个腰带总是垮;而且Elsie的那件长筒袜大腿那个位置也总会掉

p.s.2 预告:12月3号星期六去看K-ON电影的首场\(^o^)/

Author: 星野恵瑠

Mac user, Niji-Ota, Chinese, Now working in Japan at MAGES. Inc., Future's aim is that one day my name can be listed in Wikipedia

13 thoughts on “上星期和上上星期的实验是LEGO机器人”

  1. 嘛,下次記得要買S哦
    胸。。。盯~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  2. 性别什么的已经阻止不了我了!!!

    不过怎么感觉没有放松?肌肉线条很明显哦~

    话说昨天看到了乐高哈利波特的源,下面一大堆人吐槽魔杖——【冬青木凤凰羽毛的…擀面杖?!】

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

(;;) (:D) (!!!!) (……) (^o^;) (==) (OoO) (=v=o) more »Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).