Skip to main content

A Python Library For Kamibot-Pi

Project description

Package for KamibotPi

Library for KamibotPi
We need a Kamibot dongle for the operation.

example

콘트롤 모드

#-*-coding:utf-8-*-
import random
from pyKamipi.pibot import *

# 카미봇 연결
kamibot = KamibotPi('COM8', 57600)

# ------------------------------------------------
# 콘트롤모드 go_dir_speed
# ------------------------------------------------
kamibot.go_dir_speed("f", 100, "f", 100)
kamibot.delay(1)

kamibot.go_dir_speed("b", 100, "f", 100)
kamibot.delay(1)

kamibot.go_dir_speed("f", 100, "b", 100)
kamibot.delay(1)

kamibot.go_dir_speed("b", 100, "b", 100)
kamibot.delay(1)
kamibot.stop()

# ------------------------------------------------
# 콘트롤모드 go_forward_speed
# ------------------------------------------------
kamibot.go_forward_speed(50, 50)
kamibot.delay(1)

kamibot.go_forward_speed(100, 50)
kamibot.delay(1)
kamibot.stop()

# ------------------------------------------------
# 콘트롤모드 go_backward_speed
# ------------------------------------------------
kamibot.go_backward_speed(50, 50)
kamibot.delay(1)

kamibot.go_backward_speed(100, 50)
kamibot.delay(1)
kamibot.stop()

# ------------------------------------------------
# 콘트롤모드 go_left_speed
# ------------------------------------------------
kamibot.go_left_speed(50)
kamibot.delay(1)

kamibot.go_left_speed(100)
kamibot.delay(1)
kamibot.stop()

# ------------------------------------------------
# 콘트롤모드 go_right_speed
# ------------------------------------------------
kamibot.go_right_speed(50)
kamibot.delay(1)

kamibot.go_right_speed(100)
kamibot.delay(1)
kamibot.stop()

# 카미봇 연결 해제
kamibot.close()

LED

import random
from pyKamipi.pibot import *

# 카미봇 연결
kamibot = KamibotPi('COM3', 57600)

# ------------------------------------------------
# LED
# ------------------------------------------------
kamibot.turn_led(255, 0, 0)
kamibot.delay(1)
kamibot.turn_led(0, 255, 0)
kamibot.delay(1)
kamibot.turn_led(0, 0, 255)
kamibot.delay(1)


for i in range(8):
    kamibot.turn_led_idx(i)
    kamibot.delay(0.5)

for i in range(10):
    kamibot.turn_led(random.randrange(0,255), random.randrange(0,255), random.randrange(0,255))
    kamibot.delay(0.5)

for i in range(100):
    kamibot.turn_led(255, 0, 0)
    kamibot.turn_led(0, 0, 255)


# 카미봇 연결 해제
kamibot.close()

거리를 지정해서 움직이기

import random
from pyKamipi.pibot import *

# 카미봇 연결
kamibot = KamibotPi('COM3', 57600)

# ------------------------------------------------
# 정밀제어  move_forward_unit
# ------------------------------------------------
kamibot.move_forward_unit(10, "-l") # 10cm
kamibot.delay(1)
kamibot.stop()

kamibot.move_forward_unit(3, "-t") # 3sec
kamibot.delay(1)
kamibot.stop()


kamibot.move_forward_unit(50, "-s") # 50 step
kamibot.delay(1)
kamibot.stop()


# ------------------------------------------------
# 정밀제어  move_right_unit
# ------------------------------------------------
kamibot.move_right_unit(160, "-l")
kamibot.delay(1)
kamibot.stop()

# ------------------------------------------------
# 정밀제어  move_left_unit
# ------------------------------------------------
kamibot.move_left_unit(160, "-l")
kamibot.delay(1)
kamibot.stop()


# ------------------------------------------------
# 정밀제어  move_backward_unit
# ------------------------------------------------
kamibot.move_backward_unit(10, "-l")
kamibot.delay(1)
kamibot.stop()

# ------------------------------------------------
# 정밀제어  turn_continous
# ------------------------------------------------
kamibot.turn_continous("r", 100)
kamibot.delay(1)
kamibot.stop()


# ------------------------------------------------
# 정밀제어  move_step
# ------------------------------------------------
kamibot.move_step("f", 100, "f", 100)
kamibot.delay(1)
kamibot.stop()


# ------------------------------------------------
# 정밀제어  move_time
# ------------------------------------------------
kamibot.move_time("f", 10, "f", 10)
kamibot.delay(1)
kamibot.stop()

# ------------------------------------------------
# 제자리 회전 turn_right_speed, turn_left_speed
# ------------------------------------------------
kamibot.turn_right_speed(90, speed=100)
kamibot.delay(1)
kamibot.turn_left_speed(90, speed=100)
kamibot.delay(1)
kamibot.stop()


# 카미봇 연결 해제
kamibot.close()

센서값 확인

import random
from pyKamipi.pibot import *

# 카미봇 연결
kamibot = KamibotPi('COM3', 57600)

