Library to control a 3DOF leg with a PCA9685.

Revision:
3:9cc530686346
Parent:
0:ead365546ca5
Child:
4:4d4cea424b7f
--- a/HEXAPOD_LEG.cpp	Thu Apr 14 10:03:45 2016 +0000
+++ b/HEXAPOD_LEG.cpp	Mon May 02 13:41:10 2016 +0000
@@ -5,32 +5,33 @@
 
 Hexapod_Leg::Hexapod_Leg(PCA9685 Driver, calibrated_leg_centre leg_cent, calibrated_leg_1_degree leg_step, leg_outputs leg_out, bool ON_RHS) :
 
-a_ref(leg_cent.a), 
-b_ref(leg_cent.b),
-c_ref(leg_cent.c),
+    a_ref(leg_cent.a),
+    b_ref(leg_cent.b),
+    c_ref(leg_cent.c),
 
-a_1deg(leg_step.a),
-b_1deg(leg_step.b),
-c_1deg(leg_step.c),
+    a_1deg(leg_step.a),
+    b_1deg(leg_step.b),
+    c_1deg(leg_step.c),
 
-a_pin(leg_out.a),
-b_pin(leg_out.b),
-c_pin(leg_out.c),
+    a_pin(leg_out.a),
+    b_pin(leg_out.b),
+    c_pin(leg_out.c),
 
-RHS(ON_RHS),
+    RHS(ON_RHS),
 
-driver(Driver)
+    driver(Driver)
 
 {
-    
+
 }
 
 
 
-float Hexapod_Leg::angle_to_pwm(float angle, char joint) {
-    
+float Hexapod_Leg::angle_to_pwm(float angle, char joint)
+{
+
     float pwm = 0;
-    
+
     switch (joint) {
         case 'a':
         case 'A':
@@ -56,15 +57,21 @@
             pwm = 1500;
             break;
     }
-    
+
     return pwm;
 }
 
 
-void Hexapod_Leg::set_joint_angles(float angle_a, float angle_b, float angle_c) {
-       
-       driver.set_pwm_pw(a_pin, angle_to_pwm(angle_a, 'a'));
-       driver.set_pwm_pw(b_pin, angle_to_pwm(angle_b, 'b'));
-       driver.set_pwm_pw(c_pin, angle_to_pwm(angle_c, 'c'));
-       
-} 
\ No newline at end of file
+void Hexapod_Leg::set_joint_angles(float angle_a, float angle_b, float angle_c)
+{
+    driver.set_pwm_pw(a_pin, angle_to_pwm(angle_a, 'a'));
+    driver.set_pwm_pw(b_pin, angle_to_pwm(angle_b, 'b'));
+    driver.set_pwm_pw(c_pin, angle_to_pwm(angle_c, 'c'));
+}
+
+void Hexapod_Leg::set_leg_position(leg_x_angles angles)
+{
+    driver.set_pwm_pw(a_pin, angle_to_pwm(angles.a, 'a'));
+    driver.set_pwm_pw(b_pin, angle_to_pwm(angles.b, 'b'));
+    driver.set_pwm_pw(c_pin, angle_to_pwm(angles.c, 'c'));
+}
\ No newline at end of file