SunFounder PiDog Kit, Release 1.0
2.3 Easy Coding
2.3.1 PiDog Initialization
The functions of PiDog are written in the Pidog class, and the prototype of this class is shown below.
Class: Pidog()
__init__
(leg_pins
=
DEFAULT_LEGS_PINS,
head_pins
=
DEFAULT_HEAD_PINS,
tail_pin
=
DEFAULT_TAIL_PIN,
leg_init_angles
=
None
,
head_init_angles
=
None
,
tail_init_angle
=
None
)
Pidog must be instantiated in one of several ways, as shown below.
1. Following are the simplest steps of initialization.
# Import Pidog class
from
pidog
import
Pidog
# instantiate a Pidog
my_dog
=
Pidog()
2. PiDog has 12 servos, which can be initialized when we instantiate it.
# Import Pidog class
from
pidog
import
Pidog
# instantiate a Pidog with custom initialized servo angles
my_dog
=
Pidog(leg_init_angles
=
[
25
,
25
,
-
25
,
-
25
,
70
,
-
45
,
-
70
,
45
],
head_init_angles
=
[
0
,
0
,
-
25
],
tail_init_angle
=
[
0
]
)
In the Pidog class, the servos are divided into three groups.
•
leg_init_angles
: In this array, 8 values determine the angles of eight servos, with the servos (pin num-
bers) they control being
2, 3, 7, 8, 0, 1, 10, 11
. From the foldout, you can see where these servos are located.
•
head_init_angles
: There is an array with 3 values, controllers for PiDog-head yaw, roll, pitch servos (
no.
4, 6, 5
) which react to yaw, roll, pitch, or Deflection of the body.
•
tail_init_angle
: In this array, there is only one value, which is dedicated to controlling the tail servo,
which is
9
.
3. Pidog allows you to redefine the serial number of the servos when instantiating the robot if your servo order is
different.
# Import Pidog class
from
pidog
import
Pidog
# instantiate a Pidog with custom initialized pins & servo angles
my_dog
=
Pidog(leg_pins
=
[
2
,
3
,
7
,
8
,
0
,
1
,
10
,
11
],
head_pins
=
[
4
,
6
,
5
],
tail_pin
=
[
9
],
leg_init_angles
=
[
25
,
25
,
-
25
,
-
25
,
70
,
-
45
,
-
70
,
45
],
(continues on next page)
2.3. Easy Coding
75
Содержание PiDog
Страница 1: ...SunFounder PiDog Kit Release 1 0 sunfounder Jan 09 2023 ...
Страница 2: ......
Страница 4: ...ii ...
Страница 6: ...SunFounder PiDog Kit Release 1 0 Content 2 CONTENTS ...
Страница 8: ...SunFounder PiDog Kit Release 1 0 4 Chapter 1 Component List and Assembly Instructions ...
Страница 15: ...SunFounder PiDog Kit Release 1 0 Step 7 Click the WRITE button 2 1 Quick Guide on Python 11 ...
Страница 92: ...SunFounder PiDog Kit Release 1 0 88 Chapter 2 Play with Python ...
Страница 108: ...SunFounder PiDog Kit Release 1 0 104 Chapter 4 Appendix ...