本实验记录研究如何用scratch来控制WowWee MIP 机器人
最开始是开源项目:Control self balancing robot WowWee MiP from ScratchX
https://github.com/champierre/scratch2mip
找到个日本人写的windows下安装攻略,用谷歌翻译日语到中文:
https://swikis.ddo.jp/WorldStethoscope/59
高手果然都是不写细节的,我记录一下所有研究过程:
1. 下载 cratch2mip
下载scratch2mip_helper.zip
https://champierre.github.com/scratch2mip/scratch2mip_helper.zip
后解压到e:
E:\>cd scratch
E:\scratch>cd scratch2mip_helper
E:\scratch\scratch2mip_helper>npm install
'npm' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
//好吧,下面研究安装node.js
2.下载node.js
https://nodejs.org/en/
安装到d盘
E:\scratch\scratch2mip_helper>d:
d:\Program Files>cd nodejs
执行
d:\Program Files\nodejs>npm -v
6.9.0
添加环境系统变量
NODE_PATH
D:\Program Files\nodejs\node.exe
3.d:\Program Files\nodejs>npm install
npm WARN saveError ENOENT: no such file or directory, open 'd:\Program Files\nodejs\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'd:\Program Files\nodejs\package.json'
npm WARN nodejs No description
npm WARN nodejs No repository field.
npm WARN nodejs No README data
npm WARN nodejs No license field.
updated 1 package and audited 12096 packages in 67.663s
found 12 high severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for details
好吧,那就装全套吧,
4. npm install --global --production windows-build-tools
微软和ubuntu学习的apt get 方式挺好,一次性把python,MS studio全装了,就是全装C盘有点不爽
卡了的话,就把所有任务杀一下,再重新执行就可以了。
再进执行:
node .\scratch2mip_helper.js
===
Error: Cannot find module 'bluetooth-hci-socket'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (E:\scratch\scratch2mip_helper\node_modules\noble\lib\hci-socket\hci.js:6:26)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
====
查了一下问题,是微软的蓝牙驱动复杂不开源,于是按:https://www.npmjs.com/package/bluetooth-hci-socket的结果
参考了这个:http://bbs.21ic.com/icview-2521438-1-1.html?ordertype=1
5. 上京东买了一个绿联的蓝牙适配器 https://trade.tmall.com/detail/orderDetail.htm?biz_order_id=501439969250304958&forward_action=
CSR8510 A10芯片
说是win10无驱动安装,结果系统不认,联系客服,给个驱动:
usb蓝牙驱动: http://www.lulian.cn/download/22-cn.html
如果其他浏览器打不开可以用自带IE浏览器试试
(可以先看下教程哦~)
亲爱哒,此链接为usb蓝牙适配器设置教程哦~亲可参考此设置教程进行设置哈~
戳↓↓↓↓↓↓
http://tb.cn/jSP4YSw
===
装上认了以下是记录
然后用https://zadig.akeo.ie
在zadig option中要list all device才能找到CSR8510
重写驱动前记得备份数成,重写后
===
6. node .\scratch2mip_helper.js
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'bluetooth-hci-socket'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:690:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object.<anonymous> (D:\scratch\scratch2mip_helper\node_modules\noble\lib\hci-socket\hci.js:6:26)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
7. 再解决:npm install bluetooth-hci-socket
PS D:\scratch\scratch2mip_helper> npm install bluetooth-hci-socket
> usb@1.6.0 install D:\scratch\scratch2mip_helper\node_modules\usb
> prebuild-install --verbose || node-gyp rebuild
prebuild-install info begin Prebuild-install version 5.3.0
prebuild-install info looking for cached prebuild @ C:\Users\smartcity\AppData\Roaming\npm-cache\_prebuilds\752b28-usb-v1.6.0-node-v64-win32-x64.tar.gz
prebuild-install info found cached prebuild
prebuild-install info unpacking @ C:\Users\smartcity\AppData\Roaming\npm-cache\_prebuilds\752b28-usb-v1.6.0-node-v64-win32-x64.tar.gz
prebuild-install info unpack resolved to D:\scratch\scratch2mip_helper\node_modules\usb\build\Release\usb_bindings.node
prebuild-install info unpack required D:\scratch\scratch2mip_helper\node_modules\usb\build\Release\usb_bindings.node successfully
prebuild-install info install Successfully installed prebuilt binary!
> bluetooth-hci-socket@0.5.1 install D:\scratch\scratch2mip_helper\node_modules\bluetooth-hci-socket
> node-gyp rebuild
D:\scratch\scratch2mip_helper\node_modules\bluetooth-hci-socket>if not defined npm_config_node_gyp (node "D:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "D:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
在此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m”开关。
win_delay_load_hook.cc
正在生成代码
All 1 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
已完成代码的生成
binding.vcxproj -> D:\scratch\scratch2mip_helper\node_modules\bluetooth-hci-socket\build\Release\\binding.node
npm WARN scratch2mip_helper@1.1.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: xpc-connection@0.1.4 (node_modules\xpc-connection):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for xpc-connection@0.1.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ bluetooth-hci-socket@0.5.1
added 67 packages from 47 contributors and audited 320 packages in 27.614s
found 1 low severity vulnerability
run `npm audit fix` to fix them, or `npm audit` for details
8. 再执行脚本:
PS D:\scratch\scratch2mip_helper> node .\scratch2mip_helper.js
Starting scratch2mip 1.1.0
invalid status: poweredOff //不知道为啥是off
0: WowWee-MiP-8017
which one: 0 //输入0
MiP is connected.
===
此时MIP的状态是变成绿色了。
但是开源作者说明里的
http://scratchx.org/?url=http://champierre.github.io/scratch2mip/scratch2mip.js#home
这里scratchx是能连上,但没有监听,localhost:8080里写的是Upgrade Required 不知啥意思
所以教程里的功能无法使用。我试了蓝牙好象接不上MIP, 现在的MIP是机子自带的蓝牙连接的,可能是这个原因?
==
再试scratch1.4 //最新的scratch2,好象取消了这个远程广播功能?
Enable "remote sensor connections"(Click "Sensing" on the top left area, then right click on "slider sensor value". Select "enable remote sensor connections" in the context menu.)
成功监听到,然后
node scratch2mip_helper/scratch2mip_rsc.js
Use "broadcast" blocks to control MiP
只支持4个方向运动,MIP确实是跑起来了,注意几个连续动作间要加wait几秒。
距离传感功能还无法使用。
实验测试成功,其它的以后再说…………