查看“Bot:bit”的源代码
←
Bot:bit
跳转至:
导航
,
搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于这些用户组的用户使用:
用户
,labplus
您可以查看与复制此页面的源代码。
[[文件:Cc bot2.jpg|500px|缩略图|右]] == 概述 == bot:bit人形机器人是一款可以编程控制的人形机器人,支持Mpython图形化编程和Python代码编程,简单易学,通过编程可拓展人的空间思维空间能力。机器人具有多种工作形态,一是装4自由度舵机作为手臂,加上2路电机作为轮子,自由移动的同时双手可灵活操作;二是装有4自由度舵机作为双腿、实现自由行走、避障。 == 产品特点 == * 动作灵活:全身拥有8个动作关节,拟人造型,实现动作舞蹈,身手灵活。 * 无线遥控:2.4GHz射频传输模块,可实现遥控格斗运动,欢乐无穷。 * 内置加速度计 * 测距避障:内置的高精度超声波模块,能快速返回测量信息、走迷宫、越野的多种任务挑战。 * 高续航:双节14500锂电池,可循环充电,支持课堂教学应用。 == 百变创意玩法 == {| |- | [[文件:Cc bot case1.jpg|290px|缩略图|无|扎气球]] || [[文件:Cc bot case2.jpg|290px|缩略图|无|写字画画]] || [[文件:Cc bot case3.jpg|290px|缩略图|无|广场舞]] || [[文件:Cc bot case4.jpg|290px|缩略图|无|运动对抗]] |} == 程序下载教程 == {{microbit编程快速入门}} == bot:bit 拼装形态 == === Walk Bot=== * 4自由度舵机作为双腿、实现自由行走 [[文件:20180109031801!Cc bot1.png|200px|居中|有框|Walk Bot]]<br /> === Walk Bot硬件连接=== [[文件:Walk bot连接图.jpg|600px|无框|居中]] ==== Walk Bot python编程==== [http://wiki.labplus.cn/images/c/c1/Cc_bot_dancing.zip Cc_bot_dancing程序下载] <pre style="color:blue"> # -*- coding: utf-8 -*- from microbit import * import music import math servo_pos = bytearray([0, 0x05, 0xDC, 0x05, 0xDC, 0x05, 0xDC, 0x05, 0xDC]) def setServo(servo, angle): "set the servo angel" a = (1.5 + angle/90) * 1000 servo_pos[servo*2 + 1] = int(a / 256) servo_pos[servo*2 + 2] = int(a % 256) def updatePosition(): servo_pos[0] = 0 i2c.write(0x2A, servo_pos) def getDistance(): i2c.write(0x0b, bytearray([1])) temp=i2c.read(0x0B,2) dis =(temp[0]+temp[1]*256)/10 return dis inc = 0 phase_start=[0, 0, 0, 0] phase=[0, 0, 0, 0] offset=[0, 0, 0, 0] amplitude=[0, 0, 0, 0] t = 0 def refresh(): global t, phase, inc, amplitude, phase_start if (running_time() - t) > 50: t = running_time() for i in range(0, 4): pos = round(amplitude[i]*math.sin(phase[i] + phase_start[i]) + offset[i]) setServo(i, pos) phase[i] = phase[i] + inc updatePosition() def action(A, O, DIFF, T, steps): global inc, amplitude, phase_start, offset t2 = 0 inc = 2*math.pi/(T/50) for i in range(0, 4): amplitude[i] = A[i] phase_start[i] = DIFF[i] offset[i] = O[i] cycle = int(steps) t2 = running_time() + T*cycle while (running_time() < t2): refresh() for i in range(0, 4): amplitude[i] = A[i] phase_start[i] = DIFF[i] offset[i] = O[i] # move the servo t2 = running_time() + T*(steps - cycle) while (running_time() < t2): refresh() def walking(steps, T=1000, dir=1): AMP = (30, 30, 20, 20) OFFSET = (0, 0, 4, -4) DIFF = (0, 0, -math.pi/2 * dir, -math.pi/2 * dir) action(AMP, OFFSET, DIFF, T, steps) return def turn(steps, T=2000, dir=1): OFFSET = [0, 0, 4, -4] DIFF = (0, 0, -math.pi/2 * dir, -math.pi/2 * dir) if dir == 1: AMP = (30, 10, 20, 20) else: AMP = (10, 30, 20, 20) action(AMP, OFFSET, DIFF, T, steps) return def moonwalker(steps, T=900, h=20, dir=1): 'Moonwalker. Otto moves like Michael Jackson' AMP = [0, 0, h, h] OFFSET = [0, 0, h/2 + 2, -h/2 -2] DIFF = [0, 0, math.pi/180*dir*-90, math.pi/180*dir*-150] action(AMP, OFFSET, DIFF, T, steps) return def crusaito(steps, T, h, dir): AMP = [25, 25, h, h] OFFSET = [0, 0, h/2+ 4, -h/2 - 4] DIFF = [90, 90, 0, math.pi/180*dir*-60] action(AMP, OFFSET, DIFF, T, steps) def flapping(steps, T, h, dir): AMP = [12, 12, h, h] OFFSET = [0, 0, h-10, -h+10] DIFF = [0, math.pi/180*180, math.pi/180*dir*-90, math.pi/180*dir*90] action(AMP, OFFSET, DIFF, T, steps) return servo_position = [0, 0, 0, 0] servo_increment = [0, 0, 0, 0] def moveServos(time, servo_target): if time > 20: for i in range(0, 4): servo_increment[i] = (servo_target[i] - servo_position[i])/(time/20) final_time = running_time() + time; iteration = 1 while running_time() < final_time: partial_time = running_time()+20 for i in range(0, 4): setServo(i, servo_position[i]+iteration*servo_increment[i]) updatePosition() while running_time() < partial_time: pass iteration = iteration+1 else: for i in range(0, 4): setServo(i, servo_target[i]) updatePosition() for i in range(0, 4): servo_position[i] = servo_target[i] return def jump(steps, T): up = [0, 0, 45, -45] moveServos(T, up) down = [0, 0, 0, 0] moveServos(T, down) return def home(): for i in range(0, 4): setServo(i, 0) servo_position[i] = 0 updatePosition() display.off() home() while True: walking(5, 1500, 1) walking(5, 1500, -1) music.play(music.BA_DING) moonwalker(5, 1000, 25, 1) moonwalker(5, 1000, 25, -1) music.play(music.BADDY) crusaito(8, 1000, 15, 1) crusaito(8, 1000, 15, -1) crusaito(4, 2000, 15, 1) crusaito(4, 2000, 15, -1) music.play(music.NYAN) flapping(5, 1500, 15, 1) flapping(5, 1500, 15, -1) music.play(music.BIRTHDAY) </pre> === Auto Bot=== * 4自由度舵机作为手臂,加上2路电机作为轮子,自由移动的同时双手可灵活操作 [[文件:Motion bot.jpg|800px|居中|有框|motion_bot]] ==== Auto Bot硬件连接==== [[文件:Auto bot连接图.jpg|500px|无框|居中]] ==== Auto Bot python编程==== * 程序说明:需要下载有两个程序,一个是micro:bit作为遥控程序,另一个为cc bot执行动作程序。micro:bit实时发送xyz加速度数据操控cc bot轮子行走,按下「A」按键+xyz加速度操控两臂动作。 [http://wiki.labplus.cn/images/5/5c/Cc_bot_motion.zip Auto_bot程序下载] * micro:bit遥控程序 <pre style="color:blue"> from microbit import * import radio radio.on() radio.config(length=8, queue=3, channel=79, power=7, address=0x44773311, group=0x1B, data_rate=radio.RATE_250KBIT) msg = bytearray(8) x = 0 y = 0 z = 0 a = 0 while True: x = accelerometer.get_x() y = accelerometer.get_y() z = accelerometer.get_z() if button_a.is_pressed(): a = a | 0x01 else: a = a & 0xFE if button_b.is_pressed(): a = a | 0x02 else: a = a & 0xFD x = x + 10000; msg[0] = int(x / 256) msg[1] = x % 256 y = y + 10000; msg[2] = int(y / 256) msg[3] = y % 256 z = z + 10000; msg[4] = int(z / 256) msg[5] = z % 256 msg[6] = int(a / 256) msg[7] = a % 256 radio.send_bytes(msg) sleep(100) </pre> * cc bot执行程序 <pre style="color:blue"> # -*- coding: utf-8 -*- from microbit import * import radio import math motor_pwm = bytearray([8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) servo_pos = bytearray([0, 0x05, 0xDC, 0x05, 0xDC, 0x05, 0xDC, 0x05, 0xDC]) ''' motor_pwm.ch1 = M1.A motor_pwm.ch2 = M1.B motor_pwm.ch3 = M2.A motor_pwm.ch4 = M2.B ''' def motion(leftSpeed, rightSpeed): if leftSpeed > 2000: leftSpeed = 2000 if leftSpeed < -2000: leftSpeed = -2000 if leftSpeed == 0: motor_pwm[1] = 0 motor_pwm[2] = 0 motor_pwm[3] = 0 motor_pwm[4] = 0 if leftSpeed > 0: motor_pwm[1] = int(leftSpeed / 256) motor_pwm[2] = int(leftSpeed % 256) motor_pwm[3] = 0 motor_pwm[4] = 0 if leftSpeed < 0: leftSpeed = -leftSpeed motor_pwm[1] = 0 motor_pwm[2] = 0 motor_pwm[3] = int(leftSpeed / 256) motor_pwm[4] = int(leftSpeed % 256) if rightSpeed > 2000: rightSpeed = 2000 if rightSpeed < -2000: rightSpeed = -2000 if rightSpeed == 0: motor_pwm[5] = 0 motor_pwm[6] = 0 motor_pwm[7] = 0 motor_pwm[8] = 0 if rightSpeed > 0: motor_pwm[5] = 0 motor_pwm[6] = 0 motor_pwm[7] = int(rightSpeed / 256) motor_pwm[8] = int(rightSpeed % 256) if rightSpeed < 0: rightSpeed = -rightSpeed motor_pwm[5] = int(rightSpeed / 256) motor_pwm[6] = int(rightSpeed % 256) motor_pwm[7] = 0 motor_pwm[8] = 0 i2c.write(0x2A, motor_pwm) def setServo(servo, angle): "set the servo angel" a = (1.5 + angle/90) * 1000 servo_pos[servo*2 + 1] = int(a / 256) servo_pos[servo*2 + 2] = int(a % 256) def updatePosition(): servo_pos[0] = 0 i2c.write(0x2A, servo_pos) def getDistance(): i2c.write(0x0b, bytearray([1])) temp = i2c.read(0x0B, 2) dis = (temp[0]+temp[1]*256)/10 return dis # application display.off() motion(0, 0) radio.on() radio.config(length=8, queue=20, channel=79, power=7, address=0x44773311, group=0x1B, data_rate=radio.RATE_250KBIT) x = 0 y = 0 z = 0 a = 0 left = 0 right = 0 while True: # print("running") msg = bytes(8) msg = radio.receive_bytes() if msg is not None: x = msg[0]*256 + msg[1] x = x - 10000 y = msg[2]*256 + msg[3] y = y - 10000 z = msg[4]*256 + msg[5] z = z - 10000 a = msg[6]*256 + msg[7] if a == 0: left = int((y + x)/1000 * 2000) right = int((y - x)/1000 * 2000) # print('left = ', left) # print('right = ', right) motion(right, left) if (a & 0x03) != 0: motion(0, 0) y = min(max(-1000, y), 1000) x = min(max(-1000, x), 1000) sv = math.asin(y/1000)*180/math.pi sh = math.asin(x/1000)*180/math.pi sv = min(max(-45, sv), 45) sh = min(max(-45, sh), 45) if (a & 0x01) != 0: setServo(0, sv) setServo(1, -sh) if (a & 0x02) != 0: setServo(2, -sv) setServo(3, sh) updatePosition() </pre>
该页面使用的模板:
模板:Microbit编程快速入门
(
查看源代码
)
返回至
Bot:bit
。
导航菜单
个人工具
登录
命名空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
软件
Labplus软件
mPython软件
Mixly集成盛思版
mpython_conn
教学套件
创客初级实验箱
创客初级实验箱进阶版
创客中级实验箱
创客中级实验箱Ⅱ
人工智能交互实验箱
桌面机器人
乐动魔盒
可穿戴作品电子套件
创意触摸板套装
乐动魔块中级套装
乐动魔块高级套装
bot:bit
编程造物套装
逻辑造物套装
人工智能套装
物联网套装
高中信息技术套装
掌控板初级套装
初中信息技术材料包
开源硬件教学套装
冲锋舟
造物
Arduino
乐动魔块(旧版)
Blue:bit电子积木
MicroBit系列
掌控板系列
AI摄像头V1.0
AI摄像头V2.0
1956
掌控魔盒
乐动掌控
乐动魔块
互动作品
森林奇遇记
创客森林
创客乐园
物联网演示系统
博物馆防盗演示实验系统
梦想舞台演示实验系统
智能家居演示实验系统
智能教室演示实验系统
智能停车场演示实验系统
DIY-木板系列
嘘寒问暖
硬币存款机
吼一声试试
斜不胜正灯
时光葫芦
旋转转盘
越光宝盒
治愈系萌犬
光明使者
避障机械车
DIY-亚克力系列
情绪机器人
创意七彩灯
温湿度机器人
留言机
游龙戏灯
三色时钟
光影精灵
光影时钟
智能应用系列
LED眼镜
32x16 RGB LED点阵屏
DIY环境温湿度显示系统
DIY创客空间访客记录仪
其他
金属结构件套装
耗材存取管理柜
更多
课程资源
常见问题解答
Arduino语法参考手册
链接
Labplus官网
STEAM创客教育平台
工具
链入页面
相关更改
特殊页面
页面信息