Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MeArm_Servo_Calibration by
Revision 1:b9119bdd3ca9, committed 2017-07-04
- Comitter:
- eencae
- Date:
- Tue Jul 04 17:37:15 2017 +0000
- Parent:
- 0:68133f5cdfa0
- Commit message:
- Initial commit
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Jul 04 15:52:22 2017 +0000
+++ b/main.cpp Tue Jul 04 17:37:15 2017 +0000
@@ -1,4 +1,4 @@
-/* MeArm Servo Calibration
+/* MeArm Lab 1 Task 1
(c) Dr Craig A. Evans, University of Leeds
@@ -12,13 +12,11 @@
AnalogIn m_pot(p17);
AnalogIn l_pot(p18);
AnalogIn r_pot(p19);
-AnalogIn c_pot(p20);
// PWM pins for servos
PwmOut m_servo(p21);
PwmOut l_servo(p22);
PwmOut r_servo(p23);
-PwmOut c_servo(p24);
int main()
{
@@ -29,27 +27,17 @@
// keep looping forever
while(1) {
- // read val in range 0.0 to 1.0
+ // read val in range 0.0 to 1.0,
float m_pot_val = m_pot.read();
- // create a pulse-width value in range 400 to 3000us
- int m_pot_pulse_us = int(400.0 + m_pot_val*2600.0);
- m_servo.pulsewidth_us(m_pot_pulse_us);
-
- // repeat for other servos
- float l_pot_val = l_pot.read();
- int l_pot_pulse_us = int(600.0 + l_pot_val*2600.0);
- l_servo.pulsewidth_us(l_pot_pulse_us);
+ // convert to -90 to +90
+ float m_angle = -90.0+180.0*m_pot_val;
- float r_pot_val = r_pot.read();
- int r_pot_pulse_us = int(600.0 + r_pot_val*2600.0);
- r_servo.pulsewidth_us(r_pot_pulse_us);
+ // plug into linear equation to convert to pulse-width
+ int m_pulse_us = int(1650.0 + 11.0*m_angle);
+ // move servo
+ m_servo.pulsewidth_us(m_pulse_us);
- float c_pot_val = c_pot.read();
- int c_pot_pulse_us = int(600.0 + c_pot_val*2600.0);
- c_servo.pulsewidth_us(c_pot_pulse_us);
-
- // print the values to the PC terminal
- printf("M=%i L=%i R=%i C=%i\n",m_pot_pulse_us,l_pot_pulse_us,r_pot_pulse_us,c_pot_pulse_us);
+ // ADD in code for left and right servos
// delay as we don't want to update the servos too often
wait_ms(200);
