add new feature.

This commit is contained in:
张立军 2021-05-13 15:40:51 +08:00
parent 6fd7298cc7
commit c0c015e7ee
12 changed files with 132 additions and 168 deletions

9
CHANGELOG.md Normal file
View file

@ -0,0 +1,9 @@
# 2021
## 05.13
- Specification package name.
- Specification file nmae.
- Added teleop keyboard control.
- Intergrated MoveIt.
- Update sync moveit plan script.

View file

@ -45,6 +45,7 @@ catkin_install_python(PROGRAMS
scripts/mycobot_services.py
scripts/listen_real.py
scripts/teleop_keyboard.py
scripts/sync_plan.py
scripts/client.py
scripts/camera.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}

132
README.md
View file

@ -1,10 +1,11 @@
# mycobot_ros
[![jaywcjlove/sb](https://jaywcjlove.github.io/sb/lang/chinese.svg)](READMEcn.md)
[![jaywcjlove/sb](https://jaywcjlove.github.io/sb/lang/chinese.svg)]()
[![jaywcjlove/sb](https://jaywcjlove.github.io/sb/lang/english.svg)]()
[中文文档](https://www.elephantrobotics.com/docs/myCobot/3-development/4-ros&moveit/) | [English Document not finish]()
[English](README.md) | [中文](READMEcn.md)
![Demo](./Screenshot-1.png)
**Notes**:
@ -14,12 +15,11 @@
> ubuntu: 16.04LTS<br>
> ros version: 1.12.17
**If your `Atom` is 2.3 or before, or `pymycobot` is 1.\*, Please check branch [before](https://github.com/elephantrobotics/myCobotRos/tree/before)**
Download ROS [http://wiki.ros.org/ROS/Installation](http://wiki.ros.org/ROS/Installation)
<!-- **If your `Atom` is 2.3 or before, or `pymycobot` is 1.\*, Please check branch [before](https://github.com/elephantrobotics/myCobotRos/tree/before)** -->
## 1. Installation
## Installation
### Option 1: Docker
There are two ways to run this project. The first is by running the project in a container, and this requires
[installing docker](https://docs.docker.com/engine/install/ubuntu/) and
@ -77,123 +77,15 @@ cd ~/catkin_ws/src/mycobot_ros
python scripts/test.py
```
## 2. Package Modules
## Screenshot
### 2.1 Nodes
![Demo](./Screenshot-1.png)
- `display` is a display node. When the node is running, the model of ROS will show the movement of mycobot synchronously.
- `control_slider` is the node which slider bar control.
- `control_marker` is the node which use interactive marker control.
![Demo](./Screenshot-2.png)
### 2.2 Topics
- `joint_states` - control mycobot status.
```
Message_type: std_msgs/JointState
Data: position[float, float, float, float, float, float]
```
## 3. Visualization in RViz
### 3.1 Functions
- Visualization -- display.launch: This function will display robot arm movement in realtime when you manually move mycobot.
- Control -- control.launch: This function will allow you use slider bar to control movement of the robot arm.
### 3.2 Lanuch and Run
- **Use slide bar to control**
- launch ros and rviz
```
roslaunch mycobot_ros mycobot_slider.launch
```
- run python script
```
rosrun mycobot_ros slider_control.py
```
- **The model moves with the real manipulator**
- launch ros and rviz
```
roslanuch mycobot_ros mycobot_follow.launch
```
- run python script
```
rosrun mycobot_ros follow_display.py
```
- **Open the keyboard controller**
- launch
```
roslaunch mycobot_ros mycobot_teleop_keyboard.launch PORT:=/dev/ttyUSB0
```
- open another terminal run script
```
rosrun mycobot_ros teleop_keyboard.py _speed:=60 _change_size:=10
```
Then you will see this:
```
Mycobot Teleop Keyboard Controller
---------------------------
Movimg options(control coord [x,y,z,rx,ry,rz]):
w(x+)
a(y-) s(x-) d(y+)
z(z-) x(z+)
u(rx+) i(ry+) o(rz+)
j(rx-) k(ry-) l(rz-)
Gripper control:
g - open
h - close
Other:
1 - Go to init pose
2 -
3 -
q - Quit
currently: speed 50 change size 10
```
## MoveIT
### Execute plan with actual robot.
```
roslaunch mycobot_ros demo.launch
```
Open a new terminal and run:
```
rosrun mycobot_ros sync_signal.py
```
<!-- If you use the above command, then you may need to manually add some model components. If you don't want to be so troublesome, you can use the following command to load a saved **myCobot** model.
```bash
rosrun rviz rviz -d rospack find mycobot_ros/config/mycobot.rviz
``` -->
![Demo](./Screenshot-3.png)
![Demo](./Screenshot-4.png)
## Q & A
**Q: error[101]**

BIN
Screenshot-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 KiB

BIN
Screenshot-3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 KiB

BIN
Screenshot-4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 306 KiB

View file

@ -1,10 +1,10 @@
<launch>
<arg name="PORT" default="/dev/ttyUSB0" />
<arg name="BAUD" default="115200" />
<arg name="port" default="/dev/ttyUSB0" />
<arg name="baud" default="115200" />
<!-- Open communication service -->
<node name="mycobot_services" pkg="mycobot_ros" type="mycobot_services.py" output="screen">
<param name="port" type="string" value="$(arg PORT)" />
<param name="baud" type="int" value="$(arg BAUD)" />
<param name="port" type="string" value="$(arg port)" />
<param name="baud" type="int" value="$(arg baud)" />
</node>
</launch>

View file

@ -0,0 +1,59 @@
<launch>
<!-- By default, we do not start a database (it can be large) -->
<arg name="db" default="false" />
<!-- Allow user to specify database location -->
<arg name="db_path" default="$(find mycobot_ros)/default_warehouse_mongo_db" />
<!-- By default, we are not in debug mode -->
<arg name="debug" default="false" />
<!--
By default, hide joint_state_publisher's GUI
MoveIt!'s "demo" mode replaces the real robot driver with the joint_state_publisher.
The latter one maintains and publishes the current joint configuration of the simulated robot.
It also provides a GUI to move the simulated robot around "manually".
This corresponds to moving around the real robot without the use of MoveIt.
-->
<arg name="use_gui" default="false" />
<!-- Load the URDF, SRDF and other .yaml configuration files on the param server -->
<include file="$(find mycobot_ros)/launch/planning_context.launch">
<arg name="load_robot_description" value="true"/>
</include>
<!-- If needed, broadcast static tf for robot root -->
<!-- We do not have a robot connected, so publish fake joint states -->
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
<param name="use_gui" value="$(arg use_gui)"/>
<rosparam param="source_list">[move_group/fake_controller_joint_states]</rosparam>
<!-- <rosparam param="source_list">[/joint_states]</rosparam> -->
</node>
<!-- Given the published joint states, publish tf for the robot links -->
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" respawn="true" output="screen" />
<!-- Run the main MoveIt! executable without trajectory execution (we do not have controllers configured by default) -->
<include file="$(find mycobot_ros)/launch/move_group.launch">
<arg name="allow_trajectory_execution" value="true"/>
<arg name="fake_execution" value="true"/>
<arg name="info" value="true"/>
<arg name="debug" value="$(arg debug)"/>
</include>
<!-- Run Rviz and load the default config to see the state of the move_group node -->
<include file="$(find mycobot_ros)/launch/moveit_rviz.launch">
<!-- <arg name="config" value="false"/> -->
<arg name="config" value="true"/>
<arg name="debug" value="$(arg debug)"/>
</include>
<!-- If database loading was enabled, start mongodb as well -->
<include file="$(find mycobot_ros)/launch/default_warehouse_db.launch" if="$(arg db)">
<arg name="moveit_warehouse_database_path" value="$(arg db_path)"/>
</include>
</launch>

View file

@ -1,6 +1,6 @@
<launch>
<arg name="PORT" default="/dev/ttyUSB0" />
<arg name="BAUD" default="115200" />
<arg name="port" default="/dev/ttyUSB0" />
<arg name="baud" default="115200" />
<arg name="model" default="$(find mycobot_ros)/urdf/mycobot_urdf.urdf"/>
<arg name="rvizconfig" default="$(find mycobot_ros)/config/mycobot.rviz" />
@ -14,8 +14,8 @@
<node name="rviz" pkg="rviz" type="rviz" args="-d $(arg rvizconfig)" required="true" />
<include file="$(find mycobot_ros)/launch/communication_service.launch">
<arg name="PORT" value="$(arg PORT)" />
<arg name="BAUD" value="$(arg BAUD)" />
<arg name="port" value="$(arg port)" />
<arg name="baud" value="$(arg baud)" />
</include>
<node name="real_listener" pkg="mycobot_ros" type="listen_real.py" />
</launch>

View file

@ -73,25 +73,25 @@ class image_converter:
cv.imshow("Image", cv_image)
# marker = Marker()
# marker.header.frame_id = '/joint1'
# marker.header.stamp = rospy.Time.now()
# marker.type = marker.SPHERE
# marker.action = marker.ADD
# marker.scale.x = 0.04
# marker.scale.y = 0.04
# marker.scale.z = 0.04
marker = Marker()
marker.header.frame_id = '/joint1'
marker.header.stamp = rospy.Time.now()
marker.type = marker.SPHERE
marker.action = marker.ADD
marker.scale.x = 0.04
marker.scale.y = 0.04
marker.scale.z = 0.04
# marker.pose.position.x = center_x / 100
# marker.pose.position.y = center_y / 100
# marker.pose.position.z = 0
marker.pose.position.x = 0
marker.pose.position.y = 0
marker.pose.position.z = 0
# marker.color.a = 1.0
# marker.color.g = 1.0
marker.color.a = 1.0
marker.color.g = 1.0
cv.waitKey(3)
try:
# self.mark_pub.publish(marker)
self.mark_pub.publish(marker)
pass
except CvBridgeError as e:
print e

View file

@ -1,11 +1,14 @@
#!/usr/bin/env python2
import time, subprocess
import time
import rospy
from sensor_msgs.msg import JointState
from pymycobot.mycobot import MyCobot
mc = None
def callback(data):
rospy.loginfo(rospy.get_caller_id() + "%s", data)
data_list = []
@ -17,15 +20,18 @@ def callback(data):
mc.send_radians(data_list, 80)
def listener():
global mc
rospy.init_node('mycobot_reciver', anonymous=True)
port = rospy.get_param('~port', '/dev/ttyUSB0')
baud = rospy.get_param('~baud', 115200)
print(port, baud)
mc = MyCobot(port, baud)
rospy.Subscriber("joint_states", JointState, callback)
# spin() simply keeps python from exiting until this node is stopped
rospy.spin()
if __name__ == '__main__':
port = subprocess.check_output(['echo -n /dev/ttyUSB*'],
shell=True)
mc = MyCobot(port)
listener()

View file

@ -40,7 +40,7 @@ Other:
def vels(speed, turn):
return "currently:\tspeed %s\tchange size %s " % (speed, turn)
return "currently:\tspeed: %s\tchange percent: %s " % (speed, turn)
class Raw(object):
@ -57,17 +57,14 @@ class Raw(object):
def teleop_keyboard():
global settings
settings = termios.tcgetattr(sys.stdin)
rospy.init_node('teleop_keyboard')
model = 0
speed = rospy.get_param("~speed", 50)
change_size = rospy.get_param("~change_size", 10)
key_timeout = rospy.get_param("~key_timeout", 0.0)
if key_timeout == 0.0:
key_timeout = None
change_percent= rospy.get_param("~change_percent", 5)
change_angle = 180 * change_percent / 100
change_len = 250 * change_percent / 100
rospy.wait_for_service('get_joint_angles')
rospy.wait_for_service('set_joint_angles')
@ -103,49 +100,49 @@ def teleop_keyboard():
try:
print(msg)
print(vels(speed, change_size))
print(vels(speed, change_percent))
while(1):
try:
print("\r current coords: %s" % record_coords, end="")
# print("\r current coords: %s" % record_coords, end="")
with Raw(sys.stdin):
key = sys.stdin.read(1)
if key == 'q':
break
elif key in ['w', 'W']:
record_coords[0] += change_size
record_coords[0] += change_len
set_coords(*record_coords)
elif key in ['s', 'S']:
record_coords[0] -= change_size
record_coords[0] -= change_len
set_coords(*record_coords)
elif key in ['a', 'A']:
record_coords[1] -= change_size
record_coords[1] -= change_len
set_coords(*record_coords)
elif key in ['d', 'D']:
record_coords[1] += change_size
record_coords[1] += change_len
set_coords(*record_coords)
elif key in ['z', 'Z']:
record_coords[2] -= change_size
record_coords[2] -= change_len
set_coords(*record_coords)
elif key in ['x', 'X']:
record_coords[2] += change_size
record_coords[2] += change_len
set_coords(*record_coords)
elif key in ['u', 'U']:
record_coords[3] += change_size
record_coords[3] += change_angle
set_coords(*record_coords)
elif key in ['j', 'J']:
record_coords[3] -= change_size
record_coords[3] -= change_angle
set_coords(*record_coords)
elif key in ['i', 'I']:
record_coords[4] += change_size
record_coords[4] += change_angle
set_coords(*record_coords)
elif key in ['k', 'K']:
record_coords[4] -= change_size
record_coords[4] -= change_angle
set_coords(*record_coords)
elif key in ['o', 'O']:
record_coords[5] += change_size
record_coords[5] += change_angle
set_coords(*record_coords)
elif key in ['l', 'L']:
record_coords[5] -= change_size
record_coords[5] -= change_angle
set_coords(*record_coords)
elif key in ['g', 'G']:
switch_gripper(True)