Skip to content

Commit 9803220

Browse files
rahul31124bessman
andauthored
feat: added documentation for RoboticArm (#187)
Co-authored-by: Alexander Bessman <[email protected]>
1 parent 16211ed commit 9803220

File tree

8 files changed

+126
-10
lines changed

8 files changed

+126
-10
lines changed

images/img_robotic_arm1.png

126 KB
Loading

images/img_robotic_arm2.png

108 KB
Loading

images/img_robotic_arm3.png

149 KB
Loading

images/jumper_wires.jpg

47.7 KB
Loading

images/pslab_wave_pins.png

63.9 KB
Loading

images/robotic_arm_kit.jpg

30.3 KB
Loading

images/sg90_servo.jpg

93.4 KB
Loading

tutorials/roboticarm.md

Lines changed: 126 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,130 @@
1-
Robotic Arm Servos
2-
======
1+
# Robotic Arm
32

4-
Introduction to motors
5-
----------------------
3+
## What is a Robotic Arm?
64

7-
Servos
8-
------
5+
A **Robotic arm** is a mechanical structure that mimics the movements of a human arm. It typically consists of multiple joints controlled by actuators, most commonly **servo motors**, to achieve precise angular movement.
6+
7+
In the PSLab context, a robotic arm uses servo motors to perform tasks like conducting scientific experiments, lifting, rotating, or grasping. These servos are controlled via **PWM (Pulse Width Modulation)** signals.
8+
9+
The **PSLab device** provides four square wave PWM outputs `SQR1`, `SQR2`, `SQR3`, and `SQR4` which allow control of up to **four servo motors**, enabling robotic arms with **up to four degrees of freedom (DoF)**.
10+
11+
---
12+
13+
## How to use it
14+
15+
### Requirements
16+
17+
- PSLab device
18+
- Robotic arm kit
19+
- Jumper wires
20+
- External power supply
21+
22+
<div style="display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 10px; margin: 10px 0;">
23+
<img src="../images/pslab_wave_pins.png" alt="PSLab Wavegen Pins" style="height: 250px; object-fit: contain;">
24+
<img src="../images/robotic_arm_kit.jpg" alt="Robotic Arm Kit" style="height: 250px; object-fit: contain;">
25+
<img src="../images/sg90_servo.jpg" alt="Servo Motor" style="height: 150px; object-fit: contain;">
26+
<img src="../images/jumper_wires.jpg" alt="Jumper Wires" style="height: 150px; object-fit: contain;">
27+
</div>
28+
29+
30+
### Wiring Setup
31+
32+
1. Connect the **signal wires** (usually **yellow**) of the 4 servos to the PSLab device PWM outputs PINS: `SQR1`, `SQR2`, `SQR3`, and `SQR4`.
33+
2. Connect the **power wires** (usually **red**) of all servos to the **positive terminal** of an **external power supply**.
34+
3. Connect the **ground wires** (usually **black**) of all servos together to the **GND of the external power supply**.
35+
4. Finally, connect the **GND of the external power supply** to the **GND pin** of the **PSLab device** to complete the common ground.
36+
37+
> ⚠️ **Important:** Do not power the servos directly from the PSLab device. Use an external regulated supply capable of handling the current requirements of all servos.
38+
39+
40+
### Performing the Experiment
41+
42+
1. Open the **PSLab app** on your Phone.
43+
<img src="../images/img_robotic_arm3.png">
44+
2. Navigate to **Robotic Arm**.
45+
3. Use the interface to:
46+
- Manually move each servo using sliders.
47+
- Create a timeline of servo movements.
48+
- Play, pause, or reset the timeline.
49+
- Change Frequency.
50+
- Save or import movements using CSV files.
51+
52+
<table>
53+
<tr>
54+
<td><img src="../images/img_robotic_arm1.png"></td>
55+
<td><img src="../images/img_robotic_arm2.png"></td>
56+
</tr>
57+
</table>
58+
59+
<div style="text-align: center;">
60+
<a href="https://youtu.be/zZ33pp560KA?si=OruiWHxXW4BBUqOx" target="_blank">Video 1</a> &nbsp;&nbsp;&nbsp;&nbsp;
61+
<a href="https://youtu.be/IFSByhxeXV4?si=CTsC6272dFxwbhG-" target="_blank">Video 2</a>
62+
</div>
63+
64+
65+
### Timeline CSV Import/Export
66+
67+
The PSLab app supports importing servo movement timelines from a **CSV file**, allowing interoperability with the **PSLab Python library**.
68+
69+
#### Exporting Timeline using Python
70+
71+
You can generate servo movement timelines using the `pslab-python` library and export them in CSV format for use in the PSLab app.
72+
73+
Here's a minimal working example:
74+
75+
```python
76+
from pslab import ScienceLab
77+
from pslab.external.motor import Servo, RoboticArm
78+
79+
psl = ScienceLab()
80+
81+
# Initialize servos on PWM outputs PINS
82+
base = Servo("SQ1", pwm_generator=psl.pwm_generator)
83+
shoulder = Servo("SQ2", pwm_generator=psl.pwm_generator)
84+
elbow = Servo("SQ3", pwm_generator=psl.pwm_generator)
85+
grip = Servo("SQ4", pwm_generator=psl.pwm_generator)
86+
87+
# Create Robotic Arm instance
88+
arm = RoboticArm([base, shoulder, elbow, grip])
89+
90+
# Define timeline: each row = [S1, S2, S3, S4] angles at 1s interval
91+
# Use None to keep a servo at the same angle as the previous step
92+
timeline = [
93+
[None, 30, 45, 10],
94+
[90, 30, 45, None],
95+
[180, 30, 45, None],
96+
[45, 60, 60, 20],
97+
[None, 60, 60, 20],
98+
[0, 90, 90, 30],
99+
[90, 90, 90, 30],
100+
[180, 90, 90, 30],
101+
[90, 45, 45, 0],
102+
[0, 30, 30, None],
103+
]
104+
105+
# Run the timeline on the robotic arm
106+
# This will move each servo to the specified positions sequentially at 1-second intervals
107+
arm.run_schedule(timeline=timeline)
108+
109+
# Export timeline to CSV for using in PSLab App
110+
arm.export_timeline_to_csv(
111+
timeline=timeline,
112+
folderpath=r"C:\path\to\folder"
113+
)
114+
115+
# Import timeline from a CSV file
116+
timeline = arm.import_timeline_from_csv(filepath=r"\path\to\folder\filename.csv")
117+
118+
```
119+
120+
### Observations
121+
122+
- Each servo rotates to the specified angle.
123+
- Timeline playback, with position updates every 1 second, allows synchronized movement across all joints.
124+
125+
### Applications
126+
127+
- Pick-and-place mechanisms
128+
- Educational demos in robotics and automation
9129

10-
Experiment: How to move servos with PSLab
11-
-----------------------------------------
12130

13-
Experiment: The Robot Arm Kit
14-
-----------------------------

0 commit comments

Comments
 (0)