-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
817 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/usr/bin/env python3 | ||
#!/usr/bin/env python2 | ||
# -*- coding: utf-8 -*- | ||
import time | ||
|
||
import rospy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
mycobot_280/mycobot_280_gazebo_moveit/launch/mycobot_follow_gazebo.launch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<launch> | ||
<arg name="paused" default="false"/> | ||
<arg name="gazebo_gui" default="true"/> | ||
<!-- Load URDF file,加载URDF文件 --> | ||
<arg name="model" default="$(find mycobot_description)/urdf/mycobot/mycobot_280_m5_gazebo.urdf"/> | ||
<!-- <arg name="rvizconfig" default="$(find mycobot_280)/config/mycobot.rviz" /> --> | ||
|
||
<include file="$(find gazebo_ros)/launch/empty_world.launch"> | ||
<arg name="world_name" default="worlds/empty.world"/> | ||
<arg name="paused" value="$(arg paused)"/> | ||
<arg name="gui" value="$(arg gazebo_gui)"/> | ||
</include> | ||
|
||
<param name="robot_description" command="$(find xacro)/xacro --inorder $(arg model)" /> | ||
<!-- Combinejoin values to TF ,将值合并到TF--> | ||
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" > | ||
<rosparam param="source_list" subst_value="true">["joint_states"]</rosparam> | ||
</node> | ||
<!-- show in Rviza,显示在Rviz --> | ||
<!-- <node name="rviz" pkg="rviz" type="rviz" args="-d $(arg rvizconfig)" required="true" /> --> | ||
<node name="spawn_gazebo_model" pkg="gazebo_ros" type="spawn_model" args="-urdf -param robot_description -model robot -x 0 -y 0 -z 1" | ||
respawn="false" output="screen" /> | ||
|
||
<include file="$(find mycobot_280_gazebo_moveit)/launch/ros_controllers.launch"/> | ||
</launch> |
23 changes: 23 additions & 0 deletions
23
mycobot_280/mycobot_280_gazebo_moveit/launch/teleop_keyboard_gazebo.launch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<launch> | ||
<arg name="paused" default="false"/> | ||
<arg name="gazebo_gui" default="true"/> | ||
<arg name="model" default="$(find mycobot_description)/urdf/mycobot/mycobot_280_m5_gazebo.urdf"/> | ||
|
||
<!-- Launch Gazebo --> | ||
<include file="$(find gazebo_ros)/launch/empty_world.launch"> | ||
<arg name="world_name" default="worlds/empty.world"/> | ||
<arg name="paused" value="$(arg paused)"/> | ||
<arg name="gui" value="$(arg gazebo_gui)"/> | ||
</include> | ||
|
||
<param name="robot_description" command="$(find xacro)/xacro --inorder $(arg model)" /> | ||
|
||
<!-- Combinejoin values to TF ,将值合并到TF--> | ||
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" /> | ||
|
||
<node name="spawn_gazebo_model" pkg="gazebo_ros" type="spawn_model" args="-urdf -param robot_description -model robot -x 0 -y 0 -z 1" | ||
respawn="false" output="screen" /> | ||
|
||
<include file="$(find mycobot_280_gazebo_moveit)/launch/ros_controllers.launch"/> | ||
|
||
</launch> |
76 changes: 76 additions & 0 deletions
76
mycobot_280/mycobot_280_gazebo_moveit/scripts/follow_display_gazebo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env python2 | ||
# -*- coding: utf-8 -*- | ||
import time | ||
import rospy | ||
from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint | ||
from pymycobot.mycobot import MyCobot | ||
|
||
# Global Variables | ||
joint_names = [ | ||
"joint2_to_joint1", | ||
"joint3_to_joint2", | ||
"joint4_to_joint3", | ||
"joint5_to_joint4", | ||
"joint6_to_joint5", | ||
"joint6output_to_joint6", | ||
] | ||
|
||
def talker(): | ||
rospy.init_node("display", anonymous=True) | ||
|
||
print("Try connect real mycobot...") | ||
port = rospy.get_param("~port", "/dev/ttyUSB0") | ||
baud = rospy.get_param("~baud", 115200) | ||
print("port: {}, baud: {}\n".format(port, baud)) | ||
try: | ||
mycobot = MyCobot(port, baud) | ||
except Exception as e: | ||
print(e) | ||
print( | ||
"""\ | ||
\rTry connect mycobot failed! | ||
\rPlease check wether connected with mycobot. | ||
\rPlease chckt wether the port or baud is right. | ||
""" | ||
) | ||
exit(1) | ||
mycobot.release_all_servos() | ||
time.sleep(0.1) | ||
print("Rlease all servos over.\n") | ||
|
||
pub_command = rospy.Publisher("/mycobot_position_controller/command", JointTrajectory, queue_size=10) | ||
rate = rospy.Rate(30) # 30hz | ||
|
||
# pub joint state | ||
|
||
print("publishing ...") | ||
while not rospy.is_shutdown(): | ||
|
||
angles = mycobot.get_radians() | ||
data_list = [] | ||
for index, value in enumerate(angles): | ||
data_list.append(value) | ||
|
||
# rospy.loginfo('{}'.format(data_list)) | ||
|
||
# Create JointTrajectory message | ||
traj_msg = JointTrajectory() | ||
traj_msg.header.stamp = rospy.Time.now() | ||
traj_msg.joint_names = joint_names | ||
|
||
point = JointTrajectoryPoint() | ||
point.positions = data_list | ||
point.velocities = [0.0] * len(joint_names) | ||
point.time_from_start = rospy.Duration(0.1) # Set a small duration to continuously update | ||
|
||
traj_msg.points.append(point) | ||
pub_command.publish(traj_msg) | ||
|
||
rate.sleep() | ||
|
||
|
||
if __name__ == "__main__": | ||
try: | ||
talker() | ||
except rospy.ROSInterruptException: | ||
pass |
Oops, something went wrong.