本文为 virtual world challenge pack 中的基本运动(BASIC MOVEMENT) 中的 “50cm
Challenge”, 如图 1 所示.要求从 A 点或 B 点出发让 robot 前进 50cm.
此挑战使用的 robot 为 “Clawbot IQ”, 基本配置如图 2 所示.
由于场地没有任何物体, 因此没有办法使用距离传感器,
只能通过简单计算轮子需要转动的圈数.
#pragma config(StandardModel, "Clawbot IQ With Sensors")
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
task main()
{
const float diameter = 6.4; // the wheel's idameter, cm
const float distance = 50; // forward distance, cm
const float one_circle = PI * diameter; // the wheel's circumference, cm
float rotation_count = distance / one_circle;
rotation_count += 0.1; // adjusting
forward(rotation_count, rotations);
}
运行结果如图 3 所示.
本例子主要训练车子速度, 运行时间, 和运行距离之间的感觉.