Search Code
About Servo

First published 16 Nov 2009, with 4 revisions since.
Last update: 10 Feb 2010.
View history

Last change message: N/A

Related to

Servo_HelloWorld
Example to sweep a servo through its range
tag helloworld, PwmOut, Servo

WebTrafficMonitor
Example of a simple website hits/signup traffic monitor to drive a display (e.g. servo or panel meter) and indicator (e.g. bell, solenoid) based on responses from a webserver
tag ethernet, http, monitor, webserver


Pinewood_Derby_Timer
This is the end gate portion of a pinewood derby timer that uses an mbed. It communicates via HTTP to a web server that is doing the racer control and ...
tag derby, pinewood

EtonBreadboard1
Firmware for Eton breadboard


EtonBreadboard_091
Modification in routine to select substance


AVC_20110423
The software I used to run my Sparkfun AVC 2011 entry, a 1:10 scale RC truck called \"Data Bus\". This is the final revision of the code as-run on April ...
tag avc, robomagellan

MyFinalDerbot
Work for University.
tag Derby University, Kevin

ServoCamV1
This is the ServoCam Project, as shown here: http://youtu.be/riiqyXnckR4
tag mbed, ServoCam, servos, uart samera

TeaBasic
This will provide you with a nice little tea maker, which will dip your teabag in and take it out after a specified amount of time. You can set how ...
tag beginner, buttons, dipping, first, LCD, maker, matic, mbed, o, Servo, tea, wonderful

TeabagControlDevice
An updated and more polished version of the earlier TeaBasic. This is now finished and works like a treat.
tag control, device, maker, tea, teabag

Sorbonne2
Sorbonne 2 firmware
tag Sorbonne2

Exp5_RCservo
Exp5_RCservo
tag Exp5_RCservo

Exp5_ForceFeedback
Exp5_ForceFeedback
tag Exp5_ForceFeedback

GSL_09-HttpServer-RPC-Funcs_Servos
Code to demonstrate how to map 2 RPC functions to command 2 servo motors via REST HTTP Get request. Pretty useful to control a webcam PAN and TILT position when ...
tag camera, geeksessionlab, get, http, motor, pan, position, rest, rpc, Servo, tilt, webinterface

banda
El de mi banda transportadora + FPGA

Arm_Serial_Coordinates
Takes in serial coordinates (in mm) and moves servos in Lynxmotion AL5 arm accordingly.
tag RoboArm

rosserial_mbed
This program is porting rosserial_arduino for mbed http://www.ros.org/wiki/rosserial_arduino This program supported the revision of 169 of rosserial. This program contains an example.
tag ROS

Auto2
FET10 UNIMOG
tag FET10, UNIMOG

Servo
tag library, Servo

LineTracer_test
ライントレーサーのテストプログラムです。 コンパイルのみ 動作未チェック

RFID_doorlock
It is a door opener with mbed and Felica(RFID).
tag RFID

Import this program

Servo

Published 10 Feb 2010, by   user Simon Ford   tag library, Servo
Embed: (wiki syntax)

« Back to documentation index

You are viewing an out of date revision of Servo! View latest revision

Show/hide line numbers Servo.cpp Source File

Servo.cpp

00001 /* mbed R/C Servo
00002  * Copyright (c) 2007-2009 sford, cstyles
00003  * Released under the MIT License: http://mbed.org/license/mit
00004  */
00005 
00006 #include "Servo.h"
00007 #include "mbed.h"
00008 
00009 static float clamp(float value, float min, float max) {
00010     if(value < min) {
00011         return min;
00012     } else if(value > max) {
00013         return max;
00014     } else {
00015         return value;
00016     }
00017 }
00018 
00019 Servo::Servo(PinName pin) : _pwm(pin) {
00020     calibrate();
00021     write(0.5);
00022 }
00023 
00024 void Servo::write(float percent) {
00025     float offset = _range * 2.0 * (percent - 0.5);
00026     _pwm.pulsewidth(0.0015 + clamp(offset, -_range, _range));
00027     _p = clamp(percent, 0.0, 1.0);
00028 }
00029 
00030 void Servo::position(float degrees) {
00031     float offset = _range * (degrees / _degrees);
00032     _pwm.pulsewidth(0.0015 + clamp(offset, -_range, _range));
00033 }
00034 
00035 void Servo::calibrate(float range, float degrees) {
00036     _range = range;
00037     _degrees = degrees;
00038 }
00039 
00040 float Servo::read() {
00041     return _p;
00042 }
00043 
00044 Servo& Servo::operator= (float percent) { 
00045     write(percent);
00046     return *this;
00047 }
00048 
00049 Servo& Servo::operator= (Servo& rhs) {
00050     write(rhs.read());
00051     return *this;
00052 }
00053 
00054 Servo::operator float() {
00055     return read();
00056 }