Hacks4ROS / h4r_ev3_ctrl

ROS Node for managing EV3 with ROS Control
GNU General Public License v3.0
21 stars 12 forks source link

Motors can't move #13

Closed yrosascu closed 2 years ago

yrosascu commented 7 years ago

Hello, I installed the packages to control ev3 then I launched the motors but it doesn't work. I did everything that is mentioned in Geting Started In brick: I set ROS_IP= "IP of my pc" ev3_manager

In PC: roslaunch motors.launch ev3_hostname:=ev3dev

ieka@ieka:~/catkin_ws/src/h4r_ev3_launch/launch$ roslaunch motors.launch ev3_hostname:=ev3dev
... logging to /home/ieka/.ros/log/1a758ccc-1ca3-11e7-8760-a0d37a596cdf/roslaunch-ieka-31830.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://ieka:34720/

SUMMARY
========

PARAMETERS
 * /ev3dev/Ev3devJoints/Joint_A/mode: velocity
 * /ev3dev/Ev3devJoints/Joint_A/speed_pid: [1001, 61, 1]
 * /ev3dev/Ev3devJoints/Joint_B/mode: velocity
 * /ev3dev/Ev3devJoints/Joint_B/speed_pid: [1002, 62, 2]
 * /ev3dev/Ev3devJoints/Joint_C/mode: velocity
 * /ev3dev/Ev3devJoints/Joint_C/speed_pid: [1003, 63, 3]
 * /ev3dev/Ev3devJoints/Joint_D/mode: velocity
 * /ev3dev/Ev3devJoints/Joint_D/speed_pid: [1004, 64, 4]
 * /ev3dev/OutPortA/joint: Joint_A
 * /ev3dev/OutPortA/type: velocity_controll...
 * /ev3dev/OutPortB/joint: Joint_B
 * /ev3dev/OutPortB/type: velocity_controll...
 * /ev3dev/OutPortState/publish_rate: 10
 * /ev3dev/OutPortState/type: joint_state_contr...
 * /ev3dev/diffDrv/angular/z/has_acceleration_limits: True
 * /ev3dev/diffDrv/angular/z/has_velocity_limits: True
 * /ev3dev/diffDrv/angular/z/max_acceleration: 1.5
 * /ev3dev/diffDrv/angular/z/max_velocity: 1.7
 * /ev3dev/diffDrv/base_frame_id: base_footprint
 * /ev3dev/diffDrv/cmd_vel_timeout: 0.5
 * /ev3dev/diffDrv/left_wheel: Joint_C
 * /ev3dev/diffDrv/linear/x/has_acceleration_limits: True
 * /ev3dev/diffDrv/linear/x/has_velocity_limits: True
 * /ev3dev/diffDrv/linear/x/max_acceleration: 0.8
 * /ev3dev/diffDrv/linear/x/max_velocity: 1.0
 * /ev3dev/diffDrv/linear/x/min_acceleration: 0.2# m/s^2
 * /ev3dev/diffDrv/linear/x/min_velocity: -1.0
 * /ev3dev/diffDrv/pose_covariance_diagonal: [0.0, 0.0, 0.0, 0...
 * /ev3dev/diffDrv/publish_rate: 10.0
 * /ev3dev/diffDrv/right_wheel: Joint_D
 * /ev3dev/diffDrv/twist_covariance_diagonal: [0.0, 0.0, 0.0, 0...
 * /ev3dev/diffDrv/type: diff_drive_contro...
 * /ev3dev/diffDrv/wheel_radius: 0.15
 * /ev3dev/diffDrv/wheel_radius_multiplier: 1.0
 * /ev3dev/diffDrv/wheel_separation: 1.0
 * /ev3dev/diffDrv/wheel_separation_multiplier: 1.0
 * /ev3dev/ev3_manager_node/InPorts: ['in1', 'in2', 'i...
 * /ev3dev/ev3_manager_node/OutPorts: ['outA', 'outB', ...
 * /rosdistro: indigo
 * /rosversion: 1.11.20

NODES
  /ev3dev/
    controller_spawner (controller_manager/spawner)
    ev3_manager_node (h4r_ev3_manager/ev3_manager_node)

ROS_MASTER_URI=http://localhost:11311

core service [/rosout] found
process[ev3dev/ev3_manager_node-1]: started with pid [31848]
process[ev3dev/controller_spawner-2]: started with pid [31849]
[INFO] [WallTime: 1491687916.313862] Controller Spawner: Waiting for service controller_manager/load_controller
[INFO] [WallTime: 1491687916.316145] Controller Spawner: Waiting for service controller_manager/switch_controller
[INFO] [WallTime: 1491687916.318167] Controller Spawner: Waiting for service controller_manager/unload_controller
[INFO] [WallTime: 1491687916.320247] Loading controller: OutPortState
[INFO] [WallTime: 1491687916.370920] Loading controller: OutPortA
[INFO] [WallTime: 1491687916.470887] Loading controller: OutPortB
[INFO] [WallTime: 1491687916.571194] Controller Spawner: Loaded controllers: OutPortState, OutPortA, OutPortB
[ INFO] [1491687916.670842904]: Controller Change
[ INFO] [1491687916.671082092]: velocity_controllers/JointVelocityController requests Joint OutPortA Joint_A
[ INFO] [1491687916.673022080]: <--------------EV3 Joint Joint_A---------------->
[ INFO] [1491687916.674932682]: Joint control mode: velocity
[ INFO] [1491687916.678418267]: P: 1001  I: 61   D: 1
[ INFO] [1491687916.678524544]: </-------------EV3 Joint Joint_A---------------->
[ INFO] [1491687916.678608714]: ----------------------------------------------<
[ INFO] [1491687916.678713111]: PID 1001 61 1
[ INFO] [1491687916.678869799]: velocity_controllers/JointVelocityController requests Joint OutPortB Joint_B
[ INFO] [1491687916.680746845]: <--------------EV3 Joint Joint_B---------------->
[ INFO] [1491687916.682513984]: Joint control mode: velocity
[ INFO] [1491687916.685414876]: P: 1002  I: 62   D: 2
[ INFO] [1491687916.685479442]: </-------------EV3 Joint Joint_B---------------->
[ INFO] [1491687916.685524625]: ----------------------------------------------<
[ INFO] [1491687916.685575927]: PID 1002 62 2
[INFO] [WallTime: 1491687916.686034] Started controllers: OutPortState, OutPortA, OutPortB

Then I start "rqt" to try move motors with any value in "Message Publisher" i get this http://imgur.com/a/MQLcd and the motors don't move.

When i do rostopic echo /ev3dev/joint_states the data don't change and i get this:

header: 
  seq: 1920
  stamp: 
    secs: 1491688109
    nsecs:  70649827
  frame_id: ''
name: ['Joint_A', 'Joint_B', 'Joint_C', 'Joint_D']
position: [0.0, 0.0, 0.0, 0.0]
velocity: [0.0, 0.0, 0.0, 0.0]
effort: [0.0, 0.0, 0.0, 0.0]

The only data that change are sec and nsecs. I delete the tag mentioned in # 11 but it does not work because topics "OutPort#" don't appear. Try several times, with variations on the other ports and topics but nothing moves the motors.

do i need to modify any file? i don't understand why they don't work. I read other issues but don't find other similary error.

I hope that you can help me.

Thank you

cyborg-x1 commented 7 years ago

Hi, sorry did not see

I set ROS_IP= "IP of my pc"

There is already a (the?) problem. You set the ROS_IP of the brick on the brick, the ROS_IP of the PC on the PC.

You set ROS_IP to the ip the interface you use has. On your PC(Laptop) this is probably the wireless network card.

check it with ifconfig

wlp3s0 Link encap:Ethernet HWaddr ... inet addr:192.168.178.32 Bcast:192.168.178.255 Mask:255.255.255.0 ....

The first best way to check if ros is working is to rosservice list (on your PC) after you started roscore on your PC and ev3_manager on your brick. If you do not see any services of ros_control there is already a problem.

cyborg-x1 commented 7 years ago

I have a little bash function in my bashrc, maybe it is of any use, if you are bored putting export ROS_IP=192.168.178.32 all the time.

Actually there should be such function on the brick as well, check the prints after you log in.

set_rosip <successfull prints if 1> <error prints if 1>

in my case it would be

set_rosip wlp3s0 1 1 (with printing all debug messages)

Code:

#ROS IP setter
function set_rosip
{
  RED="$(tput setb 4)"
  GREEN="$(tput setaf 0)$(tput setb 2)"
  BOLD=$(tput bold)
  NOCOLOR=$(tput sgr0)

  {
  ifconfig $1
  } &> /dev/null

  if [ $? -ne 0 ]; then
    echo -e "${RED}Interface ${BOLD}$1${NOCOLOR}${RED} not found! ${BOLD}ROS_IP not set!${NOCOLOR}"
    return 1
  fi

  ip_addr=`ifconfig $1 | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'`

  if [ -z "$ip_addr" ]; then
    if [ "$3" == "1" ]; then
      echo -e "${RED}Interface ${BOLD}$1${NOCOLOR}${RED} not connected, ${BOLD}ROS_IP not set!${NOCOLOR}"
    fi
    return 1
  fi

  if [ "$2" == "1" ]; then
    echo ${GREEN}ROS_IP set to $1 with IP $ip_addr${NOCOLOR}
  fi

  export ROS_IP=$ip_addr
}
yrosascu commented 7 years ago

Hi, I did everything that you recommended me, I check the file "h4r_ros.bash" but the code is different.

function ros_ip_set
{
  RED="\e[37;41m"
  GREEN="\e[30;42m"
  YELLOW="\e[30;43m"
  BOLD="\e[1m"
  NOCOLOR="\e[0m"

  if [ "$1" == "" ]; then
     unset ROS_IP
     rm -rf $H4R_ROS_IP_FILE
     echo -e "${YELLOW}ROS_IP unset${NOCOLOR}"
     return 0
  fi

  #$1 network interface
  #$2 report on success [default - 1]
  #$3 report on error   [default - 1]

  {
  ifconfig $1
  } &> /dev/null

  if [ "$?" -ne 0 ]; then
    echo -e "${RED}Interface ${BOLD}$1${NOCOLOR}${RED} not found! ${BOLD}ROS_IP not set!${NOCOLOR}"
    return 1
  fi
  ip_addr=`ifconfig $1 | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'`

  if [ -z "$ip_addr" ]; then
    if [ "$3" != "0" ]; then
      echo -e "${RED}Interface ${BOLD}$1${NOCOLOR}${RED} not connected, ${BOLD}ROS_IP not set!${NOCOLOR}"
    fi
    return 1
  fi

  if [ "$2" != "0" ]; then
   echo -e ${GREEN}ROS_IP set to $1 with IP $ip_addr${NOCOLOR}
  fi

  export ROS_IP=$ip_addr
  echo "$ip_addr" > $H4R_ROS_IP_FILE

  return 0
}

And the command ros_ip_set don't work:

root@ev3dev:~# ros_ip_set 192.168.10.10   
Interface 192.168.10.10 not found! ROS_IP not set!

My red is:

IP pc = 192.168.10.10
IP brick = 192.168.10.123

I did ping between them and then i did ssh root@192.168.10.123 and when ev3 run i set ROS_IP variable with command export ROS_IP=192.168.10.10 (because ros_ip_set dont work), then y run roscore on my pc and ev3_manager on brick but i have the same error.

With the last changes when i running some these files are not found. Maybe do you have the initial code? because i think the error is the communication bewteen brick and pc.

I need a lot of help.

cyborg-x1 commented 7 years ago

Interface 192.168.10.10 not found! ROS_IP not set!

It expects the Interface (wlan0, eth0 ... ), you entered the IP (192.168.10.10)

And I have not told you that both scripts are the same, just that there is already a command for easily setting the ROS_IP on the brick.

The script I posted was for the PC. You can use it, if you do not want to do:

in every terminal you want to use with ROS.

instead you do set_rosip wlan0 and you are done.

(wlan0 is an example!, check your interface name!)

:warning: if you reconnect to the network your IP might change, you need to execute the command everywhere again!

I recommend to get a Router with a DNS (if you have an old one you can check if it supports OpenWRT (alternative firmware) which is shipped with a DNS server)

yrosascu commented 7 years ago

Sorry for asking again.

I connect pc and brick with usb, so the ip dont change. Is this setting correct for communication between devices?

IP of PC = 192.168.10.10
IP of Brick = 192.168.10.123

In Brick:

ros_master_set 192.168.10.10
ROS_IP = 192.168.10.10

In PC: ROS_MASTER_URI=http://localhost:11311


Run roscore in pc, ev3_manager in brick. When i run rosservice list in pc, i get this:

ieka@ieka:~/catkin_ws$ rosservice list
/ev3dev/Ev3ControlNode/get_loggers
/ev3dev/Ev3ControlNode/set_logger_level
/ev3dev/controller_manager/list_controller_types
/ev3dev/controller_manager/list_controllers
/ev3dev/controller_manager/load_controller
/ev3dev/controller_manager/reload_controller_libraries
/ev3dev/controller_manager/switch_controller
/ev3dev/controller_manager/unload_controller
/ev3dev/controller_spawner/get_loggers
/ev3dev/controller_spawner/set_logger_level
/ev3dev/ev3_manager_node/get_loggers
/ev3dev/ev3_manager_node/set_logger_level
/rosout/get_loggers
/rosout/set_logger_level

I connect motor to port A and B, then i launch motors.launch but nothing happens, then i publish: rostopic pub /ev3dev/OutPortA/command std_msgs/Float64 "data: 5.0" but motor dont move.

So i dont undertand what I am doing wrong, for that reason I think my configuration is not correct.

yrosascu commented 7 years ago

And when I stop ev3_manager node if I launch motors.launch there is not error.

cyborg-x1 commented 7 years ago

Hi again, Ehm have you installed this hotfix on the brick? https://github.com/Hacks4ROS/h4r_ev3_ctrl/releases

Check if that solves the issues.

cyborg-x1 commented 7 years ago

Just to be sure try to publish a rostopic on pc and try to echo it on the brick and the other way round to be sure communication is working properly.