Piarm, Release 1.0
(continued from previous page)
_angles_control()
sleep(
0.01
)
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 angles of the Hanging Clip respectively.
4.4.3 Electromagnet - Joystick Control
Run the code
cd
/
home
/
pi
/
piarm
/
examples
sudo python3 joystick_module3
.
py
Once the code is run, you will be able to control the rotation of PiArm’s arm by toggling the left and right joysticks,
and controlling the on/off of the Electromagnet by pressing the left and right joysticks respectively.
But you need to assemble
to PiArm first.
Code
from
robot_hat
import
Servo,PWM,Joystick,ADC,Pin
from
robot_hat.utils
import
reset_mcu
from
time
import
sleep
from
piarm
import
PiArm
reset_mcu()
sleep(
0.01
)
leftJoystick
=
Joystick(ADC(
'A0'
),ADC(
'A1'
),Pin(
'D0'
))
rightJoystick
=
Joystick(ADC(
'A2'
),ADC(
'A3'
),Pin(
'D1'
))
arm
=
PiArm([
1
,
2
,
3
])
arm
.
electromagnet_init(PWM(
'P3'
))
arm
.
set_offset([
0
,
0
,
0
])
def
_angles_control
():
arm
.
speed
=
100
flag
=
False
alpha,beta,gamma
=
arm
.
servo_positions
status
=
""
if
leftJoystick
.
read_status()
==
"up"
:
(continues on next page)
4.4. Dual Joystick Module Control
119
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 ...