原文链接:
目录
参考文章:
目录
目录
前几日,朋友在群里发了一个机器人的小视频,视频里机器人可以对话,可以推箱子,开心以后会哈哈大笑,非常有趣。
详细了解里一下,这是个叫 Cozmo 的智能机器人,可以配合 SDK 用 Python 编程,兴趣一下子就来了,询问了一下价格,闲鱼 500 左右。顺便跟同事看了一下,同事也感兴趣,立马去闲鱼淘了 2个 蓝色限量款。
第一天下单,没想到第二天下午就到了,哈哈哈。满心激动的打开箱子,里面有:
先上张图
原文链接:https://www.cnblogs.com/David-domain/p/11216603.html
打开箱子以后,接下来就是要启动 Cozmo 了,拿起 Cozmo 找了好几圈都没找到开关,emmm~~什么鬼?
通过阅读说明书才知道,Cozmo 开机其实很简单,把充电座接上电,把 Cozmo 放上去就可以了。Cozmo 的底部有 2 个金属触点,通电后屏幕就亮了。
屏幕上有 2 行字,这 2 行字的用途稍后说明。
接下来我们需要掏出手机,下载 App。
App 有 iOS 和 Android 两种,值得注意的是:iOS 版本即使在国内,也可以直接从 App Store 下载安装;而 Android 版需要连接 Google Store 才能下载,不禁吐槽一下,国内的 Go 开发者还真是艰难。
为了方便起见,祭出了我的神器——老古董 5s。下载、安装完成 App 后,更换 Wi-Fi 。Wi-Fi 名就是 Cozmo 屏幕右上方的一串字,名为 Cozmo_700xxx
的 Wi-Fi,密码则是第2行的一长串字符串。
连接成功后,切换 App 连接 Cozmo,此时就可以互动了。
原文链接:https://www.cnblogs.com/David-domain/p/11216603.html
git clone https://github.com/GrinningHermit/Cozmo-Explorer-Tool.git
快速浏览 README 后,找到了 docs 链接:Welcome to the Cozmo SDK!。
因为我使用的是 MacBook,直接浏览 Mac OSX 部分: Installation - macOS / OS X
安装步骤很简单,总共需要 3 步:
4.2.1.1. Python Installation
# 首先,根据说明安装最新的 Homebrew
# 如果已经安装了BREW,请打开终端窗口并键入以下内容来更新它:
brew update
# 安装并更新homebrew后,在终端窗口中键入以下内容以安装最新版本的python 3:
brew install python3
4.2.1.2. SDK Installation
# 在终端中输入以下命令安装 SDK
pip3 install --user 'cozmo[camera]'
# [camera] 选项增加了对 Cozmo 相机处理图像。
Pillow-6.1.0
、cozmo-1.4.10
、cozmoclad-3.4.0
、numpy-1.16.4
4.2.1.3. SDK Upgrade
# 输入如下命令升级 SDK
pip3 install --user --upgrade cozmo
4.2.1.4. 手机驱动安装(补充步骤)
Pillow
模块Cozmo SDK
的时候已经自带了pip3 install --user Pillow
Flask
模块Flask
是 Python
的 Web 应用框架,因为 Cozmo Explorer Tool
是浏览器应用,故必须安装pip3 install --user flask
Flask Socket-IO
模块pip3 install --user flask-socketio
原文链接:https://www.cnblogs.com/David-domain/p/11216603.html
cd Cozmo-Explorer-Tool
python3 explorer_tool.py
╭─david@MyAir ~/Cozmo-Explorer-Tool ‹master›
╰─➤ python3 explorer_tool.py 1 ↵
WARNING:root:Cannot import from eventlet: Do `pip3 install --user eventlet` to install
Event monitoring works, but performance is decreased
2019-07-20 09:21:42,886 cozmo.general WARNING No iOS device found running Cozmo: No connected iOS devices running Cozmo in SDK mode
WARNING:cozmo.general:No iOS device found running Cozmo: No connected iOS devices running Cozmo in SDK mode
2019-07-20 09:21:42,887 cozmo.general WARNING No Android device found running Cozmo: Failed to execute adb command adb: [Errno 2] No such file or directory: 'adb': 'adb'
WARNING:cozmo.general:No Android device found running Cozmo: Failed to execute adb command adb: [Errno 2] No such file or directory: 'adb': 'adb'
* Serving Flask app "explorer_tool" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
ERROR:flask.app:Exception on / [GET]
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "explorer_tool.py", line 89, in index
return render_template('index.html', randomID=rndID, animations=lists[0], triggers=lists[1], behaviors=lists[2], hasSocketIO=flask_socketio_installed, hasPillow=active_viewer)
IndexError: list index out of range
pip3 install --user eventlet
,说明安装依赖中还有一个包要安装,docs 中没有提及pip3 install --user eventlet
System requirements
-
- PC with Windows OS, mac OSX or Linux
- Python 3.5.1 or later
- WiFi connection
- An iOS or Android mobile device with the Cozmo app installed, connected to the PC via USB cable
explorer_tool.py
注意window环境地址是
http://127.0.0.1:5000/ ,不是 http://0.0.0.0:5000
╭─david@MyAir ~/Downloads/cozmo_sdk_examples_1.4.10
╰─➤ ll
total 32
-rw-r--r--@ 1 david staff 10K 3 13 04:32 LICENSE.txt
-rw-r--r--@ 1 david staff 676B 3 13 04:32 README.md
drwxr-xr-x@ 10 david staff 320B 3 13 04:32 apps
drwxr-xr-x@ 7 david staff 224B 3 13 04:32 face_images
drwxr-xr-x@ 7 david staff 224B 3 13 04:32 if_this_then_that
drwxr-xr-x@ 4 david staff 128B 7 20 13:27 lib
drwxr-xr-x@ 4 david staff 128B 3 13 04:32 multi_robot
drwxr-xr-x@ 3 david staff 96B 3 13 04:32 tools
drwxr-xr-x@ 8 david staff 256B 3 13 04:32 tutorials
╭─david@MyAir ~/Downloads/cozmo_sdk_examples_1.4.10
╰─➤ tree -Cl .
.
|-- LICENSE.txt
|-- README.md
|-- apps
| |-- 3d_viewer.py
| |-- cli.py
| |-- color_finder.py
| |-- desk_security_guard.py
| |-- quick_tap.py
| |-- quiz_questions.json
| |-- quizmaster_cozmo.py
| `-- remote_control_cozmo.py
|-- face_images
| |-- cozmosdk.png
| |-- hello_world.png
| |-- ifttt_gmail.png
| |-- ifttt_sports.png
| `-- ifttt_stocks.png
|-- if_this_then_that
| |-- common
| | `-- __init__.py
| |-- ifttt_gmail.py
| |-- ifttt_sports.py
| |-- ifttt_sports_flask.py
| `-- ifttt_stocks.py
|-- lib
| `-- flask_helpers.py
|-- multi_robot
| |-- multi_robot_independent.py
| `-- multi_robot_unified.py
|-- tools
| `-- cubes
| |-- auto_cube_disconnect.py
| |-- connect_cubes.py
| |-- disconnect_cubes.py
| `-- log_cube_battery_levels.py
`-- tutorials
|-- 01_basics
| |-- 01_hello_world.py
| |-- 02_drive_and_turn.py
| |-- 03_count.py
| |-- 04_drive_square.py
| |-- 05_motors.py
| |-- 06_sing_scales.py
| |-- 07_backpack_lights.py
| |-- 08_animation.py
| |-- 09_cube_lights.py
| |-- 10_play_sound.py
| |-- 11_play_song.py
| `-- 12_random_animation.py
|-- 02_cozmo_face
| |-- 01_cozmo_face_image.py
| |-- 02_cozmo_face_mirror.py
| `-- 03_alarm_clock.py
|-- 03_vision
| |-- 01_light_when_face.py
| |-- 02_face_follower.py
| |-- 03_annotate.py
| `-- 04_exposure.py
|-- 04_cubes_and_objects
| |-- 01_go_to_pose_test.py
| |-- 02_create_wall.py
| |-- 03_go_to_object_test.py
| |-- 04_stack_or_roll.py
| |-- 05_cube_stack.py
| |-- 06_pickup_furthest.py
| |-- 07_lookaround.py
| |-- 08_drive_to_charger_test.py
| |-- 09_custom_objects.py
| |-- 10_object_moved.py
| |-- 11_dock_with_cube.py
| |-- 12_roll_cube.py
| `-- 13_pop_a_wheelie.py
|-- 05_async_python
| |-- 01_cube_blinker_sync.py
| `-- 02_cube_blinker.py
`-- 06_actions
`-- 01_parallel_actions.py
15 directories, 62 files
flask_helper.py
的文件,通过刚才 Cozmo Explorer Tool
的调试,我们能知道 Cozmo 使用 flask 框架做的 web 。所以,这个应该也是有 flask web 界面的。flask_helper.py
文件,可以看到顶部注释部分有一个说明Flask is a Python web framework. remote_control_cozmo.py and other scripts may use
these utility functions to interact with a web browser.
我们看到了什么?
你说对了!——remote_control_cozmo.py
find
一下
╭─david@MyAir ~/Downloads/cozmo_sdk_examples_1.4.10
╰─➤ find ./* -name "remote_control_cozmo.py"
./apps/remote_control_cozmo.py
╭─david@MyAir ~/Downloads/cozmo_sdk_examples_1.4.10
╰─➤ python3 apps/remote_control_cozmo.py
Traceback (most recent call last):
File "apps/remote_control_cozmo.py", line 29, in
import flask_helpers
ModuleNotFoundError: No module named 'flask_helpers'
flask_helpers
模块。你觉得在哪?是的,flask_helper.py
文件中lib
目录中╭─david@MyAir ~/Downloads/cozmo_sdk_examples_1.4.10
╰─➤ cd lib 1 ↵
╭─david@MyAir ~/Downloads/cozmo_sdk_examples_1.4.10/lib
╰─➤ python3 ../apps/remote_control_cozmo.py
2019-07-20 13:27:29,093 cozmo.general WARNING No iOS device found running Cozmo: No connected iOS devices running Cozmo in SDK mode
2019-07-20 13:27:29,095 cozmo.general WARNING No Android device found running Cozmo: Failed to execute adb command adb: [Errno 2] No such file or directory: 'adb': 'adb'
A connection error occurred: No devices connected running Cozmo in SDK mode
╭─david@MyAir ~/Downloads/cozmo_sdk_examples_1.4.10/lib
╰─➤ python3 ../apps/remote_control_cozmo.py 1 ↵
2019-07-20 13:33:24,416 cozmo.general INFO App connection established. sdk_version=1.4.10 cozmoclad_version=3.4.0 app_build_version=00003.00004.00000
2019-07-20 13:33:24,417 cozmo.general INFO Found robot id=1
2019-07-20 13:33:24,427 cozmo.general INFO Connected to iOS device_id=4 serial=4189dea05df44b4741d3f5a4fda9173d7e59a8c5
2019-07-20 13:33:24,726 cozmo.general INFO Robot id=1 serial=08828a31 initialized OK
* Serving Flask app "remote_control_cozmo" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
/Users/david/Library/Python/3.7/lib/python/site-packages/cozmo/annotate.py:181: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
if isinstance(text, collections.Iterable):
原文链接:https://www.cnblogs.com/David-domain/p/11216603.html
CTRL+C
退出 flask,保持 SDK 模式连接不中断文件 | 动作 |
---|---|
01_hello_world.py | 喊出“Hello World” |
02_drive_and_turn.py | 前进一段距离后,左转 |
03_count.py | 数数,从 1 数到 5 |
04_drive_square.py | 左转4次,走一个正方形 |
05_motors.py | 升级机械臂 |
06_sing_scales.py | 从 1 数到 10,并步进升起机械臂 |
07_backpack_lights.py | Cozmo 顶部的灯循环变色 |
08_animation.py | 做 3个动作 |
09_cube_lights.py | 魔方显示不同颜色的灯光 |
10_play_sound.py | Cozmo 唱歌 |
11_play_song.py | 手机播放音乐 |
12_random_animation.py | Cozmo 做 6 个随机动作 |
文件 | 动作 |
---|---|
01_cozmo_face_image.py | Cozmo 抬头,屏幕循环输出"WELCOME TO THE COZMO SDK" 和 “HELLO WORLD” |
02_cozmo_face_mirror.py | Cozmo 抬头,模仿镜子,屏幕显示它看到的画面 |
03_alarm_clock.py 15:30 | Cozmo 抬头,设置闹钟,传参 15:30,到时后会说“Wake up lazy human! It's time xxxx” |
文件 | 动作 |
---|---|
01_light_when_face.py | 人脸识别。打开一个窗口,显示 Cozmo 看到的实时的图像。 |
02_face_follower.py | 人脸跟踪。打开一个窗口,显示 Cozmo 看到的实时的图像。如果人脸移动,Cozmo 也会向相同方向转向。 |
03_annotate.py | 显示一个图形用户界面窗口,显示带注释的相机视图。 |
04_exposure.py | 演示Cozmo相机的手动和自动曝光设置。 |
文件 | 动作 | 说明 |
---|---|---|
01_go_to_pose_test.py | Cozmo 向左前方45度方向前进一段距离 | |
02_create_wall.py | 演示 Cozmo 绕过障碍物 | 需要执行 pip3 install --user 'cozmo[3dviewer]' ,否则找不到 OpenGL 模块 |
03_go_to_object_test | Cozmo 环顾四周找到魔方,并向魔方移动 | |
04_stack_or_roll.py | Cozmo 四处看看,然后等他看到一定数量的物体,将执行不同的操作。 | |
05_cube_stack.py | Como 把第一个看到的魔方放在第二个上 | |
06_pickup_furthest.py | Cozmo 找到一个魔方,把它举起来,并打开一个窗口,显示Cozmo 的识别过程 | |
07_lookaround.py | Cozmo 环顾四周,拿起并放下一个立方体。举起来后,Cozmo 会高兴的大笑。 | |
08_drive_to_charger_test | Cozmo 环顾四周,寻找充电器,并向它移动 | 好像识别不到充电器,哈哈哈 |
09_custom_objects.py | 演示如何定义自定义对象。 | |
10_object_moved.py | 演示跟踪Cozmo检测到立方体正在移动的时间。 | |
11_dock_with_cube.py | 在 Cozmo 正前方放一个魔方,Cozmo 与魔方对接 | |
12_roll_cube.py | 在 Cozmo 正前方放一个魔方,Cozmo 回去滚动魔方 | |
13_pop_a_wheelie.py | 在 Cozmo 正前方放一个魔方,Cozmo 通过机械臂和旋转,背靠在魔方上 |
文件 | 动作 | 说明 |
---|---|---|
01_cube_blinker_sync.py | Cozmo 先四处寻找一个立方体。一旦找到一个,魔方的灯呈圆形闪烁绿色,人点击魔方后退出。 | 同步案例 |
02_cube_blinker.py | Cozmo 先四处寻找一个立方体。一旦找到一个,魔方的灯呈圆形闪烁绿色,人点击魔方后退出。 | 异步案例 |
文件 | 动作 |
---|---|
01_parallel_actions.py | Cozmo 前进、升降机械臂并行进行 |
原文链接:https://www.cnblogs.com/David-domain/p/11216603.html
The usbmuxd (USB Multiplexor Daemon) must be installed on any computer system paired with an iOS device before running any programs. Installing iTunes will also install the usbmuxd on those systems. Linux users can install the usbmuxd module through the command line with sudo apt-get install usbmuxd.
usbmuxd
。sudo apt-get install usbmuxd
命令安装。Make sure adb (Android Debug Bridge) is installed on your system prior to running a program with an Android device. See the Install page for instructions.
01_hello_world.py
重命名为 nightnight.py
cd cozmo_sdk_examples_1.4.10/tutorials/01_basics/
cp 01_hello_world.py nightnight.py
nightnight.py
#!/usr/bin/env python3
# Copyright (c) 2016 Anki, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License in the file LICENSE.txt or at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
'''Hello World
Make Cozmo say 'Hello World' in this simple Cozmo SDK example program.
'''
import cozmo # 导入 cozmo SDK 包
def cozmo_program(robot: cozmo.robot.Robot):
robot.say_text("Hello World").wait_for_completed()
'''
robot.say_text(…) 表示要让 Cozmo 大声说出一段文本内容
"Hello World" 是 Cozmo 要说的内容
wait_for_completed() 表示要让 Cozmo 说完这段文本后才执行写下一行代码,如果没有这句,Cozmo 不会说出任何内容就停止了
'''
cozmo.run_program(cozmo_program)
import cozmo
def cozmo_program(robot: cozmo.robot.Robot):
robot.say_text("Night Night").wait_for_completed()
cozmo.run_program(cozmo_program)
./nightnight.py
既然我们已经编写了自己的 CozMo程序,那么可以看一下 CozMo SDK 的其余部分以及其他许多示例程序,以获得更多的想法。
Cozmo SDK 中的 API,可以在http://cozmosdk.anki.com/docs/api.html找到。里面包括了所有组件、动作、事件,参考示例程序,我相信各位看官一定能开发出非常 geek 的程序。
原文链接:https://www.cnblogs.com/David-domain/p/11216603.html