Making a Remote Controlled Car using Sun SPOT

10,826

Circuit Image

A remote Sun SPOT will transmit data to a Sun SPOT mounted on a car, which will control an integrated circuit (IC) according to the digital input/output pins D0 to D3. The IC will subsequently drive the motors that propel the car. The application utilizes various libraries from the Sun SPOT platform, including those for radiogram communication, peripheral management, and sensor integration. The remote Sun SPOT sends tilt values detected by its accelerometer to the car Sun SPOT, which interprets these values to control the car's movement.

The application begins by initializing the EDemoBoard instance and setting up a connection to the car Sun SPOT using its IEEE address. A continuous loop is established to read tilt data from the accelerometer. Based on the tilt values, specific control commands are generated and sent via radiogram to the car Sun SPOT. The control commands are determined by evaluating the tilt angles along the X and Y axes, with predefined thresholds to ascertain movement direction. The application also includes mechanisms for error handling and resource management, ensuring that connections are appropriately closed and LEDs are turned off when the application is terminated.

The control logic is encapsulated within the `getControl()` method, which returns specific numeric values representing the tilt conditions. These values correspond to different movement commands for the car, allowing for responsive control based on the remote Sun SPOT's orientation.

The overall architecture of the system relies on effective communication between the two Sun SPOT devices, leveraging wireless radiogram connections to facilitate real-time data exchange. This setup enables the remote control of the car based on physical tilt inputs, showcasing the integration of sensor data with motor control in an embedded system environment.Here remote Sun SPOT will send data to Sun SPOT on car which will drive the IC according to DC IO pins D0 - D3. The IC will drive the Motors which will run the car. package org. sunspotworld. demo; import com. sun. spot. io. j2me. radiogram. Radiogram; import com. sun. spot. io. j2me. radiogram. RadiogramConnection; import com. sun. spot. peripheral. NoRouteExcepti on; import com. sun. spot. peripheral. Spot; import com. sun. spot. peripheral. radio. IRadioPolicyManager; import com. sun. spot. sensorboard. EDemoBoard; import com. sun. spot. sensorboard. peripheral. ITriColorLED; import com. sun. spot. sensorboard. peripheral. IAccelerometer3D; import java. io. IOException; import javax. microedition. midlet. MIDletStateChangeException; import com. sun. spot. util. IEEEAddress; import com. sun. spot. util. Utils; import javax. microedition. io. Connector; /** * Remote Spot will send Tilt values to the Car Spot. * * @author Jay Mahadeokar */ public class StartApp extends javax. microedition. midlet. MIDlet { EDemoBoard demoboard = EDemoBoard. getInstance(); protected void startApp() throws MIDletStateChangeException { IRadioPolicyManager rpm = Spot. getInstance(). getRadioPolicyManager(); IEEEAddress myAddr = new IEEEAddress(rpm. getIEEEAddress(); System. out. println("Hi! my address = " + myAddr. asDottedHex(); //This is my Car Sun SPOT address IEEEAddress bsAddress = new IEEEAddress(new String("0014.

4F01. 0000. 1231"); IAccelerometer3D acc = demoboard. getAccelerometer(); while(true) { try{ RadiogramConnection conn = (RadiogramConnection)Connector. open("radiogram://0014. 4F01. 0000. 1A29:10"); Radiogram rdg = (Radiogram)conn. newDatagram(conn. getMaximumLength(); try { //Get control called and value sent to car spot! rdg. writeUTF(""+getControl(); conn. send(rdg); Utils. sleep(200); // Sleep for sometime! } catch (NoRouteException e) { System. out. println ("No route to 0014. 4F01. 0000. 1A29"); } finally { conn. close(); } } catch(IOException e){ System. out. println("There is a problem opening the connection"); } } } //Returns the numeric value corresponding to the current Tilt Positions of //Sun SPOT //Return values only if Tilt > 0. 5 or Tilt < -0. 5 public int getControl() { int ret = 0; try { double xTilt = demoboard. getAccelerometer(). getTiltX(); double yTilt = demoboard. getAccelerometer(). getTiltY(); if (xTilt > 0. 5 && yTilt < 0. 5 && yTilt > -0. 5) { ret = 110; } if (xTilt < -0. 5 && yTilt < 0. 5 && yTilt > -0. 5) { ret = 101; } if (yTilt > 0. 5 && xTilt < 0. 5 && xTilt > -0. 5) { ret = 100; } if (yTilt < -0. 5 && xTilt < 0. 5 && xTilt > -0. 5) { ret = 1000; } } catch (IOException ex) { ex. printStackTrace(); } return ret; } protected void destroyApp(boolean unconditional) throws MIDletStateChangeException { ITriColorLED [] leds = EDemoBoard.

getInstance(). getLEDs(); for (int i = 0; i < 8; i+) { // turn off the LEDs when we exit leds[i]. setOff(); } } protected void pauseApp() { } } import com. sun. spot. io. j2me. radiogram. Radiogram; import com. sun. spot. io. j2me. radiogram. RadiogramConnection; import com. sun. spot. peripheral. NoRouteException; import com. sun. spot. peripheral. Spot; import com. sun. spot. peripheral. radio. IRadioPolicyManager; import com. sun. spot. sensorboard. EDemoBoard; import com. sun. spot. sensorboard. peripheral. ITriColorLED; import com. sun. spot. sensorboard. peripheral. IAccelerometer3D; import java. io. IOException; import javax. microedition. midlet. MIDletStateChangeException; import com. sun. spot. util. IEEEAddress; import com. sun. spot. util. Utils; import javax. microedition. io. Connector; /** * Remote Spot will send Tilt values to the Car Spot. * * @author Jay Mahadeokar */ public class StartApp extends javax. microedition. midlet. MIDlet { EDemoBoard demoboard = EDemoBoard. getInstance(); protected void startApp() throws MIDletStateChangeException { //This is my Car Sun SPOT address IEE 🔗 External reference




Warning: include(partials/cookie-banner.php): Failed to open stream: Permission denied in /var/www/html/nextgr/view-circuit.php on line 713

Warning: include(): Failed opening 'partials/cookie-banner.php' for inclusion (include_path='.:/usr/share/php') in /var/www/html/nextgr/view-circuit.php on line 713