Notifications
Clear all

ROS package: qbo_control

24 Posts
4 Users
6 Reactions
3,407 Views
caju
 caju
(@caju)
Member
Joined: 4 years ago
Posts: 22
Topic starter  

Hello Romeo, first of all, congrats for writing your first node. The node is really okey, but there are few things that I would like to comment to help you improve it. Hope I can be clear in my answer, with any doubt don't hesitate on asking.

First of all, I see that your code has no identation, what is needed in Python, but I assume that it is because of the copy-paste in the comment (just to make sure)

After that, I will start with the comments related to ROS. Firstly, I see that you have used the same scheme that I use to program in ROS, I hope you understand it, I do it like that because it is the best way I have found to structure my nodes, but it is just my way of writing. If you have any question regarding it, just feel free to ask.

I will recomend you not to name the running function "Sensor_cb()". In my case, the suffix "_cb" is the one I use to specify that it is a ROS callback, it means that is a function that will be executed when the subscriber related to that function calls it every time a message is received. It has no importance, is only a naming convention, but as it can lead to some missunderstanding I wanted to tell you. In that way, I would recommend you to call the function something like "sensor_run" or "sensor_main", just to indicate that it is the main running function that is going to be executing all the time and controls the workflow of your code.

Another issue, maybe the most important, is that you are defining every time your publisher and the best would be to define it only once at the beginning, although as you have it your code will also work. I would recomend you to remove the line "pub = rospy.Publisher('test_1', String, queue_size=10)" and write it into the __init__ of the class, but adding at the beginning a "self." to declare the publisher object as global inside the class: "self.pub = rospy.Publisher('test_1', String, queue_size=10)". Then, when publishing, you should change your line "pub.publish(touch_str)" to "self.pub.publish(touch_str)"

The last thing, is just an annotation, because you are importing the library: "from std_msgs.msg import UInt8" to use the msg type UInt8. However, you don't need it in your code, so you can remove it. Anyway, it won't cause you any problem, but I just wanted to indicate it to you only to remind you that if in future projects you need to use different msg types as, for example, UInt8MultiArray from std_msgs, you will need to import it so that you can use that message type.

 

That's all, as you see, are just some little changes because you have done it really well. So, well done! 😀 👍 

 


   
ReplyQuote
(@romeo)
Member
Joined: 6 years ago
Posts: 76
 

Hi caju, thanks for the useful advice you have given me and which show that I am not yet very familiar with python and ros. (I forgot the instruction "from std_msgs.msg import UInt8" because I originally wanted to export the "touch" value ... in any case I tried to fre a new node for the microphone ... which I attach to this post, where I I followed your advice better and that perhaps (with appropriate precautions) could be useful, at least I think, for example if you wanted to move QBO's head in the direction of the source of the sound ... (to tell the truth I still don't have all of them clear the information of the vectors used by Qbo.Cmd.py) and I repeat that I have very little experience with this type of programming. I hope to receive some help later ... (I enclose the text of the microphone node). p.s. Forgive my english but i have some difficulties and i use google translate to help me.

mic_node :

#!/usr/bin/env python2.7
# import the necessary packages
import rospy
import serial
import QboCmd

# import the necessary msgs. Example with msg type String_Int_Arrays:
from std_msgs.msg import Int8
mic_w =[]
class Mic_Controler():
""" Class Mic_controler.

Bridge class to control with ROS the microphones of the robot.
"""

def __init__(self):
"""Class constructor

It is the constructor of the class. It does:
- Call serial_configuration
- Publish mic_w (MIC_REPOERT)
"""

#-------

self.serial_configuration()
self.pub = rospy.Publisher('test_mic', Int8, queue_size=10)

def serial_configuration(self):
"""Void serial_configuration

Configure the serial communication with the Qbo PCB.
Set the serial port, the baudrate and similar things"""
port = '/dev/serial0'
ser = serial.Serial(port, baudrate = 115200, bytesize = serial.EIGHTBITS, stopbits = serial.STOPBITS_ONE, parity = serial.PARITY_NONE, rtscts = False, dsrdtr = False, timeout = 0)
self.QBO = QboCmd.Controller(ser)

