Ask Your Question
0

hx711 python library; ROS node; name 'rospy' is not defined

asked 2018-12-29 17:11:35 -0600

Vrinda gravatar image

Hello ! I am trying to read a load sensor on raspberry pi having Ubuntu Mate with ROS Kinetic. I am using the library link text. However when I create a catkin package and insert the python files, my mouse cursor shows a plus sign. Additionally when I run the example.py by "sudo python example.py", I get "name rospy is not defined". My aim is to read the load sensor and make a rostopic to display the numbers. I needed some guidance regarding this ! Thank you for your time!

edit retag flag offensive close merge delete

Comments

Why are you using sudo? I don't see any use of it in the README

jayess gravatar imagejayess ( 2018-12-29 23:33:43 -0600 )edit

Hello ! It says permission denied when I do "python example.py"

Vrinda gravatar imageVrinda ( 2018-12-30 09:40:46 -0600 )edit

I'd be very careful about running scripts using sudo

jayess gravatar imagejayess ( 2018-12-30 11:23:41 -0600 )edit

Yes, I thought so. I resolved it and made another package from scratch. Thanks much !

Vrinda gravatar imageVrinda ( 2018-12-31 10:39:56 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2019-10-25 04:29:37 -0600

tuman3515 gravatar image

updated 2019-10-25 05:49:18 -0600

gvdhoorn gravatar image

i have the same problem to with arduino and ros commmunication.when i use hx711 library and ros library together i get this msg."Unable to sync with device; possible link problem or link software version mismatch such as hydro rosserial_python with groovy Arduino"

this is my code on arduino

#include <ros.h>
#include <std_msgs/Float64.h>
#include "HX711.h"
#define DOUT  3//
#define CLK  2//
HX711 scale;
float calibration_factor = -5880; //-7050 worked for my 440lb max scale setup
ros::NodeHandle nh;

std_msgs::Float64 test;
ros::Publisher p2("my_topic", &test);
void setup()
{ 
  delay(2000);
  scale.begin(DOUT, CLK);
  scale.set_scale();
  scale.tare(); //Reset the scale to 0 
  long zero_factor = scale.read_average(); //Get a baseline reading
  delay(2000);
  nh.initNode();
  nh.advertise(p2);
  delay(2000);
}

void loop()
{
  delay(200);
  scale.set_scale(calibration_factor); //Adjust to this calibration factor
  float weight=(scale.get_units());
  test.data = weight;
  p2.publish( &test );
  nh.spinOnce();
}

ros command is this

rosrun rosserial_python serial_node.py /dev/ttyUSB1

is there any way to use hx711 withouth library.

edit flag offensive delete link more

Comments

1

Please do not post question as answers on another question. ROS Answers works like Stack Exchange and Stack Overflow: they are not forums.

If you have the same question, post a comment or post a new question while referring to this one.

gvdhoorn gravatar imagegvdhoorn ( 2019-10-25 05:50:10 -0600 )edit
0

answered 2018-12-31 10:38:28 -0600

Vrinda gravatar image

updated 2018-12-31 13:29:23 -0600

jayess gravatar image

Hello everyone ! It was a silly thing. Those files did not have a

#!/usr/bin/env python

at the top. For further information, I then followed this link and placed the hx711.py (a class which I was trying to import in my node) in another package in my catkin_ws.

edit flag offensive delete link more
0

answered 2018-12-30 06:35:43 -0600

hamid gravatar image

updated 2018-12-30 06:35:59 -0600

hi
for running python scrip you must use "rosrun" ,somting lik this:

rosrun pkg_name py_test.py

also pls see the wiki

edit flag offensive delete link more

Comments

Hello ! I tried that. It works with other nodes, however I cannot make it to work with the library I have.

Vrinda gravatar imageVrinda ( 2018-12-30 09:42:12 -0600 )edit

could you share your code?

hamid gravatar imagehamid ( 2018-12-31 00:30:46 -0600 )edit

It is the library I was trying to use (link in my question). I was trying to use the example.py as my script for the ROS node.

Vrinda gravatar imageVrinda ( 2018-12-31 10:42:41 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2018-12-29 17:09:29 -0600

Seen: 91 times

Last updated: Oct 25