Hello, community!
First of all, I would like to ask if I can do my project in constructsim because I do not have a laptop or desktop with Linux to do simulation?
Let me move on to my main question, Ι have a question about the project.
I saw the course on the basic kinematics of a mobile robot, but up to the point of a differential drive section 3.3. I was able to find the equations that give the wheel speeds (right and left) as you describe in 3.2, I also saw exercise 3.2 with its solution, but I was not able to understand it to modify my template code according to the solution.
Below are the tests I did in the code to print the values Vl and Vr.
#!/usr/bin/env python
"""
Test ROS Node
"""
import rospy, roslib
import operator
import time
import sys
#import pigpio
from math import sin, cos, atan2, pi, sqrt
import numpy as np
from std_msgs.msg import Float64
from geometry_msgs.msg import Twist
class TestNode():
"""Test node for templating"""
def __init__(self):
#ROS subscriber
self.sub = rospy.Subscriber('/cmd_listener', Twist, self._callback, queue_size=1)
self.twist_vels = Twist()
self.vr = Float64()
self.vl = Float64()
self.rate = rospy.Rate(1)
def _callback(self, msg):
L = 0.4 # L = 40cm
R = 0.05 # R = 5cm
self.twist_vels = msg
self.vr = ((2*self.twist_vels.linear.x) + (self.twist_vels.angular.z*L))/(2*R)
self.vl = ((2*self.twist_vels.linear.x) - (self.twist_vels.angular.z*L))/(2*R)
print(self.vr, self.vl)
def publish(self):
msg2pub = String()
msg2pub.data = 'test_msg'
while not rospy.is_shutdown():
self.pub.publish(msg2pub)
self.pub_rate.sleep()
def turn_off_node(self):
"""
Execute here the code when the node is terminated Ctrl + c
"""
pass
if __name__ == '__main__':
#Initialize the node
rospy.init_node("test_node")
#Create test node object
tn = TestNode()
#Handle shutdown
rospy.on_shutdown(tn.turn_off_node)
rospy.spin()
Eventually, I could not see the speed values, what mistake did I make in the code?
Thanks in advance!
Hello @vasileios.tzimas ,
Yes, you can do any project using TheConstruct platform. Remember that rosjects can only have up to 2GB of files, but it is enough for a big variety of projects.
I noticed you are mentioning about sections of the course. Are you running a similar simulation in the rosject? Are you running inside the course environment?
Regards
No, I tried the following code in my school lab on a Raspberry Pi with Ubuntu.
I understand.
In that case you must make sure you have messages arriving to the topic /cmd_listener
, since you are expecting to have these values printed in the _callback
method, right?
You can check that by using the commands:
rostopic list
rostopic echo
Do you have a node publishing to this topic?
It would be great if you can create a rosject where I can reproduce your environment and share with me. Could you do that? It would be easier to check your code
Regards
Yes, I do, dear. Let me think about how to do that! Give me some time!
1 Like
I think I created it right
Hello, did you see the rosject?
I have created a package named mobile_robot_diff_drive
Hi @vasileios.tzimas ,
Yes, I got it. But I see a script slightly different than the one you posted in the first moment.
You mention that you couldn’t see the calculated speeds, let me show you the result I got here using your rosject and maybe you can point me out what is missing. Here it is possible to see the calculated speeds being published in a second terminal like I show in the video below:
What was the expected result up to this point?
Regards
1 Like
Yes yes… I managed to see the result with the launch file.
If you look now I did it last night.
But is there a way to combine the two python files into one and just run that? That is, you do not need a launch file.
I understand.
If you want to keep both nodes in a single file, I would not recommend and I don’t think it is possible, as far as I know. This is the reference I found related to that: Is it possible to launch multiple nodes from one python script? - ROS Answers: Open Source Q&A Forum
If you need both nodes in the same file to launch at the computer startup, I suggest to look on how to do that using roslaunch:
Is that the case?
If you don’t need both nodes, but a single node that publishes and subscribes, yes this is totally possible. For example, from pub_vels.py to calc_speed.py, you would need to define the publisher:
pub = rospy.Publisher('/twist_vels', Twist, queue_size=1)
to the class and you can use inside the same loop, no problem at all. The thing is that you would need a logic if you want to setup different publishing rates to each one.
Is the topic published by pub_vels.py being subscribed by another node? The robot for example? If not, you could get rid of this topic and include the logic inside calc_speed.py, for example
Regards