Skip to content

Commit 5b87d08

Browse files
committed
WIP calibration tool.
1 parent 3093132 commit 5b87d08

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* This example is used for calibrating the zero angles
2+
* for each motor of the robot arm prior to assembly of
3+
* the arm.
4+
*/
5+
6+
/**************************************************************************************
7+
* INCLUDE
8+
**************************************************************************************/
9+
10+
#include <Braccio++.h>
11+
12+
/**************************************************************************************
13+
* TYPEDEF
14+
**************************************************************************************/
15+
16+
class InitialServoPosition
17+
{
18+
public:
19+
InitialServoPosition(int const motor_id, float const motor_angle_deg)
20+
: _motor_id{motor_id}
21+
, _motor_angle_deg{motor_angle_deg}
22+
{ }
23+
24+
inline int id() const { return _motor_id; }
25+
inline float angle() const { return _motor_angle_deg; }
26+
27+
private:
28+
int const _motor_id;
29+
float const _motor_angle_deg;
30+
};
31+
32+
/**************************************************************************************
33+
* CONSTANT
34+
**************************************************************************************/
35+
36+
static std::array<InitialServoPosition, 6> const INITIAL_SERVO_POSITION =
37+
{
38+
InitialServoPosition{1, 0.0},
39+
InitialServoPosition{2, 0.0},
40+
InitialServoPosition{3, 0.0},
41+
InitialServoPosition{4, 0.0},
42+
InitialServoPosition{5, 0.0},
43+
InitialServoPosition{6, 0.0},
44+
};
45+
46+
/**************************************************************************************
47+
* FUNCTIONS
48+
**************************************************************************************/
49+
50+
void calibrate(int const id, float const target_angle)
51+
{
52+
Serial.print("Connecting .... ");
53+
for (; !Braccio.get(id).connected(); delay(10)) { }
54+
Serial.println("OK.");
55+
delay(500);
56+
57+
Serial.print("Disengaging ... ");
58+
Braccio.get(id).disengage();
59+
Serial.println("OK.");
60+
delay(500);
61+
62+
Serial.print("Engaging ...... ");
63+
Braccio.get(id).engage();
64+
Serial.println("OK.");
65+
delay(500);
66+
67+
/* Drive to the position for assembling the servo horn. */
68+
for (float current_angle = Braccio.get(id).position();
69+
fabs(Braccio.get(id).position() - target_angle) > 1.0;)
70+
{
71+
Braccio.get(id).move().to(target_angle).in(200ms);
72+
delay(250);
73+
74+
char msg[64] = {0};
75+
snprintf(msg, sizeof(msg), "Angle (Target | Current) = %.2f | %.2f", target_angle, Braccio.get(id).position());
76+
Serial.println(msg);
77+
}
78+
}
79+
80+
/**************************************************************************************
81+
* SETUP/LOOP
82+
**************************************************************************************/
83+
84+
void setup()
85+
{
86+
Serial.begin(115200);
87+
while(!Serial) { }
88+
89+
Braccio.begin();
90+
delay(100);
91+
Braccio.disengage();
92+
delay(100);
93+
94+
calibrate(1, 0.0);
95+
96+
/*
97+
for (auto & servo : INITIAL_SERVO_POSITION)
98+
{
99+
Serial.print("Servo ");
100+
Serial.print(servo.id());
101+
Serial.print(": Angle = ");
102+
Serial.print(servo.angle());
103+
Serial.print(" °");
104+
Serial.println();
105+
106+
calibrate(servo.id(), servo.angle());
107+
}
108+
*/
109+
}
110+
111+
void loop()
112+
{
113+
114+
}

0 commit comments

Comments
 (0)