]> rtime.felk.cvut.cz Git - orte.git/commitdiff
ROBOT_DEMO: fix sync. problems in publisher for "motion_speed"
authorMartin Vajnar <martin.vajnar@gmail.com>
Mon, 5 Aug 2013 21:37:29 +0000 (23:37 +0200)
committerMartin Vajnar <martin.vajnar@gmail.com>
Mon, 5 Aug 2013 21:37:29 +0000 (23:37 +0200)
Don't use synchronized(), because it may block the setSpeed() and prevent
receiving new data from accelerometer. The isSent variable is now used
to determine whether we need new data.

Add robot's IP address to the list of fellow managers.

orte/Robot_Demo/src/org/ocera/orte/demo/HokuyoScanSubscribe.java
orte/Robot_Demo/src/org/ocera/orte/demo/MainActivity.java
orte/Robot_Demo/src/org/ocera/orte/demo/MotionSpeedPublish.java

index 22a47e8ebe1fe82ad7f37d534dec3b7044a44f7e..97b5cd58fe112eb69a0754a6b76c41b99664afa4 100644 (file)
@@ -25,7 +25,7 @@ public class HokuyoScanSubscribe extends SubscriptionCallback{
                this.domainApp = domainApp;
                
            NtpTime deadline      = new NtpTime(10);
-           NtpTime minSeparation = new NtpTime(0,773094113);
+           NtpTime minSeparation = new NtpTime(0);
            
            hokuyomsg = new HokuyoScanType(domainApp, "hokuyo_scan");
                
index d2b61d1210b737366823694752d521b9aec30c8d..249e508bf6f6163eaabe384efb300c3a193eb9c5 100644 (file)
@@ -18,7 +18,7 @@ import android.view.MenuItem;
 public class MainActivity extends Activity {
        
        private Manager manager = null;
-    private String[] mgrs = {"192.168.1.5","192.168.1.8"};
+    private String[] mgrs = {"192.168.1.5","192.168.1.8","10.1.1.1"};
        private MotionSpeedPublish motion_speed = null;
        private HokuyoScanSubscribe hokuyo_scan = null;
     private SensorManager mSensorManager = null;
@@ -55,6 +55,7 @@ public class MainActivity extends Activity {
         if (hokuyo_scan != null && !hokuyo_scan.isCancelled()) {
                        hokuyo_view.run(false);
                        hokuyo_scan.cancel();
+                       hokuyo_view.invalidate();
                        hokuyo_item.setTitle("Start hokuyo");
         }
         
@@ -165,4 +166,4 @@ public class MainActivity extends Activity {
                 }
        }
     }
-}
\ No newline at end of file
+}
index d9a985076a16af13a62a7d7100a0044d45b01fd0..af04f65aed54266aceae15561aa4451a39580875 100644 (file)
@@ -13,11 +13,11 @@ public class MotionSpeedPublish implements Runnable {
        
        private short[] speed = new short[2];
        private boolean isCancelled = false;
+       private boolean isSent = true;
        private float maxRange;
        private float[] accelData = new float[2];
        private SpeedMotionType speedmsg;
        private Publication pub;
-       private Object lock = new Object();
        private Thread thread = null;
        private PublProp publProp;
        private DomainApp appDomain;
@@ -81,22 +81,20 @@ public class MotionSpeedPublish implements Runnable {
        @Override
        public void run() {
            while(!isCancelled) {
-             synchronized(lock) {
-                 calculateSpeed(accelData);
-                 speedmsg.speed = this.speed;
-                 
-                 pub.send(speedmsg);
-             }
-             
+             calculateSpeed(accelData.clone());
+             speedmsg.speed = this.speed.clone();  
+             pub.send(speedmsg);
+             isSent = true;
          JOrte.sleepMs(100);
                }
        }
        
        public void setSpeed(float accelX, float accelY) {
-               synchronized(lock) {
+               if(isSent) {
+                       isSent = false;
                        this.accelData[0] = accelX;
                        this.accelData[1] = accelY;
                }
        }
        
-}
\ No newline at end of file
+}