import javax.microedition.midlet.MIDlet;To rotate a servo with Sun SPOT, you only have to write the following 2 lines.
import javax.microedition.midlet.MIDletStateChangeException;
// ...
public class SunSpotApplication extends MIDlet {
// ...
protected void startApp() throws MIDletStateChangeException {
System.out.println("Hello, world");
// ...
Servo serv0 = new Servo(EDemoBoard.getInstance().getOutputPins()[EDemoBoard.H0]);For the details about "how to move/turn a servo motor", please refer to Servomechanism or Google says a lot about it. Here it's enough for you to know that a servo needs constant "square wave" to move/turn itself and its wave length directly maps to servo angle (or velocity for continuous rotation servo). A typical servo expects to see a pulse every 20 milliseconds and a 1500 microseconds (1.5 millisecond) pulse will make the motor turn to the 90 degrees (it's called "Neutral" position). Other pulses will do it based on their lengths as follows:
serv0.setValue(2000);
- 1500 - value: 0 degrees
- 1500 + value: 180 degrees
If you have written embedded programs, you may notice it is not so easy to write the same program with C. Of course it depends on how many libraries you're provided, but typically you need a lot of include files as well as check how to use registers and command syntax for serial communication. Then, you also need to write a program that bring high a digital port, wait for around 1.5ms, bring low the same port (and loop these procedures for a while). Or even if you can use a bit high level operation like ATmega88 "8-bit Timer/Counter2 with PWM and Asynchronous Operation" to generate PWM (pulse-width modulation), the root complication is not solved as long as you use embedded C.
If you feel this is cool, NOW TIME TO CHANGE YOUR PLATFORM TO Sun SPOT!!
No comments:
Post a Comment