<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.cognimbus.com/index.php?action=history&amp;feed=atom&amp;title=HamsterPythonExample2</id>
		<title>HamsterPythonExample2 - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.cognimbus.com/index.php?action=history&amp;feed=atom&amp;title=HamsterPythonExample2"/>
		<link rel="alternate" type="text/html" href="http://wiki.cognimbus.com/index.php?title=HamsterPythonExample2&amp;action=history"/>
		<updated>2026-06-14T21:48:30Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.28.2</generator>

	<entry>
		<id>http://wiki.cognimbus.com/index.php?title=HamsterPythonExample2&amp;diff=881&amp;oldid=prev</id>
		<title>Ariy at 09:17, 24 March 2019</title>
		<link rel="alternate" type="text/html" href="http://wiki.cognimbus.com/index.php?title=HamsterPythonExample2&amp;diff=881&amp;oldid=prev"/>
				<updated>2019-03-24T09:17:57Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 09:17, 24 March 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot; &gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Python Example 2 ===&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Python Example 2 ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Detect right/left turn from IMU&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Detect right/left turn from &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Inertial Measurement Unit (&lt;/ins&gt;IMU&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;)&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;* That Hamster IMU has 10 degrees of freedom (3 accelerometer, 3 gyro, 3 magnetometer, 1 barometer)&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* IMU angles are represented in Quaternions [[https://en.wikipedia.org/wiki/Quaternion]] hence translated to RPY (roll pitch yaw)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* IMU angles are represented in Quaternions [[https://en.wikipedia.org/wiki/Quaternion]] hence translated to RPY (roll pitch yaw)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* RPY are in radians, translated to degrees&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* RPY are in radians, translated to degrees&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l51&quot; &gt;Line 51:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 52:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; $ python example2.py&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; $ python example2.py&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== Ex.2 ==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* Write a function that will detect if the hamster is stationary or in motion from the IMU&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key cogniteam_wiki:diff:version:1.11a:oldid:877:newid:881 --&gt;
&lt;/table&gt;</summary>
		<author><name>Ariy</name></author>	</entry>

	<entry>
		<id>http://wiki.cognimbus.com/index.php?title=HamsterPythonExample2&amp;diff=877&amp;oldid=prev</id>
		<title>Ariy: Created page with &quot;=== Python Example 2 === Detect right/left turn from IMU * IMU angles are represented in Quaternions https://en.wikipedia.org/wiki/Quaternion hence translated to RPY (roll...&quot;</title>
		<link rel="alternate" type="text/html" href="http://wiki.cognimbus.com/index.php?title=HamsterPythonExample2&amp;diff=877&amp;oldid=prev"/>
				<updated>2019-03-24T09:04:26Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;=== Python Example 2 === Detect right/left turn from IMU * IMU angles are represented in Quaternions &lt;a href=&quot;/index.php?title=Https://en.wikipedia.org/wiki/Quaternion&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Https://en.wikipedia.org/wiki/Quaternion (page does not exist)&quot;&gt;https://en.wikipedia.org/wiki/Quaternion&lt;/a&gt; hence translated to RPY (roll...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=== Python Example 2 ===&lt;br /&gt;
Detect right/left turn from IMU&lt;br /&gt;
* IMU angles are represented in Quaternions [[https://en.wikipedia.org/wiki/Quaternion]] hence translated to RPY (roll pitch yaw)&lt;br /&gt;
* RPY are in radians, translated to degrees&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line='line'&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
import rospy&lt;br /&gt;
import math&lt;br /&gt;
from sensor_msgs.msg import Imu&lt;br /&gt;
from tf.transformations import euler_from_quaternion, quaternion_from_euler&lt;br /&gt;
&lt;br /&gt;
def calculate_robot_angle(orientation):&lt;br /&gt;
	quaternion = (&lt;br /&gt;
	    orientation.x,&lt;br /&gt;
	    orientation.y,&lt;br /&gt;
	    orientation.z,&lt;br /&gt;
	    orientation.w)&lt;br /&gt;
	euler = euler_from_quaternion(quaternion)&lt;br /&gt;
	roll = euler[0]&lt;br /&gt;
	pitch = euler[1]&lt;br /&gt;
	yaw = euler[2]&lt;br /&gt;
	return math.degrees(yaw)&lt;br /&gt;
&lt;br /&gt;
prev_angle = 0&lt;br /&gt;
def callback(msg):	&lt;br /&gt;
	global prev_angle	    &lt;br /&gt;
	curr_angle = calculate_robot_angle(msg.orientation)&lt;br /&gt;
	if curr_angle &amp;gt; prev_angle :&lt;br /&gt;
		print &amp;quot;TURINING LEFT&amp;quot;&lt;br /&gt;
	else:&lt;br /&gt;
		print &amp;quot;TURINIGN RIGHT&amp;quot;&lt;br /&gt;
	prev_angle = curr_angle&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
rospy.init_node('imu_values')&lt;br /&gt;
&lt;br /&gt;
#Put your Hamster number instead of agent&amp;lt;number&amp;gt;&lt;br /&gt;
#The agent number is printed on the Hamster cover &lt;br /&gt;
sub = rospy.Subscriber('/agent14/imu', Imu, callback)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
rospy.spin()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To execute save this example in example2.py and type in the terminal &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line='line'&amp;gt;&lt;br /&gt;
 $ python example2.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ariy</name></author>	</entry>

	</feed>