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

来自Labplus盛思维基百科
跳转至: 导航搜索
(Senadmin移动页面Bot:bitPrivate:Bot:bit
程序下载教程
第26行: 第26行:
 
|}
 
|}
 
== 程序下载教程 ==
 
== 程序下载教程 ==
<big>'''Step1'''</big>.下载并安装[http://labplus.cn/index.php/product/software/242-m-python m:python]编程软件,该软件支持图形化编程和python源码编程。http://labplus.cn/index.php/product/download<br />
+
{{microbit编程快速入门}}
<big>'''Step2'''</big>.USB接口连接至电脑,打开电源开关。电脑应能识别到可移动存储设备MICROBIT。<br />[[文件:Microbit u盘.png|400px|无框|左]]<br /><br /><br /><br />
 
<big>'''Step3'''</big>.打开m:python编程软件,根据需要选择图形化编程或python代码编程方式来完成程序。<br />
 
[[文件:下载Hex.png|700px|无框|左]]<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
 
<big>'''Step4'''</big>.程序完成后,点击
 
[[文件:Mpython download.png|100px|无框]]
 
,下载程序并保存到microbit可移动盘上 ,待下载指示灯闪烁完毕后,说明程序下载成功。<br /><br />
 
[[文件:保存hex.png|600px|无框|左]]<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
 
  
 
== bot:bit 拼装形态 ==
 
== bot:bit 拼装形态 ==

2018年3月15日 (四) 13:01的版本

Cc bot2.jpg

概述

bot:bit人形机器人是一款可以编程控制的人形机器人,支持Mpython图形化编程和Python代码编程,简单易学,通过编程可拓展人的空间思维空间能力。机器人具有多种工作形态,一是装4自由度舵机作为手臂,加上2路电机作为轮子,自由移动的同时双手可灵活操作;二是装有4自由度舵机作为双腿、实现自由行走、避障。

产品特点

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


百变创意玩法

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

程序下载教程

Step1.m:python编程软件安装:

双击mpythonSetup.exe按提示安装编程程序。进入官网下载 ( http://labplus.cn/index.php/product/download )
系统要求:windows7/windows8/windows10,32/64位;windows XP。
Mpython ico1.png

Step2.Micro:bit 串口驱动安装:双击mbedWinSerial.exe,按提示安装串口驱动。如需要USB串口打印数据须安装该驱动,不需要可跳过此步骤。

进入官网下载 ( http://labplus.cn/index.php/product/download )
Mbed serial.png

Step3.硬件识别:USB接口连接至电脑,打开电源开关。电脑将自动识别到可移动存储设备MICROBIT。

Microbit u盘.png



Step4. 程序设计:打开mpython编程软件,根据需要选择图形化编程或python代码编程方式来完成程序。点击软件指令区,选择对应指令进行编程,更方便快速的设计程序。也可点击菜单栏“模块化”,可切换至代码编程。

下载Hex.png

Step5. 程序完成后,点击Mpython download.png,下载程序并保存到microbit可移动盘上 ,待下载指示灯闪烁完毕后,说明程序下载成功。

保存hex.png

更多m:python编程软件操作说明可查看 http://wiki.labplus.cn/index.php?title=Mpython

bot:bit 拼装形态

Walk Bot

  • 4自由度舵机作为双腿、实现自由行走
Walk Bot

Walk Bot硬件连接

Walk bot连接图.jpg

Walk Bot python编程

Cc_bot_dancing程序下载

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

Auto Bot

  • 4自由度舵机作为手臂,加上2路电机作为轮子,自由移动的同时双手可灵活操作
motion_bot

Auto Bot硬件连接

Auto bot连接图.jpg

Auto Bot python编程

  • 程序说明:需要下载有两个程序,一个是micro:bit作为遥控程序,另一个为cc bot执行动作程序。micro:bit实时发送xyz加速度数据操控cc bot轮子行走,按下「A」按键+xyz加速度操控两臂动作。

Auto_bot程序下载

  • micro:bit遥控程序
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)
  • cc bot执行程序
# -*- 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()