RobotnikAutomation / barrett_hand

ROS package to control the Barrett Hand
13 stars 24 forks source link

Cannot initialize hand #18

Open civerachb-cpr opened 3 years ago

civerachb-cpr commented 3 years ago

I've been fighting with this problem for a week or so, and I haven't been able to figure it out. When I initialize the hand by running rosservice call /bhand_node/actions "action: 1" I'm getting ret: False and seeing the following output from the driver:

$ roslaunch bhand_controller bhand_controller.launch port:=/dev/pcanusb32
... logging to /home/administrator/.ros/log/c1407f26-eef4-11eb-83d9-c400ad58196b/roslaunch-robot-hostname-28412.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://robot-hostname:44577/

SUMMARY
========

PARAMETERS
 * /bhand_node/control_mode: POSITION
 * /bhand_node/desired_freq: 250.0
 * /bhand_node/ft_sensor: False
 * /bhand_node/joint_ids: ['F1', 'F1_TIP', ...
 * /bhand_node/joint_names: ['bh_j12_joint', ...
 * /bhand_node/port: /dev/pcanusb32
 * /bhand_node/tactile_sensors: False
 * /rosdistro: melodic
 * /rosversion: 1.14.11

NODES
  /
    bhand_node (bhand_controller/bhand_node.py)

ROS_MASTER_URI=http://localhost:11311

process[bhand_node-1]: started with pid [28470]
[INFO] [1627403455.784208]: /bhand_node: init: setting control mode by default to PID
{'F2_TIP': ['bh_j23_joint', 3], 'F1': ['bh_j12_joint', 0], 'F2': ['bh_j22_joint', 2], 'F3': ['bh_j32_joint', 4], 'F3_TIP': ['bh_j33_joint', 5], 'F1_TIP': ['bh_j13_joint', 1], 'SPREAD_1': ['bh_j11_joint', 6], 'SPREAD_2': ['bh_j21_joint', 7]}
[INFO] [1627403455.787482]: /bhand_node: port /dev/pcanusb32, freq = 250, topic = state, tactile_sensors = False
[INFO] [1627403455.789131]: bhand_node: starting
PCANBasic::Initialize: Port /dev/pcanusb32 opened successfully
PCANBasic::Initialize: Port /dev/pcanusb32 configured
PCANBasic::Initialize: PCAN version info = Release_20171027_n
[INFO] [1627403457.084393]: /bhand_node:setup: ok
[ERROR] [1627403464.665821]: pyHand: init_hand: error: (0) Error Number: -0x1 while attempting to read

[ERROR] [1627403464.669740]: pyHand: init_hand: error: (1) Error Number: -0x1 while attempting to read

[ERROR] [1627403464.674769]: pyHand: init_hand: error: (2) Error Number: -0x1 while attempting to read

[ERROR] [1627403464.679061]: pyHand: init_hand: error: (3) Error Number: -0x1 while attempting to read

[ERROR] [1627403464.683329]: pyHand: init_hand: error: (4) Error Number: -0x1 while attempting to read

[ERROR] [1627403464.685178]: /bhand_node::handActions: error on INIT_HAND service
[ERROR] [1627403464.686852]: /bhand_node::canError: Errors on CAN bus
[INFO] [1627403464.688649]: BHand::switchToState: FAILURE_STATE

Immediately after the activation signal I can hear the high-pitched whine from the hand, and the fingers splay open. Then the driver crashes and reverts to the failure state.

The computer in question has 4 CAN ports: 2 on a PCI card (can0 and can1 -- these are working correctly), and 2 USB dongles (one each for a gripper mounted on the end of the left and right arms). For the moment I've disconnected one gripper completely, and the other is connected to the control box. I can confirm that the dip switches on the hand are set to the correct positions, as I'm able to control the hand correctly when I connect the USB dongle to my laptop instead of my robot.

Additional output and config files:

$ uname -a
Linux robot-hostname 4.15.0-151-generic #157-Ubuntu SMP Fri Jul 9 23:07:57 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.5 LTS
Release:    18.04
Codename:   bionic

$ ls -l /dev/pcan*
lrwxrwxrwx 1 root root          8 Jul 27 12:30 /dev/pcan0 -> pcanpci0
lrwxrwxrwx 1 root root          8 Jul 27 12:30 /dev/pcan1 -> pcanpci1
lrwxrwxrwx 1 root root          9 Jul 27 12:30 /dev/pcan32 -> pcanusb32
crw-rw-rw- 1 root root    241,  0 Jul 27 12:30 /dev/pcanpci0
crw-rw-rw- 1 root plugdev 241,  1 Jul 27 12:30 /dev/pcanpci1
crw-rw-rw- 1 root root    241, 32 Jul 27 12:30 /dev/pcanusb32

/dev/pcan-usb:
total 0
drwxr-xr-x 2 root root 60 Jul 27 12:30 0

$ ifconfig -a
# non-can interfaces redacted
can0: flags=128<NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 2  bytes 16 (16.0 B)
        RX errors 0  dropped 2  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

can1: flags=193<UP,RUNNING,NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

can2: flags=193<UP,RUNNING,NOARP>  mtu 16
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 10  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

$ cat /proc/pcan

*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20171027_n (8.5.1) Jul 21 2021 10:53:51 --------------
*------------------- [mod] [isa] [pci] [par] [usb] [net] --------------------
*--------------------- 3 interfaces @ major 241 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
 0    pci   can1 f7000000 017 0x001c 00000000 00000000 00000000 00000000 0x0000
 1    pci   can2 f7000400 017 0x0014 00000000 00000000 00000000 00000000 0x0000
32    usb   can0 ffffffff 000 0x0014 00000002 0000000a 00004dec 0000000b 0x0000

$ cat /etc/modprobe.d/pcan.conf 
# Configure each CAN devoce to be a specific CAN ID
options pcan assign=pcan0:can0,pcan1:can1,pcan32:can2,pcan33:can3

# pcan - automatic made entry, begin --------
# if required add options and remove comment
# options pcan type=isa,sp
install pcan modprobe --ignore-install pcan
# pcan - automatic made entry, end ----------

I have a udev rule that sets the bitrate to 1M:

# set the  base platform CAN interface to 1M bps and battery interface to 500k bps
KERNEL=="pcan*", ATTR{ndev} == "can0", RUN+="/usr/sbin/load_peak '$attr{ndev}' 1000000"
KERNEL=="pcan*", ATTR{ndev} == "can1", RUN+="/usr/sbin/load_peak '$attr{ndev}' 500000"

# set the gripper CAN interfaces to 1M bps
KERNEL=="pcan*", ATTR{ndev}=="can2", RUN+="/usr/sbin/load_peak '$attr{ndev}' 1000000", MODE="0666", GROUP="plugdev"
KERNEL=="pcan*", ATTR{ndev}=="can3", RUN+="/usr/sbin/load_peak '$attr{ndev}' 1000000", MODE="0666", GROUP="plugdev"

The load_peak script contains this:

#!/bin/bash
DEVID=$1
BITRATE=$2
ip link set ${DEVID} type can bitrate ${BITRATE}
ip link set ${DEVID} up

I've rebuilt the pcan driver several times, with netdev support both enabled and disabled, and it's made no difference. I tried the additional flags mentioned in https://github.com/RobotnikAutomation/barrett_hand/issues/16, same result: the error persists. I've also tried the peak-linux-driver versions 8.11.0 and 8.12.0; both produce the same error as above.

The node works correctly when I connect the gripper directly to my laptop (where it's the only CAN device), but I cannot get it to work in my robot's computer. Is there a known compatibility issue when using a PCI CAN card at the same time as the USB dongles that I'm unaware of? Or have I just missed something with my configuration and I'm too far down the rabbit hole to have noticed?

Any suggestions or insight is greatly appreciated; I've been at this for a week and feel like I haven't made any progress.

civerachb-cpr commented 3 years ago

Small update: it turns out I had a deb package installed that was also providing the pcan kernel module, and that was overriding my compiled-from-source driver. I can confirm that compiling the driver without netdev support works. BUT, the CAN devices connected to my computer's PCI CAN card need netdev support, otherwise the whole robot doesn't work. The options I see are: 1) Reconfigure pcan_python so it works with netdev CAN devices. This feels like it would basically be rewriting the entire pcan_python library, so not sure that's worth it. 2) Use the serial instead of CAN; I have 2 open serial ports on the computer, and I can flip the dip switch in the hand to switch from CAN to RS232, but it looks like the ROS driver only works with CAN? 3) Install 2 version of the peak driver: one with netdev support for my PCI CAN card, and the other without netdev support for use with the USB adapters.

xiaodai-116 commented 2 years ago

hello,I have met the similar question like you.I run the ros package on untuntu 18.04 . I installed the can driver of 8.x version. When I run rosservice call /bhand_node/actions "action: 1" I meet the same error pyHand: init_hand: error: (0) Error Number: -0x1 while attempting to read. I think it is the problem of pcanlibrary and the _pcan_module we make. I wonder how you solve the problem.Thank you.

civerachb-cpr commented 2 years ago

For the application I was working on we ultimately just installed a second, low-cost computer in the robot to run the drivers for the two hands. We configured it to use the same ROS master as the rest of the robot, but that was the most-expedient work-around to meet our requirements of having the pcan_python module compiled with both NETDEV and CHARDEV concurrently.

To use the Barrett hands you ned to compile the pcan_python library with the NET=NO_NETDEV_SUPPORT option (see https://github.com/RobotnikAutomation/pcan_python).

It's also worth double-checking that you have the dip switches on the hand itself set properly; depending on whether you're using the connector on the side or the bottom of the hand you'll need to flip some switches under the small plate on the base of the hand.

Finally, make sure you're opening the correct CAN device when you launch the driver by setting the port argument.