
Piarm, Release 1.0
(continued from previous page)
alpha
+=
1
flag
=
True
elif
leftJoystick
.
read_status()
==
"down"
:
alpha
-=
1
flag
=
True
if
leftJoystick
.
read_status()
==
"left"
:
gamma
+=
1
flag
=
True
elif
leftJoystick
.
read_status()
==
"right"
:
gamma
-=
1
flag
=
True
if
rightJoystick
.
read_status()
==
"up"
:
beta
+=
1
flag
=
True
elif
rightJoystick
.
read_status()
==
"down"
:
beta
-=
1
flag
=
True
if
leftJoystick
.
read_status()
==
"pressed"
:
bucket
+=
2
flag
=
True
elif
rightJoystick
.
read_status()
==
"pressed"
:
bucket
-=
2
flag
=
True
if
flag
==
True
:
arm
.
set_angle([alpha,beta,gamma])
arm
.
set_bucket(bucket)
(
'servo angles:
%s
, bucket angle:
%s
'
%
(arm
.
servo_positions,arm
.
˓
→
component_staus))
In this code, the
_angles_control()
function is created to control the PiArm.
•
alpha
,
beta
and
gamma
refer to the angles of the 3 servos on the Arm respectively, refer to:
• If the
left
joystick is toggled up,
alpha
increases and the Arm will extend forward.
• If the
left
joystick is toggled down,
alpha
decreases and the Arm will retract backward.
• If the
left
joystick is toggled to the left,
gamma
increases and the Arm will turn left.
• If the
left
joystick is toggled to the right,
gamma
decreases and the Arm will turn right.
• If the
right
joystick is toggled up,
beta
increases and the Arm will raise up.
• If the
right
joystick is toggled down,
beta
decreases and the Arm will lower down.
• Finally, use the left and right joystick buttons to control the angle of the Shovel Bucket respectively.
4.4.2 Hanging Clip - Joystick Control
Run the code
cd
/
home
/
pi
/
piarm
/
examples
sudo python3 joystick_module2
.
py
Once the code is running, you will be able to control the rotation of PiArm’s arm by toggling the left and right joysticks,
and control the opening/closing of the Hanging Clip by pressing the left and right joysticks respectively.
But you need to assemble
to PiArm first.
4.4. Dual Joystick Module Control
117
Summary of Contents for PiArm
Page 1: ...Piarm Release 1 0 www sunfounder com Mar 31 2022 ...
Page 2: ......
Page 4: ...ii ...
Page 6: ...Piarm Release 1 0 2 CONTENTS ...
Page 8: ...Piarm Release 1 0 4 Chapter 1 Component List and Assembly Instructions ...
Page 48: ...Piarm Release 1 0 44 Chapter 3 Play with Ezblock ...
Page 91: ...Piarm Release 1 0 3 9 GAME Iron Collection 87 ...
Page 92: ...Piarm Release 1 0 88 Chapter 3 Play with Ezblock ...
Page 99: ...Piarm Release 1 0 Step 7 Click the WRITE button 4 1 Quick Guide on Python 95 ...
Page 148: ...Piarm Release 1 0 Yes then Ok Finish 144 Chapter 5 Appendix ...
Page 152: ...Piarm Release 1 0 Step 4 Double click the connection just created 148 Chapter 5 Appendix ...
Page 160: ...Piarm Release 1 0 156 Chapter 5 Appendix ...