Skip to content

Commit 35dae35

Browse files
committed
[WIP] Tool for aligning all motor joints.
1 parent 0f3d34c commit 35dae35

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* This example is used for calibrating the zero angles
2+
* for each motor of the robot arm.
3+
*/
4+
5+
#include <Braccio++.h>
6+
7+
void calibrate(int const motor_id)
8+
{
9+
while (!Braccio.get(motor_id).connected()) { }
10+
Braccio.get(motor_id).disengage();
11+
delay(500);
12+
Braccio.get(motor_id).engage();
13+
delay(500);
14+
15+
float target_position_deg = Braccio.get(motor_id).position();
16+
/* This is necessary because right now the library does not always report the right position from the very start ... */
17+
for(; target_position_deg > 360.0; target_position_deg = Braccio.get(motor_id).position()); { delay(100); }
18+
19+
while(!Braccio.isButtonPressed_ENTER())
20+
{
21+
Serial.print("[");
22+
Serial.print(motor_id);
23+
Serial.print("] ");
24+
Serial.print("Position (Current | Target) = ");
25+
Serial.print(Braccio.get(motor_id).position());
26+
Serial.print(" | ");
27+
Serial.println(target_position_deg);
28+
29+
if(Braccio.isJoystickPressed_LEFT())
30+
target_position_deg -= 1.0;
31+
if(Braccio.isJoystickPressed_RIGHT())
32+
target_position_deg += 1.0;
33+
34+
target_position_deg = max(target_position_deg, 0.0);
35+
target_position_deg = min(target_position_deg, 360.0);
36+
37+
delay(50);
38+
39+
/* Only call move().to() every 500 ms. Otherwise you flood the bus with messages and there you have the salad ... */
40+
static auto now = millis();
41+
if ((millis() - now) > 500)
42+
{
43+
Braccio.get(motor_id).move().to(target_position_deg).in(5s);
44+
now = millis();
45+
}
46+
}
47+
}
48+
49+
void setup()
50+
{
51+
Serial.begin(115200);
52+
while(!Serial) { }
53+
54+
Braccio.begin();
55+
56+
/* Ensure that servos don't block and hold too much. */
57+
Braccio.speed(SLOW);
58+
Braccio.disengage();
59+
60+
61+
Serial.println("Calibrate Motor 5 - 1st arm segment should look vertically up.");
62+
calibrate(5);
63+
while(Braccio.isButtonPressed_ENTER()) { }
64+
65+
Serial.println("Calibrate Motor 4 - 2nd arm segment should look vertically up.");
66+
calibrate(4);
67+
while(Braccio.isButtonPressed_ENTER()) { }
68+
69+
Serial.println("Calibrate Motor 3 - 3rd arm segment should look vertically up.");
70+
calibrate(3);
71+
while(Braccio.isButtonPressed_ENTER()) { }
72+
73+
Serial.println("Calibrate Motor 2 - bottom of hand should be aligned with cable of motor 3.");
74+
calibrate(2);
75+
while(Braccio.isButtonPressed_ENTER()) { }
76+
77+
Serial.println("Calibrate Motor 1 - gripper should be firmly closed.");
78+
calibrate(1);
79+
while(Braccio.isButtonPressed_ENTER()) { }
80+
81+
Serial.println("Calibrate Motor 6 - front of motor 6 should be aligned with 0deg marking in plate.");
82+
calibrate(6);
83+
while(Braccio.isButtonPressed_ENTER()) { }
84+
}
85+
86+
void loop()
87+
{
88+
89+
}

0 commit comments

Comments
 (0)