Introducing the Sun SPOTs

  • 4,401 views
Uploaded on

Slides of presentation given at Sun Tech Days 2007 in Milan about Sun SPOTs programming.

Slides of presentation given at Sun Tech Days 2007 in Milan about Sun SPOTs programming.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,401
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
0
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Introducing the Sun SPOTs Stefano Sanna Senior Developer JUG Sardegna ONLUS 1
  • 2. About Me • Senior developer @ beeweeb technologies • Technical writer @ DEV, Computer Programming, Java Journal... • Supporter @ JUG Sardegna, JMDF, JIA, GULCh • LEGO constructor since 1973... 2
  • 3. Java User Groups in Italy 3
  • 4. Program the (Real) World • Wireless sensor networks open new exciting scenarios: > pervasive monitoring of environment and structures > massive distributed intelligence > urban smart objects • Programmable Objects for Real World > connected: the Internet of Things > autonomous: local CPU, local memory, local code > environment-aware: sensors > safe and robust 4
  • 5. Sensors: New Frontier of Interaction • To be programmable and connected is not enough! • The ability to “perceive” the surroundings is the next interaction frontier for consumer and mobile devices • Gaming console, mobile phones, automotive appliances, embedded systems: any object is expected to “sense” and act according to physical quantity such as temperature, light, acceleration, position, humidity, proximity... 5
  • 6. Sensors in the Java ME World • Java ME is leading technology for mobile applications, ranging from cellular phones to embedded systems • A rich set of standard API enables multimedia capabilities, 2D and 3G graphics, local and remote connectivity, location, NFC... • The Java Community Process has published the Mobile Sensor API (JSR 256) for accessing devices such as accelerometers, thermometers, light sensor 6
  • 7. Introducing the Project Sun SPOTs Small Programmable Object Technology • Project from Sun Laboratories • Platform for intelligent wireless sensors network • Live-laboratory for implementing new computing scenarios: > The (Inter)net of Things > Program the world 7
  • 8. Sun SPOT Presentations 8
  • 9. SPOTs Hardware • Processor Board > 180 MHz 32 bit ARM920T core 512K RAM/4M Flash > 2.4 GHz IEEE 802.15.4 radio with integrated antenna > USB interface > 3.7V rechargeable 720 mAh lithium-ion battery > 32 uA deep sleep mode 9
  • 10. SPOTs Hardware • Demo Sensor Board > 2G/6G 3-axis accelerometer > Temperature sensor > Light sensor > 8 tri-color LEDs > 6 analog inputs, 2 switches > 5 general purpose I/O pins > 4 high current output pins 10
  • 11. SPOTs Software • Squawk Virtual Machine > Fully capable J2ME CLDC 1.1 Java VM with OS functionality > VM executes directly out of flash memory > Device drivers written in Java > Automatic battery management 11
  • 12. Sun SPOT Java Development Kit 12
  • 13. Free-Range and Basestation • Sun SPOT Development Kit provides: > Two free-range SPOTs, equipped with Processor Board, radio interface, Demo Sensor and battery > One basestation SPOT, with Processor Board and radio interface > SDK for Windows, Mac OS X, Linux > USB cable 13
  • 14. Development • SDK comprises libraries and utilities for compiling and packaging bytecode, updating SPOTs firmware, running basestation applications • SDK is based on Ant tasks and can be integrated in any IDE, e.g. Netbeans • SPOTs support remote installation, execution and debugging of applications through wireless connection 14
  • 15. Applications • Sun SPOT Applications > Run on free-range SPOTs > CLDC 1.1 and IMP 1.0 application model > Full access to peripherals and demo board • Sun SPOT Host Applications > Run on a SPOT configured as basestation > Stand-alone application model > Simultaneous access to SPOT and JSE libraries 15
  • 16. Classes, Devices, Sensors, Interfaces • There are over 400 classes documented in the Sun SPOT javadoc: nearly three times the MIDP 2.0 specification! :-) • The Sun SPOT device library contains drivers and high-level classes to access physical interfaces and peripherals: > ILed > IlightSensor, IAccelerometer3D > IFlashMemoryDevice > IPowerController > IPWMOutput > IAT91_PIO, IAT91_IAC... 16
  • 17. Radio Communication • Sun SPOTs come with low-range IEEE 802.15.4 radio module • Communication API is based on Generic Connection Framework and provides: > RadioConnection (radio://) from stream-based communication > RadiogramConnection (radiogram://) for datagram based communication > basestation may act as proxy for HTTP connections 17
  • 18. Sun SPOTs Projects • Many projects based on Sun SPOTs have been published on the Web: just use your preferred search engine or video repository to find them! 18
  • 19. Mashing-up Hardware and Software • The Sun SPOTs let developers build their custom interfaces for virtually any kind of electronic peripheral: > sensors > motors > microcontrollers > radio equipment 19
  • 20. Be Careful with Solder... :-( • However, soldering and designing circuits and interfaces for physical components require some specific expertise • Wrong assembly or accidental short circuit may definitively damage your SPOTs and/or your peripherals • How can we exploit Sun SPOTs potential without setting-up a electronic lab? 20
  • 21. Fun for Everyone! :-) • Thanks to the basestation, we can use the PC as gateway to any resource such as USB devices, network hosts and Bluetooth peripherals • LEGO Mindstorms NXT kit provides: > Easy and flexible > 3 outputs > 4 inputs > Bluetooth and USB interfaces > Open source iCommand Java library provides easy and powerful API for remote NXT control 21
  • 22. “Real” Gesture Controller for Vehicle USB 802.15.4 radio Bluetooth 22
  • 23. Overview • The Gesture Controller > Runs on a free-range SPOT > Reads tilt degrees on X and Y axes > Sends message to Vehicle Controller • The Vehicle Controller > Runs on the basestation > Receives messages from Gesture Controller > Sends commands to NXT Vehicle 23
  • 24. The Gesture Controller (source.1) public class SunSpotApplication extends MIDlet { private IAccelerometer3D accelerometer = EDemoBoard.getInstance().getAccelerometer(); private ISwitch switch1; private int st=0; private RadiogramConnection conn; protected void startApp() throws MIDletStateChangeException{ switch1 = EDemoBoard.getInstance().getSwitches()[0]; runSwitchWatcher(); } 24
  • 25. The Gesture Controller (source.2) protected void pauseApp() { // This will never be called by the Squawk VM } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { } 25
  • 26. The Gesture Controller (source.3) private void runSwitchWatcher(){ Thread t1 = new Thread(){ public void run(){ sw1.waitForChange(); if (conn == null) { try { conn = (RadiogramConnection) Connector.open(quot;radiogram://broadcast:133quot;); startAccelerometerWatcher(); } catch (Exception e) { } } } }; t1.start(); } 26
  • 27. The Gesture Controller (source.4) public void startAcceWatchThreadd(){ Thread t2 = new Thread() { public void run() { while(true){ readTildAndSend(); } } }; t2.start(); } 27
  • 28. The Gesture Controller (source.5) private void readTiltAndSend() { try { int tiltX = (int) Math.toDegrees(acc.getTiltX()); int tiltY = (int) Math.toDegrees(acc.getTiltY()); String data = Integer.toString(tiltX) + quot;#quot; + Integer.toString(tiltY); send(data); } catch (IOException ex) { } try { Thread.sleep(100); } catch (InterruptedException ex) { } } 28
  • 29. The Gesture Controller (source.6) private synchronized void send(String data) { if (conn != null) { try{ Datagram datagram = conn.newDatagram(conn.getMaximumLength()); datagram.writeUTF(data); conn.send(datagram); } catch(IOException e){ } } } } 29
  • 30. The Vehicle Controller (source.1) public class SunSpotHostApplication { private static final int FORWARD = 0; private static final int BACKWARD = 1; private static final int RIGHT = 2; private static final int LEFT = 3; private static final int STOP = 4; private int last = STOP; private static Pilot pilot; // iCommand Java NXT Library public static void main(String[] args) { SunSpotHostApplication app = new SunSpotHostApplication(); startNXT(); app.start(); } 30
  • 31. The Vehicle Controller (source.2) private static void startNXT() { try { NXTCommand.open(); pilot = new Pilot(2.1f,4.4f,Motor.A, Motor.C,true); } catch(Exception e) { e.printStackTrace(); } } 31
  • 32. The Vehicle Controller (source.3) public void run() { try{ RadiogramConnection conn = (RadiogramConnection) Connector.open(quot;radiogram://:133quot;); Datagram datagram = conn.newDatagram(conn.getMaximumLength()); while(true){ datagram.reset(); conn.receive(datagram); String rawData = datagram.readUTF(); String[] tokens = rawData.split(quot;#quot;); moveVehicle(tokens[0], tokens[1]); } }catch(IOException e){ e.printStackTrace(); } } 32
  • 33. The Vehicle Controller (source.4) private void moveVehicle(String accelX, String accelY) { int tiltX = (int) Double.parseDouble(accelX); int tiltY = (int) Double.parseDouble(accelY); if (tiltY > 15) { if (last != BACKWARD) { pilot.backward(); last = BACKWARD; } } else if (tiltY < -15) { if (last != FORWARD) { pilot.forward(); last = FORWARD; } } 33
  • 34. The Vehicle Controller (source.5) else if (tiltX < -25) { if (last != RIGHT) { pilot.rotate(30); last = RIGHT; } } else if (tiltX > 25) { if (last != LEFT) { pilot.rotate(-30); last = LEFT; } } else { if (last != STOP) { pilot.stop(); last = STOP; } 34
  • 35. DEMO (Murphy Law loading... please wait...) 35
  • 36. Conclusions • Sensors are the new frontier of interaction • The Sun SPOTs are the quot;cool Java wayquot; to create a quot;live labquot; for innovative scenarios of ubiquitous and pervasive computing • Extended class library and full integration of basestation with desktop PC gives everybody the opportunity to HAVE FUN with SPOT 36
  • 37. References • Sun SPOT World > http://www.sunspotworld.com • Sun SPOTs and Java robotics on java.net > https://sunspot-robotics.dev.java.net/ > http://community.java.net/robotics/ • Sun SPOT purchasing: > http://www.sunspotworld.com/products > http://store.systronix.com • LEGO Mindstorms NXT > http://mindstorms.lego.com > http://lejos.sourceforge.net 37
  • 38. Contacts • Stefano Sanna > gerdavax@tiscali.it – http://www.gerdavax.it • JUG Sardegna ONLUS > http://www.jugsardegna.org • Java Mobile Developers Forum > http://www.jmdf.org 38
  • 39. Introducing the Sun SPOTs Stefano Sanna Senior Developer JUG Sardegna ONLUS 39