ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

I have using ros1 - melodic and run in ubuntu 18.04 in Jetson-Nano I trying to access serial port of Jetson-Nano. But when i run with command "python3 serial_modules.py" then no error occurs but not access to serial port If I delete "import rospy" then everything is running fine

asked 2022-04-04 10:25:33 -0500

phanmanhducct gravatar image

updated 2022-04-07 03:19:22 -0500

Below is the code:

#!/usr/bin/env python3.6
import serial   #sudo apt-get install python3-serial
import time
import rospy

def initConnection(portNo, baudRate):
   try:
       ser = serial.Serial(portNo, baudRate)
       print("Device Connected")
       return ser
   except:
       print("Not Connected")

def sendData(se, data, name):
   myString = "$"
   for x in range(3):
       myString += (name[i] + ":" + str(data[i]) + "$")
   myString += "\r\n"
   try:
       se.write(myString.encode())
       #print(myString)
   except:
       print("Data Transmition Failed")

if __name__ == "__main__":
   ser = initConnection('/dev/ttyTHS1', 115200) # on jetson replace COM8 with /dev/ttyTHS1 coresponding
   while True:
       myString = "hello"
       ser.write(myString.encode())
       time.sleep(1)
edit retag flag offensive close merge delete

Comments

Was ROS sourced for sure?

ljaniec gravatar image ljaniec  ( 2022-04-05 22:08:37 -0500 )edit

I think sure ...... Can you help me, but I'm also stuck with this error

phanmanhducct gravatar image phanmanhducct  ( 2022-04-06 09:01:11 -0500 )edit

You have to add more information about your case, what kind of system is it, what kind of robot, what are you trying to do too. I think I know what is the problem though, give me a moment.

ljaniec gravatar image ljaniec  ( 2022-04-06 09:14:52 -0500 )edit

thank you .... i have using ros1 - melodic and run in ubuntu 18.04 in Jetson-Nano I trying to access serial port of Jetson-Nana But when i run with command "python3 serial_modules.py" then no error occurs but not access to serial port If I delete "import rospy" then everything is running fine

phanmanhducct gravatar image phanmanhducct  ( 2022-04-06 11:29:50 -0500 )edit

Add these to the question in the edit please, to keep everything in one place

ljaniec gravatar image ljaniec  ( 2022-04-06 14:21:33 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2022-04-06 09:17:17 -0500

ljaniec gravatar image

updated 2022-04-06 09:19:05 -0500

It seems you are using ROS1 Kinetic and Python 3.6.

ROS Kinetic targets Python 2.7.

Relevant questions about Kinetic and Python 2.7:

If it is possible, you should switch to other newer ROS version (ROS1 Noetic or ROS2 Foxy/Galactic). Otherwise, you should switch to Python 2.7 (not really recommended).

edit flag offensive delete link more

Comments

i using ROS1 melodic and python 3.6

phanmanhducct gravatar image phanmanhducct  ( 2022-04-06 11:21:51 -0500 )edit

Then it won't work out of the box. Can you try to use Python 2.7 with this code?

ljaniec gravatar image ljaniec  ( 2022-04-06 14:20:59 -0500 )edit

i have using ros1 - melodic and run in ubuntu 18.04 in Jetson-Nano I trying to access serial port of Jetson-Nano But when i run with command "python3 serial_modules.py" then no error occurs but not access to serial port If I delete "import rospy" then everything is running fine

phanmanhducct gravatar image phanmanhducct  ( 2022-04-07 03:16:09 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-04-04 10:25:33 -0500

Seen: 172 times

Last updated: Apr 07 '22