def stopping_node(self):
"""ROS closing node

Is the function called when ROS node is closed."""
print("\n\nBye bye! :)\n\n")

def Mic_main(self):
while not rospy.is_shutdown():

print("start")
"""ROS callback

This void is executed when a message is received"""
mic_w = self.QBO.GetHeadCmd("GET_MIC_REPORT",0)
r = rospy.Rate(10) # 10hz
#functions to repeat until the node is closed
self.pub.publish(mic_w)
print("send mic_status",mic_w)
r.sleep()

if __name__=='__main__':
""" Main void.

Is the main void executed when started. It does:
- Start the node
- Create an object of the class
- Run the node

"""
try:
rospy.init_node('Mic_node') # Init ROS node

Mic = Mic_Controler()
print("[INFO] Node started")
rospy.on_shutdown(Mic.stopping_node) #When ROS is closed, this void is executed

Mic.Mic_main()

except rospy.ROSInterruptException:
pass


   
ReplyQuote
(@romeo)
Member
Joined: 6 years ago
Posts: 76
 

Hi @caju, I tried to install ubuntu server 20.04 and check if I could communicate with QBO but apparently something is not working on the serial communication, I am attaching an image where we see that QboCmd.py responds to test.py but I have none communication with the serial port serial0 which I set in / dev. Do you have any suggestions? Does anyone from Thecorpora have any information on this?

Thanks for the attention... ;-)



   
ReplyQuote
caju
 caju
(@caju)
Member
Joined: 4 years ago
Posts: 22
Topic starter  

Hi Romeo,

First of all, sorry for the delay answering. I was busy last week when you wrote, and then I forgot. 

 

Related to the ROS node of the microphone, I would say it is perfect. Only, I have never used "rospy.Rate", but in the same way as I told you about the declaration of the publisher, I guess that you could declare "r=rospy.Rate(10)" out of the While loop to avoid declaring it all the time. Try it, and if it works declaring it only once at the beginning, I would recommend you to do that. But apart from that, the node is perfect, well done!

 

Regarding to your second issue, I understand that your problem is that apparently the node executes without errors, but Qbo is not responding to the serial commands, right? In that case, I cannot solve your doubt, it is related with the serial communication of the robot. In fact, I already had some similar issues when trying to use a raspberry-pi 4. I could work with ROS on it without problems, but as it was not possible to control the serial communication, I downgraded againt to the Raspberry-Pi 3. My problem was the same, I executed the node, aparently it should be working, but there was no response from Qbo. Please, if you can manage to solve that issue, let me know.

 

PD. Your english is perfect, the translator works fine! ;)


   
ReplyQuote
(@romeo)
Member
Joined: 6 years ago
Posts: 76
 

My intention would be to be able to work with python3 on ROS2 Foxy environment and for this I have installed ubuntu server 20.04 on pi3, (debian versions do not support it) maybe tomorrow we could also try with a pi4 ... I installed the QboCmd .py and test.py on a directory, but apparently I can't establish communication with the serial port / dev / ttyS0, which with the necessary permissions seems to accept the commands but the QBO firmware doesn't respond. I probably lack some knowledge and I would like to ask someone from Thecorpora staff for some info. (I also intend to update the QBO firmware as soon as the segger j-link edu mini arrives). I am not very experienced in this environment and I know there is a long way to go ... if I get some help ....

 


   
caju, caju and caju reacted
ReplyQuote
Qbo Robot
(@nonogrub)
Member Admin
Joined: 8 years ago
Posts: 185
 
Posted by: @romeo

My intention would be to be able to work with python3 on ROS2 Foxy environment and for this I have installed ubuntu server 20.04 on pi3, (debian versions do not support it) maybe tomorrow we could also try with a pi4 ... I installed the QboCmd .py and test.py on a directory, but apparently I can't establish communication with the serial port / dev / ttyS0, which with the necessary permissions seems to accept the commands but the QBO firmware doesn't respond. I probably lack some knowledge and I would like to ask someone from Thecorpora staff for some info. (I also intend to update the QBO firmware as soon as the segger j-link edu mini arrives). I am not very experienced in this environment and I know there is a long way to go ... if I get some help ....

 

