Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR/add jsk aibo robot #1852

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions jsk_aibo_robot/aibo_selenium_ros/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
devel/
logs/
build/
bin/
lib/
msg_gen/
srv_gen/
msg/*Action.msg
msg/*ActionFeedback.msg
msg/*ActionGoal.msg
msg/*ActionResult.msg
msg/*Feedback.msg
msg/*Goal.msg
msg/*Result.msg
msg/_*.py
build_isolated/
devel_isolated/

# Generated by dynamic reconfigure
*.cfgc
/cfg/cpp/
/cfg/*.py

# Ignore generated docs
*.dox
*.wikidoc

# eclipse stuff
.project
.cproject

# qcreator stuff
CMakeLists.txt.user

srv/_*.py
*.pcd
*.pyc
qtcreator-*
*.user

/planning/cfg
/planning/docs
/planning/src

*~

# Emacs
.#*

# Catkin custom files
CATKIN_IGNORE
.vscode/*
20 changes: 20 additions & 0 deletions jsk_aibo_robot/aibo_selenium_ros/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 2.8.3)
project(aibo_selenium_ros)

find_package(catkin REQUIRED catkin_virtualenv)

catkin_python_setup()

catkin_generate_virtualenv(
PYTHON_INTERPRETER python3
CHECK_VENV FALSE
)

catkin_package()

file(GLOB NODE_SCRIPTS_FILES node_scripts/*.py)

catkin_install_python(
PROGRAMS ${NODE_SCRIPTS_FILES}
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
65 changes: 65 additions & 0 deletions jsk_aibo_robot/aibo_selenium_ros/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# aibo_selenium_ros

This package provides a ROS Node which retieve head camera images from web browser and publish it as ROS message.

## How to setup

**Currently this node is only tested with ROS noetic.**

First, Download [suitable version of chrome webdriver to Google chrome installed](https://chromedriver.chromium.org/downloads) and place it somewhere.

And install catkin dependencies

```bash
cd <directory of aibo_selenium_ros>
rosdep install --from-paths . --ignore-src -y -r
```

Build

```bash
catkin bt
```

## How to run (Manual mode)

To run this node, first run roscore

```bash
roscore
```

Then run `main.py`

```bash
$ rosrun aibo_selenium_ros main.py

Press Enter when logging if completed.
```

This script shows up a selenium controlled webbrowser window.

![aibo_login](https://user-images.githubusercontent.com/9410362/237017652-29c64750-a3a6-4008-a197-9c2cc5ba5bdb.png)

Please sign in to myaibo manually and open the dashboard page below.

![dashboard](https://user-images.githubusercontent.com/9410362/237017806-9f85e696-1f1c-4362-b1cc-22b0fe0e7635.png)

Then hit Enter key on the `main.py` window. So it will start to control browser and publish image.

![output](https://user-images.githubusercontent.com/9410362/237018221-13d6a118-6ec2-44ff-86eb-eecf75cfe218.gif)


## How to run (Auto-login mode)

You may be able to use `auto_login` mode. **This mode is unstable**

```bash
rosrun aibo_selenium_ros main.py _login_id:=<login_id> _login_password:=<login_password> _auto_login:=true
```

You can also use headless mode. by setting parameter.

```bash
rosrun aibo_selenium_ros main.py _login_id:=<login_id> _login_password:=<login_password> _auto_login:=true _headless:=true
```
66 changes: 66 additions & 0 deletions jsk_aibo_robot/aibo_selenium_ros/node_scripts/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python

import logging
import sys
import time

import cv2
import rospy
from cv_bridge import CvBridge
from sensor_msgs.msg import CompressedImage, Image

from aibo_selenium_ros import AIBOBrowserInterface

if __name__ == '__main__':

rospy.init_node('aibo_selenium_ros')

pub_raw = rospy.Publisher('~image', Image, queue_size=1)
pub_compressed = rospy.Publisher('~image/compressed',
CompressedImage,
queue_size=1)
cv_bridge = CvBridge()

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

login_id = rospy.get_param('~login_id', '')
login_password = rospy.get_param('~login_password', '')

auto_login = bool(rospy.get_param('~auto_login', False))
headless = bool(rospy.get_param('~headless', False))

interface = AIBOBrowserInterface(login_id=login_id,
login_pw=login_password,
auto_login=auto_login,
headless=headless)
if not auto_login:
input('Press Enter when logging if completed.')
interface.initialized = True

if not interface.initialized:
rospy.logerr('Initialization failed.')
input('Press Enter when logging if completed.')

interface.start_watching()
while True:
image_rgb = interface.get_current_image()
if image_rgb is None:
rospy.loginfo('Restarting watching....')
time.sleep(3.)
ret = interface.continue_watching()
rospy.loginfo('Restarted watching.')
else:
if pub_raw.get_num_connections() > 0:
msg_raw = cv_bridge.cv2_to_imgmsg(cv2.cvtColor(image_rgb,
cv2.COLOR_RGBA2RGB),
encoding='rgb8')
pub_raw.publish(msg_raw)
rospy.loginfo('Publish a raw message')

if pub_compressed.get_num_connections() > 0:
msg_compressed = cv_bridge.cv2_to_compressed_imgmsg(cv2.cvtColor(
image_rgb, cv2.COLOR_RGBA2RGB),
dst_format='jpg')
pub_compressed.publish(msg_compressed)
rospy.loginfo('Publish a compressed message')
53 changes: 53 additions & 0 deletions jsk_aibo_robot/aibo_selenium_ros/node_scripts/test_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python

import argparse
import logging
import sys
import time

import cv2

from aibo_selenium_ros import AIBOBrowserInterface

if __name__ == '__main__':

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

parser = argparse.ArgumentParser()

parser.add_argument('--login-id', default='')
parser.add_argument('--login-password', default='')

parser.add_argument('--auto-login', action='store_true')
parser.add_argument('--headless', action='store_true')

args = parser.parse_args()

interface = AIBOBrowserInterface(login_id=args.login_id,
login_pw=args.login_password,
auto_login=args.auto_login,
headless=args.headless)
if not args.auto_login:
input('Press Enter when logging if completed.')
interface.initialized = True

if not interface.initialized:
logger.error('Initialization failed.')
sys.exit(1)

interface.start_watching()
while True:
image_rgb = interface.get_current_image()
if image_rgb is None:
logger.info('Restarting watching....')
time.sleep(3.)
ret = interface.continue_watching()
logger.info('Restarted watching.')
else:
image_bgr = cv2.cvtColor(image_rgb, cv2.COLOR_RGB2BGR)
cv2.imshow('hoge', image_bgr)
if cv2.waitKey(1) != -1:
break

cv2.destroyAllWindows()
22 changes: 22 additions & 0 deletions jsk_aibo_robot/aibo_selenium_ros/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<package format="2">
<name>aibo_selenium_ros</name>
<version>1.1.0</version>
<description>The aibo_selenium_ros package</description>

<maintainer email="[email protected]">Koki Shinjo</maintainer>
<maintainer email="[email protected]">Kei Okada</maintainer>

<author email="[email protected]">Koki Shinjo</author>

<license>BSD</license>

<buildtool_depend>catkin</buildtool_depend>
<build_depend>catkin_virtualenv</build_depend>

<exec_depend>chromium-browser</exec_depend>
<exec_depend>chromedriver</exec_depend>
<export>
<pip_requirements>requirements.txt</pip_requirements>
</export>
</package>
Loading
Loading