@tigerpython/robotics-libraries 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG +68 -0
- package/LICENSE +373 -0
- package/README.md +81 -0
- package/calliope/README.md +15 -0
- package/calliope/callibot.py +176 -0
- package/calliope/callibotmot.py +46 -0
- package/calliope/callimk.py +143 -0
- package/calliope/cbalarm.py +14 -0
- package/calliope/cpglow.py +76 -0
- package/calliope/cpmike.py +16 -0
- package/calliope/cprover.py +33 -0
- package/calliope/cputils.py +23 -0
- package/calliope/libraries.json +10 -0
- package/calliope/libraries.raw.json +10 -0
- package/calliope/min/callibot.py +97 -0
- package/calliope/min/callibotmot.py +23 -0
- package/calliope/min/callimk.py +47 -0
- package/calliope/min/cbalarm.py +6 -0
- package/calliope/min/cpglow.py +29 -0
- package/calliope/min/cpmike.py +8 -0
- package/calliope/min/cprover.py +9 -0
- package/calliope/min/cputils.py +7 -0
- package/dist/index.d.mts +124 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +2896 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2862 -0
- package/dist/index.mjs.map +1 -0
- package/microbit/README.md +48 -0
- package/microbit/controller.py +212 -0
- package/microbit/huskylens.py +479 -0
- package/microbit/libraries.json +19 -0
- package/microbit/libraries.raw.json +19 -0
- package/microbit/mbalarm.py +15 -0
- package/microbit/mbbitbot.py +127 -0
- package/microbit/mbglow.py +77 -0
- package/microbit/mbled.py +56 -0
- package/microbit/mbmarsrover.py +216 -0
- package/microbit/mbminibit.py +139 -0
- package/microbit/mbrobot.py +401 -0
- package/microbit/mbrobot_legacy.py +90 -0
- package/microbit/mbrobot_plus.py +179 -0
- package/microbit/mbrobot_plusV2.py +490 -0
- package/microbit/mbrobot_plusV3.py +427 -0
- package/microbit/mbrobotmot.py +49 -0
- package/microbit/mbthetabot.py +167 -0
- package/microbit/mbwait.py +50 -0
- package/microbit/mbxgo.py +173 -0
- package/microbit/min/controller.py +42 -0
- package/microbit/min/huskylens.py +145 -0
- package/microbit/min/mbalarm.py +6 -0
- package/microbit/min/mbbitbot.py +40 -0
- package/microbit/min/mbglow.py +29 -0
- package/microbit/min/mbled.py +18 -0
- package/microbit/min/mbmarsrover.py +62 -0
- package/microbit/min/mbminibit.py +50 -0
- package/microbit/min/mbrobot.py +82 -0
- package/microbit/min/mbrobot_legacy.py +45 -0
- package/microbit/min/mbrobot_plus.py +75 -0
- package/microbit/min/mbrobot_plusV2.py +102 -0
- package/microbit/min/mbrobot_plusV3.py +194 -0
- package/microbit/min/mbrobotmot.py +25 -0
- package/microbit/min/mbthetabot.py +47 -0
- package/microbit/min/mbwait.py +23 -0
- package/microbit/min/mbxgo.py +37 -0
- package/package.json +54 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import gc
|
|
2
|
+
from calliope_mini import i2c,sleep
|
|
3
|
+
import machine
|
|
4
|
+
class Motor:
|
|
5
|
+
def __init__(A,id):A._id=id
|
|
6
|
+
def _f2(B,d,s):
|
|
7
|
+
if B._id==0:A=0
|
|
8
|
+
else:A=2
|
|
9
|
+
try:i2c.write(32,bytearray([A,d,s]))
|
|
10
|
+
except:
|
|
11
|
+
print('Please switch on mbRobot!')
|
|
12
|
+
while True:0
|
|
13
|
+
def rotate(B,s):
|
|
14
|
+
A=abs(s);A=A+50
|
|
15
|
+
if s>0:B._f2(0,A)
|
|
16
|
+
elif s<0:B._f2(1,A)
|
|
17
|
+
else:B._f2(0,0)
|
|
18
|
+
delay=sleep
|
|
19
|
+
def setLED(on):
|
|
20
|
+
if on==1:i2c.write(33,bytearray([0,3]))
|
|
21
|
+
else:i2c.write(33,bytearray([0,0]))
|
|
22
|
+
motL=Motor(0)
|
|
23
|
+
motR=Motor(2)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import gc
|
|
2
|
+
from calliope_mini import i2c,sleep
|
|
3
|
+
i2c.init()
|
|
4
|
+
_g1=30
|
|
5
|
+
_g2=.09
|
|
6
|
+
def w(d1,d2,s1,s2):i2c.write(16,bytearray([0,d1,s1]));i2c.write(16,bytearray([2,d2,s2]))
|
|
7
|
+
def forward():w(0,0,_g1,_g1)
|
|
8
|
+
def backward():w(1,1,_g1,_g1)
|
|
9
|
+
def stop():w(0,0,0,0)
|
|
10
|
+
def right():w(0 if _g1>0 else 1,1 if _g1>0 else 0,_g1,_g1)
|
|
11
|
+
def left():w(1 if _g1>0 else 0,0 if _g1>0 else 1,_g1,_g1)
|
|
12
|
+
def rightArc(r):
|
|
13
|
+
A=abs(_g1)
|
|
14
|
+
if r<_g2:B=0
|
|
15
|
+
else:C=(r-_g2)/(r+_g2)*(1-A*A/200000);B=int(C*A)
|
|
16
|
+
if _g1>0:w(0,0,A,B)
|
|
17
|
+
else:w(1,1,B,A)
|
|
18
|
+
def leftArc(r):
|
|
19
|
+
A=abs(_g1)
|
|
20
|
+
if r<_g2:B=0
|
|
21
|
+
else:C=(r-_g2)/(r+_g2)*(1-A*A/200000);B=int(C*A)
|
|
22
|
+
if _g1>0:w(0,0,B,A)
|
|
23
|
+
else:w(1,1,A,B)
|
|
24
|
+
def setSpeed(speed):
|
|
25
|
+
A=speed;global _g1
|
|
26
|
+
if A<15:_g1=15
|
|
27
|
+
else:_g1=A
|
|
28
|
+
def motorL(dir,speed):i2c.write(16,bytearray([0,dir,speed]))
|
|
29
|
+
def motorR(dir,speed):i2c.write(16,bytearray([2,dir,speed]))
|
|
30
|
+
def led(right_left,on_off):
|
|
31
|
+
A=bytearray(2)
|
|
32
|
+
if right_left==0:A[0]=11
|
|
33
|
+
else:A[0]=12
|
|
34
|
+
A[1]=on_off;i2c.write(16,A)
|
|
35
|
+
def setLEDLeft(on):led(1,on)
|
|
36
|
+
def setLEDRight(on):led(0,on)
|
|
37
|
+
def setLED(on):led(1,on);led(0,on)
|
|
38
|
+
def rgbLED(red,green,blue):A=bytearray(2);A[0]=24;A[1]=red;B=bytearray(2);B[0]=25;B[1]=green;C=bytearray(2);C[0]=26;C[1]=blue;i2c.write(16,A);i2c.write(16,B);i2c.write(16,C)
|
|
39
|
+
def getDistance():i2c.write(16,bytearray([40]));sleep(20);A=i2c.read(16,2);B=A[0]<<8|A[1];return B
|
|
40
|
+
def irLeftValue():i2c.write(16,bytearray([29]));A=i2c.read(16,1)[0];return 0 if A&1!=0 else 1
|
|
41
|
+
def irRightValue():i2c.write(16,bytearray([29]));A=i2c.read(16,1)[0];return 0 if A&2!=0 else 1
|
|
42
|
+
def setServo(S,Angle):
|
|
43
|
+
if S=='S1':A=20
|
|
44
|
+
if S=='S2':A=21
|
|
45
|
+
i2c.write(16,bytearray([A,Angle]))
|
|
46
|
+
exit=stop
|
|
47
|
+
delay=sleep
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from calliope_mini import*
|
|
2
|
+
_g1=0
|
|
3
|
+
_g2=0
|
|
4
|
+
_g3=0
|
|
5
|
+
_g4=50
|
|
6
|
+
_g5=True
|
|
7
|
+
_g6=False
|
|
8
|
+
def makeGlow():global _g6;display.set_pixel(2,2,9);_g6=True
|
|
9
|
+
def clear():display.clear()
|
|
10
|
+
def forward():_f1(1)
|
|
11
|
+
def back():_f1(-1)
|
|
12
|
+
def right(angle):global _g3;_g3=(_g3+angle)%360
|
|
13
|
+
def left(angle):right(-angle)
|
|
14
|
+
def setPos(x,y):global _g1,_g2;_g1=x;_g2=y;_f2()
|
|
15
|
+
def getPos():return _g1,_g2
|
|
16
|
+
def setSpeed(speed):global _g4;_g4=speed
|
|
17
|
+
def showTrace(enable):global _g5;_g5=enable
|
|
18
|
+
def isLit():return display.get_pixel(_g1+2,4-(_g2+2))==9
|
|
19
|
+
def _f1(s):
|
|
20
|
+
global _g1,_g2;sleep(2000-_g4*20);d=_g3//45
|
|
21
|
+
if d in[1,2,3]:_g1+=s
|
|
22
|
+
if d in[5,6,7]:_g1-=s
|
|
23
|
+
if d in[0,1,7]:_g2+=s
|
|
24
|
+
if d in[3,4,5]:_g2-=s
|
|
25
|
+
_f2()
|
|
26
|
+
def _f2():
|
|
27
|
+
if not _g6:print('Use "makeGlow()" to create a Glow.');raise Exception('Glow not initialized.')
|
|
28
|
+
if not _g5:display.clear()
|
|
29
|
+
if-2<=_g1<=2 and-2<=_g2<=2:display.set_pixel(_g1+2,4-(_g2+2),9)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from calliope_mini import pin3,running_time,sleep
|
|
2
|
+
_g1=running_time()
|
|
3
|
+
def isClicked(level=10,rearm_time=500):
|
|
4
|
+
A=False;global _g1
|
|
5
|
+
if running_time()-_g1<rearm_time:sleep(10);return A
|
|
6
|
+
B=pin3.read_analog()
|
|
7
|
+
if B<518-level:_g1=running_time();return True
|
|
8
|
+
return A
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from calliope_mini import pin28,pin29,pin30
|
|
2
|
+
def forward():pin28.write_analog(v);pin29.write_digital(1);pin30.write_digital(1)
|
|
3
|
+
def left():pin28.write_analog(v);pin29.write_digital(0);pin30.write_digital(1)
|
|
4
|
+
def right():pin28.write_analog(v);pin29.write_digital(1);pin30.write_digital(0)
|
|
5
|
+
def stop():pin28.write_digital(0)
|
|
6
|
+
def move():left()
|
|
7
|
+
def rewind():right()
|
|
8
|
+
def setSpeed(speed):global v;v=int(speed/100*1023)
|
|
9
|
+
setSpeed(100)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
def cat(filename):
|
|
2
|
+
with open(filename)as B:
|
|
3
|
+
A=B.readline()
|
|
4
|
+
while A:print(A[:-1]);A=B.readline()
|
|
5
|
+
from math import asin,atan2,sqrt,degrees
|
|
6
|
+
def getPitch(a):A=atan2(a[1],a[2]);return int(degrees(A))
|
|
7
|
+
def getRoll(a):A=sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);B=asin(a[0]/A);return int(degrees(B))
|