Hackathon日记 WAIR Robotics

6月24日

[toc]

机器人law 1:不伤害人类

提问了“不伤害人类”是怎么实现的,助教的回答是目前制定了法律或规则草案,但是并不健全,现有的措施是让机器人遇到障碍物躲开。

感觉现在的机器人并没有对应的软硬件保证不伤害人类。

Webots R2021a

我们的任务基本上是用c++控制机器人走完路线和躲避障碍,初始化的代码已经写好了。貌似我们只需要完成while loop就好。有点像上学期c++实验的实用版。

组队

耶!如愿以偿和姐妹们组队了,开始干活!(一共十三个人参赛,五个都是中国人😂)

Main Task: Line Following

已经给出了wbt文件,可直接在webots中加载机器人和机器人所在的世界。我们需要用c++编写controller控制机器人的行为,具体点说是根据机器人身上传感器的数据控制机器人的运动。

机器人有两个距离传感器(红)和三个红外线传感器(黑),距离传感器用来躲避障碍物,红外线传感器用来识别轨道。四个轮子的速度可以被控制。

我们的任务是补全while loop:

while (robot->step(TIME_STEP) != -1) {
// print current status
std::cout<<"while loop "<<std::endl;
ir_right_val = ir_right->getValue();
ir_mid_val = ir_mid->getValue();
ir_left_val = ir_left->getValue();
std::cout<<"ir-right : "<<ir_right_val<<std::endl;
std::cout<<"ir-mid : "<<ir_mid_val<<std::endl;
std::cout<<"ir-left : "<<ir_left_val<<std::endl;

ds_right_val = ds_right->getValue();
ds_left_val = ds_left->getValue();
std::cout<<"right distance : "<< ds_right_val <<std::endl;
std::cout<<"left distance : "<< ds_left_val <<std::endl;
...}

在while循环中用if结构,首先列出车停下的情况:在轨道外/前方有障碍物

if (
((ir_mid_val<20)&&(ir_left_val<20)&&(ir_right_val<20)) || 
ds_right_val < 400 || 
ds_left_val < 400) 
{ left_front_motor -> setVelocity(0.0);
right_front_motor -> setVelocity(0.0);
left_rear_motor -> setVelocity(0.0);
right_rear_motor -> setVelocity(0.0);
}
...}

之后通过左右传感器识别到的颜色判断左右转

else if (ir_left_val>600){
    left_front_motor -> setVelocity(0.1);
    right_front_motor -> setVelocity(4.5);
    left_rear_motor -> setVelocity(0.1);
    right_rear_motor -> setVelocity(4.5);
    }
    
    else if(ir_right_val>600){
    left_front_motor -> setVelocity(4.5);
    right_front_motor -> setVelocity(0.1);
    left_rear_motor -> setVelocity(4.5);
    right_rear_motor -> setVelocity(0.1);
    }

默认情况是往前直走

 else{
    left_front_motor -> setVelocity(1.0);
    right_front_motor -> setVelocity(1.0);
    left_rear_motor -> setVelocity(1.0);
    right_rear_motor -> setVelocity(1.0);}

6月25日

Bonus Task

留下评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据