“Bot:bit”的版本间的差异

来自Labplus盛思维基百科
跳转至: 导航搜索
第29行: 第29行:
 
=== Walk Bot===
 
=== Walk Bot===
 
[[文件:20180109031801!Cc bot1.png|200px|居中|有框|Walk Bot]]<br />
 
[[文件:20180109031801!Cc bot1.png|200px|居中|有框|Walk Bot]]<br />
 +
=== Walk Bot python编程===
  
 +
<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>
 
=== Motion Bot===
 
=== Motion Bot===
  
 
[[文件:Motion bot.jpg|800px|居中|有框|motion_bot]]
 
[[文件:Motion bot.jpg|800px|居中|有框|motion_bot]]

2018年1月12日 (五) 09:38的版本

Cc bot2.jpg

概述

CC-Bot人形机器人是一款可以编程控制的人形机器人,支持Mpython图形化编程和Python代码编程,简单易学,通过编程可拓展人的空间思维空间能力。机器人具有多种工作形态,一是装4自由度舵机作为手臂,加上2路电机作为轮子,自由移动的同时双手可灵活操作;二是装有4自由度舵机作为双腿、实现自由行走、避障;三是同时组转双手和双腿,8自由度舵机实现各种舞蹈动作,使用方法灵活多变,富有创意。

产品特点

  • 动作灵活:全身拥有8个动作关节,拟人造型,实现动作舞蹈,身手灵活。
  • 无线遥控:2.4GHz射频传输模块,可实现遥控格斗运动,欢乐无穷。
  • 内置加速度计
  • 测距避障:内置的高精度超声波模块,能快速返回测量信息、走迷宫、越野的多种任务挑战。
  • 高续航:双节14500锂电池,可循环充电,支持课堂教学应用。


百变创意玩法

扎气球
写字画画
广场舞
运动对抗

CC-Bot 拼装形态

Walk Bot

Walk Bot

Walk Bot python编程

# -*- 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)
    
    



Motion Bot

motion_bot