Hi @romeo

Serial ports comes due to OS problems, since it normally uses it as an I / O port for the system console by default or it is directly disconnected as is the case "specifically" with the Raspberry Pi 4. We'll give you the link where he explains everything related to serial ports in each Raspberry model. Anyway this problem seems to be common for new operating systems and we have found several forums where they talk about it, we will pass you some links.

1.- https://raspberrypi.stackexchange.com/questions/114366/rpi4-serial-port-not-working-on-either-raspberry-os-or-ubuntu

2.- https://www.raspberrypi.org/documentation/configuration/uart.md

 


   
ReplyQuote
(@romeo)
Member
Joined: 6 years ago
Posts: 76
 

this is my gift to the community to test the V3 beta version. Wishes for a happy 2021.


   
ReplyQuote
Qbo Robot
(@nonogrub)
Member Admin
Joined: 8 years ago
Posts: 185
 
Posted by: @romeo

this is my gift to the community to test the V3 beta version. Wishes for a happy 2021.

Good Job @romeo

We appreciate your efforts in our project!!!

theCorpora team 


   
ReplyQuote
(@romeo)
Member
Joined: 6 years ago
Posts: 76
 

A test node for ROS Kinetic that enables QBO to speak when the topic writer reports a sentence. you can set the languages ​​recognized by pico2wawe.wav

I carry the python text in plain text to give the possibility to view it even by beginners.

The associated ros topic command is: rostopic pub -1 /writer std_msgs/String "try to write something"

The python text of the speak_US program:

#!/usr/bin/env python2.7
# import the necessary packages
import rospy
#import yaml
from std_msgs.msg import String
import subprocess

# import the necessary msgs. Example with msg type String_Int_Arrays:
from std_msgs.msg import String

class speak_controler():
""" Class speak_controler.

Bridge class to control with ROS the speaker of the robot.
"""

def __init__(self):
"""Class constructor

It is the constructor of the class. It does:
- Subscribe to /writer topic
"""

#Subscribe to ROS topics
self.sub_phrase = rospy.Subscriber("writer", String, self.writer_cb)

print("[INFO] Node started")

def run_loop(self):
""" Infinite loop.

When ROS is closed, it exits.
"""
while not rospy.is_shutdown():
#functions to repeat until the node is closed
rospy.spin()

def stopping_node(self):
"""ROS closing node

Is the function called when ROS node is closed."""
print("\n\nBye bye! :)\n\n")

def writer_cb(self, data):
"""ROS callback

This void is executed when a message is received"""

# phrase: string Data
if data.data != "":
speak = 'pico2wave -l \"en-US\" -w /home/pi/catkin_ws/src/qbo_control/sounds/pico2wave.wav "<volume level=\'{}\'>{}" && aplay -D convertQBO /home/pi/catkin_ws/src/qbo_control/sounds/pico2wave.wav'.format(75,"hello human friend")
subprocess.call(speak, shell=True)

try:
phrase = data.data
print ("phrase",phrase)
speak = 'pico2wave -l \"en-US\" -w /home/pi/catkin_ws/src/qbo_control/sounds/pico2wave.wav "<volume level=\'{}\'>{}" && aplay -D convertQBO /home/pi/catkin_ws/src/qbo_control/sounds/pico2wave.wav'.format(75,phrase)
subprocess.call(speak, shell=True)

except:
print ("[ERROR]: Wrong data sent in speaker")

if __name__=='__main__':
""" Main void.

Is the main void executed when started. It does:
- Start the node
- Create an object of the class
- Run the node

"""
try:
rospy.init_node('speak_node') # Init ROS node

phrase = speak_controler()
rospy.on_shutdown(phrase.stopping_node) #When ROS is closed, this void is executed

phrase.run_loop()

except rospy.ROSInterruptException:
pass




   
caju, caju and caju reacted
ReplyQuote
Page 2 / 2
Share: