Difference between revisions of "HamsterPython"

From cogniteam
Jump to: navigation, search
 
(35 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
{{DISPLAYTITLE:Hamster Python API}}
 +
[[Category:Hamster]]
 +
 
=== Python setup ===
 
=== Python setup ===
* Note you are on the HamsterNet
+
* Note you are connected to the hamster_net (wifi / router)
  
 
<syntaxhighlight lang="bash" line='line'>
 
<syntaxhighlight lang="bash" line='line'>
Line 10: Line 13:
 
</syntaxhighlight>
 
</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>
  
=== Python Example 1, read Laser from robot ===
+
* Install dependencies
  
<syntaxhighlight lang="python" line='line'>
+
<syntaxhighlight lang="bash" line='line'>
#!/usr/bin/env python
+
sudo apt-get install ros-kinetic-desktop ros-kinetic-ackermann-*
import rospy
+
</syntaxhighlight>
from sensor_msgs.msg import LaserScan
 
  
def is_free(ranges ,start_index, end_index ,min_distance):
+
=== Beginner tutorials ===
s_ranges = ranges[start_index:end_index]
 
b_ranges = [i for i in s_ranges if i <= min_distance]
 
if len(b_ranges) > 1 :print "BLOCKED"
 
else : print "FREE"
 
  
+
* Exercise 1 - [https://wiki.cogni.io/index.php/HamsterPythonExample1 | Process laser Scan ]
def callback(msg):    
+
* Exercise 2 - [https://wiki.cogni.io/index.php/HamsterPythonExample2 | Process inertial measurement unit (IMU) ]
is_free(msg.ranges,160,200,0.2)
+
* Exercise 3 - [https://wiki.cogni.io/index.php/HamsterPythonExample3 | Move until collision ]
 
rospy.init_node('scan_values')
 
 
 
#Put your Hamster number instead of agent<number>
 
#The agent number is printed on the Hamster cover
 
sub = rospy.Subscriber('/agent14/scan', LaserScan, callback)
 
rospy.spin()
 
 
 
</syntaxhighlight>
 

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