这个设计也许还周到,你也可以使用其他部件等。但是如果你是像上面所述的方法一样连接的,
下面是一些小提示,作为你开始对机器人编程的参考。
在你的编辑器内输入(或者复制-粘贴)以下代码,连好机器人后按下F5 +++ main: readadc 1, b1 ' takes the voltage returned to analogue pin 1, and puts it into variable b1
debug ' this draws out all variables to the editor. Set it to “Byte” if it is on “ Word”
goto main +++ 现在,把你的手伸到机器人头的前面,注意变量b1的变化。你可以用你已有的只是快速的判断出
将会发生什么。
现在我建议你将机器人放在火柴盒上,这样轮子就可以开始转动。
在你的编辑器内输入(或者复制-粘贴)以下代码,连好机器人后按下F5 +++ high 4 low 5 +++ 其中一个轮子会转向一个方向,是不是向前转呢?那么,这就是轮子前进的指令。
如果要让轮子向后转,你可以试试: +++ low 4 high 5 +++ 要转动另一个轮子: high 6 low 7 (或者其他向反方向转动的方法)
伺服电机你已经试过了。
自始至终,转到一边是: servo 0, 75 转到另一边是: servo 0, 225
转到中间: servo 0, 150 这里有一个小程序,它将使机器人转圈,在障碍物前停下来,巡视四周确定最好的路,转弯和大
胆的向前进。 +++ Symbol dangerlevel = 70 ' how far away should thing be, before we react?
symbol turn = 300 ' this sets how much should be turned
symbol servo_turn = 700 ' This sets for how long time we should wait for the servo to turn (depending on it′s speed) before we measure distance main: ' the main loop
readadc 1, b1 ' read how much distance ahead
if b1 < dangerlevel then
gosub nodanger ' if nothing ahead, drive forward
else
gosub whichway ' if obstacle ahead then decide which way is better
end if
goto main ' this ends the loop, the rest are only sub-routines
nodanger:' this should be your combination to make the robot drive forward, these you most likely need to adjust to fit the way you have wired your robots motors
high 5 : high 6 : low 4 : low 7
return
whichway:
gosub totalhalt ' first stop! 'Look one way:
gosub lturn ' look to one side
pause servo_turn ' wait for the servo to be finished turning
gosub totalhalt
readadc 1, b1 'Look the other way:
gosub rturn ' look to another side
pause servo_turn ' wait for the servo to be finished turning
gosub totalhalt
readadc 1, b2 ' Decide which is the better way:
if b1<b2 then
gosub body_lturn
else
gosub body_rturn
end if
return body_lturn:
high 6 : low 5 : low 7 : high 4 ' this should be your combination that turns the robot one way
pause turn : gosub totalhalt
return body_rturn:
high 5 : low 6 : low 4 : high 7 ' this should be your combination that turns the robot the other way
pause turn : gosub totalhalt
return rturn:
servo 0, 100 ' look to one side
return lturn:
servo 0, 200 ' look to the other side
return totalhalt:
low 4 : low 5 : low 6 : low 7 ' low on all 4 halts the robot!
Servo 0,150 ' face forward
wait 1 ' freeze all for one second
return
+++ 优秀的程序可以使机器人向前进,转头,下决策,做较小的调整适应,转向“有趣的洞”,比如
大门口,在前进时还可以一齐工作。当他的转头时还旋转,那看起来真的非常的酷。
点击此处可以看伪代码:http://letsmakerobots.com/node/25