Difference between revisions of "HamsterPython"

From cogniteam
Jump to: navigation, search
 
(37 intermediate revisions by the same user not shown)
Line 1: Line 1:
<syntaxhighlight lang="python" line='line'>
+
{{DISPLAYTITLE:Hamster Python API}}
#!/usr/bin/env python
+
[[Category:Hamster]]
import rospy
 
from sensor_msgs.msg import LaserScan
 
  
def is_free(ranges ,start_index, end_index ,min_distance):
+
=== Python setup ===
s_ranges = ranges[start_index:end_index]
+
* Note you are connected to the hamster_net (wifi / router)
b_ranges = [i for i in s_ranges if i <= min_distance]
 
if len(b_ranges) > 1 :print "BLOCKED"
 
else : print "FREE"
 
  
   
+
<syntaxhighlight lang="bash" line='line'>
def callback(msg):    
+
  $ export ROS_IP=<your IP>
is_free(msg.ranges,160,200,0.2)
+
</syntaxhighlight>
   
+
 
rospy.init_node('scan_values')
+
<syntaxhighlight lang="bash" line='line'>
 +
$ export ROS_MASTER_URI=http://10.0.2.<HAMSTER AGENT Number>:11311
 +
</syntaxhighlight>
 +
 
 +
* If the Hamster is powered and your terminal is well configured you should be able to
 +
See all data streams
 +
<syntaxhighlight lang="bash" line='line'>
 +
  $ rostopic list
 +
</syntaxhighlight>
 +
See imagery from the robot
 +
<syntaxhighlight lang="bash" line='line'>
 +
$ rqt_image_view
 +
</syntaxhighlight>
  
#Put your Hamster number instead of agent<number>
+
* Install dependencies
#The agent number is printed on the Hamster cover
 
sub = rospy.Subscriber('/agent14/scan', LaserScan, callback)
 
rospy.spin()
 
  
 +
<syntaxhighlight lang="bash" line='line'>
 +
sudo apt-get install ros-kinetic-desktop ros-kinetic-ackermann-*
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
=== Beginner tutorials ===
 +
 +
* Exercise 1 - [https://wiki.cogni.io/index.php/HamsterPythonExample1 | Process laser Scan ]
 +
* Exercise 2 - [https://wiki.cogni.io/index.php/HamsterPythonExample2 | Process inertial measurement unit (IMU) ]
 +
* Exercise 3 - [https://wiki.cogni.io/index.php/HamsterPythonExample3 | Move until collision ]

Latest revision as of 09:21, 24 March 2019


Python setup

  • Note you are connected to the hamster_net (wifi / router)

<syntaxhighlight lang="bash" line='line'>

$ export ROS_IP=<your IP>

</syntaxhighlight>

<syntaxhighlight lang="bash" line='line'>

$ export ROS_MASTER_URI=http://10.0.2.<HAMSTER AGENT Number>:11311

</syntaxhighlight>

  • If the Hamster is powered and your terminal is well configured you should be able to

See all data streams <syntaxhighlight lang="bash" line='line'>

$ rostopic list

</syntaxhighlight> See imagery from the robot <syntaxhighlight lang="bash" line='line'>

$ rqt_image_view

</syntaxhighlight>

  • Install dependencies

<syntaxhighlight lang="bash" line='line'> sudo apt-get install ros-kinetic-desktop ros-kinetic-ackermann-* </syntaxhighlight>

Beginner tutorials