Revision: 8040
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8040&view=rev
Author:   thjc
Date:     2009-07-16 18:58:03 +0000 (Thu, 16 Jul 2009)

Log Message:
-----------
added example from patch 2707273
A new example using libplayerc_py

Added Paths:
-----------
    code/player/trunk/examples/python/
    code/player/trunk/examples/python/laser_obstacle_avoid.py

Added: code/player/trunk/examples/python/laser_obstacle_avoid.py
===================================================================
--- code/player/trunk/examples/python/laser_obstacle_avoid.py                   
        (rev 0)
+++ code/player/trunk/examples/python/laser_obstacle_avoid.py   2009-07-16 
18:58:03 UTC (rev 8040)
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+
+import math
+from playerc import *
+
+def limit(val, bottom, top):
+    if val > top:
+        return top
+    elif val < bottom:
+        return bottom
+    return val
+
+# Create a client object
+c = playerc_client(None, 'localhost', 6665)
+# Connect it
+if c.connect() != 0:
+  raise playerc_error_str()
+
+# Create a proxy for position2d:0
+p = playerc_position2d(c,0)
+if p.subscribe(PLAYERC_OPEN_MODE) != 0:
+  raise playerc_error_str()
+
+# Retrieve the geometry
+if p.get_geom() != 0:
+  raise playerc_error_str()
+print 'Robot size: (%.3f,%.3f)' % (p.size[0], p.size[1])
+
+# Create a proxy for laser:0
+l = playerc_laser(c,0)
+if l.subscribe(PLAYERC_OPEN_MODE) != 0:
+  raise playerc_error_str()
+
+# Retrieve the geometry
+if l.get_geom() != 0:
+  raise playerc_error_str()
+#print 'Laser pose: (%.3f,%.3f,%.3f)' % (l.pose[0],l.pose[1],l.pose[2])
+
+while True:
+    if c.read() == None:
+        raise playerc_error_str()
+    minR = l.min_right
+    minL = l.min_left
+
+    print "minR:", minR, "minL:", minL
+    left = (1e5*minR)/500-100
+    right = (1e5*minL)/500-100
+
+    if left > 100:
+        left = 100
+    if right > 100:
+        right = 100
+
+    newspeed = (right+left)/1e3
+
+    newturnrate = (right-left)
+    newturnrate = limit(newturnrate, -40.0, 40.0)
+    newturnrate = math.radians(newturnrate)
+
+    print "speed: ", newspeed, "turn: ", newturnrate
+    print help(p.set_cmd_vel)
+
+    p.set_cmd_vel(newspeed, newspeed, newturnrate, 1)
+
+# Clean up
+p.unsubscribe()
+l.unsubscribe()
+c.disconnect()
+
+
+                


Property changes on: code/player/trunk/examples/python/laser_obstacle_avoid.py
___________________________________________________________________
Added: svn:mime-type
   + text/plain


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to