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

ehsan_amp's profile - activity

2021-06-01 11:36:03 -0500 received badge  Self-Learner (source)
2020-08-31 05:01:17 -0500 received badge  Famous Question (source)
2020-05-28 16:47:44 -0500 received badge  Famous Question (source)
2020-05-01 19:20:56 -0500 received badge  Famous Question (source)
2020-03-29 21:40:02 -0500 received badge  Notable Question (source)
2020-01-22 23:07:52 -0500 marked best answer How to import service file (.srv) in a python node?

I want to import .srv file from another package into my python node. How can I do that? Thanks in advance.

2020-01-22 23:07:33 -0500 marked best answer How to call a service inside a python node?

I want to subscribe a data in a python node and for different values of subscribed values, call a predefined service from another package and make it True or False. As it is explained for this question or in this link, I have tried call_service function but get this error.

[ERROR] [1579531979.101601]: bad callback: <function callback_receive at 0x7efd5a15dd70>
Traceback (most recent call last):
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "/home/ehsan/catkin_ws/src/fsr_sensor/scripts/subscriber_node.py", line 16, in callback_receive
rosservice.call_service('/joint2_controller/torque_enable',False)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosservice/__init__.py", line 411, in call_service
rospy.init_node('rosservice', anonymous=True)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/client.py", line 274, in init_node
raise rospy.exceptions.ROSException("rospy.init_node() has already been called with different arguments: 
"+str(_init_node_args))
ROSException: rospy.init_node() has already been called with different arguments: ('subscriber_node', 
['/home/ehsan/catkin_ws/src/fsr_sensor/scripts/subscriber_node.py'], False, None, False, False)

I attached my python node below. Thanks in advance.

#!/usr/bin/env python

import rospy
import time
from std_msgs.msg import Bool
from std_msgs.msg import Int32
import rosservice

def callback_receive(msg):
   if msg.data == 1:
      rosservice.call_service('/joint2_controller/torque_enable',True)
      rosservice.call_service('/joint1_controller/torque_enable',True)
   else:
      rosservice.call_service('/joint2_controller/torque_enable',False)
      rosservice.call_service('/joint1_controller/torque_enable',False)

if __name__ == '__main__':
    rospy.init_node('subscriber_node')
    rospy.Subscriber("/X",Int32,callback_receive)

 rospy.spin()
2020-01-21 10:01:09 -0500 received badge  Nice Answer (source)
2020-01-21 09:21:36 -0500 received badge  Self-Learner (source)
2020-01-21 09:21:36 -0500 received badge  Teacher (source)
2020-01-21 08:29:27 -0500 received badge  Popular Question (source)
2020-01-21 08:18:13 -0500 edited answer How to call a service inside a python node?

As far as I know rosservice.call_service doesn't work for this usage. I attached the code that I used. #!/usr/bin/env p

2020-01-21 08:08:29 -0500 answered a question How to call a service inside a python node?

As far as I know rosservice.call_service doesn't work for this usage. I attached the code that I used below. #!/usr/bin

2020-01-21 08:08:29 -0500 received badge  Rapid Responder (source)
2020-01-21 08:08:10 -0500 received badge  Notable Question (source)
2020-01-21 08:05:39 -0500 commented answer How to call a service inside a python node?

Thanks for your answer. I tried that and it worked! I will write it down as an answer.

2020-01-21 08:04:20 -0500 answered a question How to import service file (.srv) in a python node?

I Found the problem and each time I compiled the code, it couldn't found the .srv file. when I wanted to import a servic

2020-01-21 08:04:20 -0500 received badge  Rapid Responder (source)
2020-01-21 07:57:35 -0500 commented question How to import service file (.srv) in a python node?

@Delb Thanks for your answer. Yes, I wanted to call a predefined service as I explained in #q342113. I will write it dow

2020-01-21 07:57:09 -0500 commented question How to import service file (.srv) in a python node?

@Delb Thanks for your answer. Yes, I wanted to call a predefined service as I explained in #q342113 I will write it down

2020-01-21 07:55:38 -0500 commented question How to import service file (.srv) in a python node?

Thanks for your answer. Yes, I wanted to call a predefined service as I explained in [#q342113]. I will write it down

2020-01-21 07:55:10 -0500 commented question How to import service file (.srv) in a python node?

Thanks for your answer. Yes, I wanted to call a predefined service as I explained in [#q342113]. (https://answers.ros.o

2020-01-21 03:10:13 -0500 asked a question How to import service file (.srv) in a python node?

How to import service file (.srv) in a python node? I want to import .srv file from another package into my python node.

2020-01-20 22:12:11 -0500 received badge  Popular Question (source)
2020-01-20 09:17:32 -0500 asked a question How to call a service inside a python node?

How to call a service inside a python node? I want to subscribe a data in a python node and for different values of subs

2020-01-03 07:30:39 -0500 commented answer Strange data in arduino and ROS serial communication

Thanks. I did that, and it works well

2019-12-29 11:13:59 -0500 commented answer Strange data in arduino and ROS serial communication

Thanks. Actually, I want to control another servo motor with Arduino, so I don't need to publish the data again. I'm usi

2019-12-29 11:04:07 -0500 marked best answer Strange data in arduino and ROS serial communication

I'm using AX-12+ dynamixel motor as an encoder in my robot joint. I receive data with dynamixel packages in ros kinetic. Then by the aim of a python node, I subscribe to the data and publish it to the Arduino DUE serial. I printed the encoder position in Arduino serial monitor, and among my correct data sometimes my motor send some unknown data like

⸮⸮⸮
⸮⸮⸮Notor2_arduinostd_msgs/Int16 8524586e34fbd7cb1c08c5f5f1ca0e57⸮

The error that is shown in the terminal while I run the publisher node:

[ERROR] [1577099602.767875]: bad callback: <function callback_receive at 0x7f5266c9a9b0>
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
    cb(msg)
  File "/home/ehsan/catkin_ws/src/gripper/scripts/dynamixel_servo.py", line 11, in callback_receive
    motor_data2=msg.motor_states[1]
IndexError: list index out of range

I want to use the motor encoder data in my calculations, so I need to filter the data. How can I extract only the numbers and filter the unknown ones?

Python Subscriber and Publisher node:

#!/usr/bin/env python

import rospy
import time
from std_msgs.msg import Int16

from dynamixel_msgs.msg import MotorStateList
def callback_receive(msg):
motor_data1=msg.motor_states[0]
pub1.publish(motor_data1.position)
motor_data2=msg.motor_states[1]
pub2.publish(motor_data2.position)



if __name__ == '__main__':
rospy.init_node('dynamixel_servo')
sub = rospy.Subscriber("/motor_states/pan_tilt_port",MotorStateList,callback_receive)
pub1=rospy.Publisher("/motor1_arduino",Int16,queue_size=30)
pub2=rospy.Publisher("/motor2_arduino",Int16,queue_size=10)

rospy.spin()

Arduino Code:

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include <WProgram.h>
#endif
#define USE_USBCON
#include <ros.h>
#include <std_msgs/Int16.h>
#include <std_msgs/Empty.h>
#include <std_msgs/Float64.h>
int position2;
ros::NodeHandle  nh;

void servo_cb2(const std_msgs::Int16& cmd_msg2){
//Serial.println(cmd_msg2.data); 
position2 = cmd_msg2.data;

}

ros::Subscriber<std_msgs::Int16> sub1("motor2_arduino", &servo_cb2 );

void setup() {

Serial.begin(57600);
nh.initNode();
nh.subscribe(sub1);

}

void loop() {
int val = map(position2, 0, 1023, 0, 300);
val=val+30;
Serial.println(val);
nh.spinOnce();
delay(1);
}
2019-12-29 11:04:07 -0500 received badge  Scholar (source)
2019-12-29 03:42:09 -0500 received badge  Notable Question (source)
2019-12-26 03:55:14 -0500 received badge  Popular Question (source)
2019-12-24 14:24:51 -0500 asked a question Strange data in arduino and ROS serial communication

Strange data in arduino and ROS serial communication I'm using AX-12+ dynamixel motor as an encoder in my robot joint. I

2019-11-13 06:16:32 -0500 received badge  Supporter (source)