# ------------------------------------------------
# 물체감지 get_object_detect
# ------------------------------------------------
left, right = kamibot.get_object_detect()
print(f"left={left}, right={right}")
kamibot.delay(1)
kamibot.get_object_detect(False)


# ------------------------------------------------
# 라인센서 get_line_sensor
# ------------------------------------------------
left, center, right = kamibot.get_line_sensor()
print(f"left={left}, center={center}, right={right}")
kamibot.delay(1)

# ------------------------------------------------
# 컬러센서 get_color_sensor
# ------------------------------------------------
r, g, b = kamibot.get_color_elements()
print(f"r={r}, g={g}, b={b}")
idx = kamibot.get_color_sensor()
print(f"idx={idx}")
kamibot.get_color_elements(False)

# ------------------------------------------------
# 배터리 get_battery
# ------------------------------------------------
battery = kamibot.get_battery()
print(f"battery={battery}")
kamibot.delay(1)


# ------------------------------------------------
# 멜로디  melody
# ------------------------------------------------
kamibot.melody(45, 1)
kamibot.delay(1)

kamibot.beep()
kamibot.delay(1)


# 카미봇 연결 해제
kamibot.close()

Top모터 기본 동작

import random
from pyKamipi.pibot import *

# 카미봇 연결
kamibot = KamibotPi('COM3', 57600)

# ------------------------------------------------
# 탑모터 제어  top_motor_degree
# ------------------------------------------------
kamibot.top_motor_degree("l", 180)  # 왼쪽 방향으로
kamibot.delay(1)

kamibot.top_motor_degree("r", 180)  # 오른쪽 방향으로
kamibot.delay(1)

# 카미봇 연결 해제
kamibot.close()

Top모터 절대위치

import random
from pyKamipi.pibot import *

# 카미봇 연결
kamibot = KamibotPi('COM3', 57600)

kamibot.top_motor_abspos(0)
kamibot.delay(1)

kamibot.top_motor_abspos(90)
kamibot.delay(1)

kamibot.top_motor_abspos(180)
kamibot.delay(1)

# 카미봇 연결 해제
kamibot.close()

TOP모터 정해진 시간만큼 회전

import random
from pyKamipi.pibot import *

# 카미봇 연결
kamibot = KamibotPi('COM3', 57600)

kamibot.top_motor_time("l", 10)
kamibot.delay(1)

kamibot.top_motor_time("r", 10)
kamibot.delay(1)

# 카미봇 연결 해제
kamibot.close()

그리기

import random
from pyKamipi.pibot import *

# 카미봇 연결
kamibot = KamibotPi('COM3', 57600)

# ------------------------------------------------
# 삼각형
# ------------------------------------------------
kamibot.draw_tri(10)
kamibot.delay(1)

# ------------------------------------------------
# 사각형
# ------------------------------------------------
kamibot.draw_rect(10)
kamibot.delay(1)

# ------------------------------------------------
# 오각형
# ------------------------------------------------
kamibot.draw_penta(10)
kamibot.delay(1)

# ------------------------------------------------
# 육각형
# ------------------------------------------------
kamibot.draw_hexa(10)
kamibot.delay(1)

# ------------------------------------------------
# 별
# ------------------------------------------------
kamibot.draw_star(10)
kamibot.delay(1)

# ------------------------------------------------
# 원그리기
# ------------------------------------------------
kamibot.draw_circle(10)
kamibot.delay(1)

# ------------------------------------------------
# 반원그리기
# ------------------------------------------------
kamibot.draw_semicircle(10, "l")
kamibot.delay(1)

# ------------------------------------------------
# 원호그리기
# ------------------------------------------------
kamibot.draw_arc(10, 3)
kamibot.delay(1)

# 카미봇 연결 해제
kamibot.close()

맵보드

import random
from pyKamipi.pibot import *

# 카미봇 연결
kamibot = KamibotPi('COM3', 57600)

# ------------------------------------------------
# 라인트레이서
# ------------------------------------------------
kamibot.toggle_linetracer(True, 100)
kamibot.delay(10)
kamibot.toggle_linetracer(False)

# ------------------------------------------------
# 블록 맵보드
# ------------------------------------------------
kamibot.move_forward(1, '-b')
kamibot.move_backward(1)
kamibot.turn_left(1, "-b")
kamibot.turn_right(1, "-b")
kamibot.turn_back(1, "-b")

# ------------------------------------------------
# 라인 맵보드
# ------------------------------------------------
kamibot.move_forward(1)
kamibot.turn_left()
kamibot.turn_right()
kamibot.turn_back()


# 카미봇 연결 해제
kamibot.close()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pykamipi-3.0.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file pykamipi-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: pykamipi-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.18

File hashes

Hashes for pykamipi-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb622cf633cf8031d28c5870e4ccf67e37a8a475b1a7cac1000ab727ae59d5d7
MD5 630bc62aba95b756a39cd6ea0304619f
BLAKE2b-256 088590865db9cae9330f57e7c7b66cdc5c9387192119850a33f66bc20e9c52c7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page