接下来是很有趣的工作。(或者说让他具有生命)
无论如何都要把电池正极的红线和工程主板上的红线(V)连在一起,还有黑线(-)和地线。具体怎么做取决于你的设备工具。如果电池和主板都有别针,那么你应该确保从电池的正极出发到主板的“地线”。虽然并不是经常,但有时候别针会相反,所以只要保证把相配的别针组一起。
还有就是不要供给主板超过6伏的电压。
一个小提示:在这里我们只用一个电池工作。除了V1和V2,你以后可能会要用同样的地线。那样的话你的别针可以只用一个电源,马达等其他的部件用别的电压。
在你自己的电脑上装一个Picaxe单片机编程的编辑器,按照手册把插口/USB接口/串口都连接起来,把电池装进还未装头的机器人,往机器人插入插口杆。。。进入编辑器,写程序: servo 0, 150 按下F5,等待程序的转换,接着你的伺服电机会有点拉动(或者旋转,这取决于他的初始状态)。
如果在这里出错,联系我,或者翻阅手册检查端口,直到没有错误警告并可以工作。
作为测试,试着写下: servo 0, 200
按下F5,伺服电机会旋转一个角度后停下来。为了回来,写: servo 0, 150 按下F5,现在,机器人的头正向朝前了。
粘上头--夏普的电感式电压调整感应器。
你好世界,我是一个机器人,准备好接受你的命令去探索世界!^_^
你已经做好基础的工作了。
这个设计也许还周到,你也可以使用其他部件等。但是如果你是像上面所述的方法一样连接的,
下面是一些小提示,作为你开始对机器人编程的参考。
在你的编辑器内输入(或者复制-粘贴)以下代码,连好机器人后按下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