Skip to content

Commit 1a9ff12

Browse files
author
Murilo Marinho
committed
[sas_robot_driver_myrobot] Adding the part about the python script.
1 parent e04c35a commit 1a9ff12

File tree

2 files changed

+101
-5
lines changed

2 files changed

+101
-5
lines changed

docs/source/sas/sas_robot_driver_add_new_robot.rst

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ to match other elements of ``sas``.
348348
:lines: 17
349349

350350
Running the launch file
351-
-----------------------
351+
+++++++++++++++++++++++
352352

353353
.. code-block:: console
354354
@@ -398,3 +398,99 @@ Accessing through Python
398398
└── src
399399
├── sas_robot_driver_myrobot.cpp
400400
└── sas_robot_driver_myrobot_node.cpp
401+
402+
403+
:download:`joint_interface_example.py <../../../sas_tutorial_workspace/src/sas_robot_driver_myrobot/scripts/joint_interface_example.py>`
404+
405+
.. literalinclude:: ../../../sas_tutorial_workspace/src/sas_robot_driver_myrobot/scripts/joint_interface_example.py
406+
:language: python
407+
:linenos:
408+
:lines: 27-
409+
410+
411+
412+
With the :file:`launch` file running in one terminal, open another one and run
413+
414+
.. code-block:: console
415+
416+
ros2 topic echo /myrobot_1/get/joint_states
417+
418+
Then, in yet another terminal, run the sample Python script
419+
420+
.. code-block:: console
421+
422+
ros2 run sas_robot_driver_myrobot joint_interface_example.py
423+
424+
The output of :file:`joint_interface_example.py` will be only descriptive.
425+
426+
.. dropdown:: joint_interface_example.py output
427+
428+
.. code-block:: console
429+
430+
**************************************************************************
431+
sas::Clock (c) Murilo M. Marinho (murilomarinho.info) 2016-2023 LGPLv3
432+
**************************************************************************
433+
**************************************************************************************
434+
sas::RobotDriverClient (c) Murilo M. Marinho (murilomarinho.info) 2016-2023 LGPLv3
435+
**************************************************************************************
436+
[INFO] [1743579389.703532605] [sas_robot_driver_myrobot_joint_space_example_node_cpp]: ::Initializing RobotDriverClient with prefix myrobot_1
437+
topic prefix = myrobot_1
438+
joint positions = [0. 0. 0. 0. 0. 0.]
439+
440+
441+
While the magic happens in ROS2, therefore in the terminal in which we executed ``ros2 topic echo``
442+
443+
.. dropdown:: ros2 topic echo output
444+
445+
.. code-block:: console
446+
447+
header:
448+
stamp:
449+
sec: 1743579392
450+
nanosec: 471990465
451+
frame_id: ''
452+
name: []
453+
position:
454+
- 0.17141407117840998
455+
- 0.17141407117840998
456+
- 0.17141407117840998
457+
- 0.17141407117840998
458+
- 0.17141407117840998
459+
- 0.17141407117840998
460+
velocity: []
461+
effort: []
462+
---
463+
header:
464+
stamp:
465+
sec: 1743579392
466+
nanosec: 474015460
467+
frame_id: ''
468+
name: []
469+
position:
470+
- 0.17141407117840998
471+
- 0.17141407117840998
472+
- 0.17141407117840998
473+
- 0.17141407117840998
474+
- 0.17141407117840998
475+
- 0.17141407117840998
476+
velocity: []
477+
effort: []
478+
---
479+
header:
480+
stamp:
481+
sec: 1743579392
482+
nanosec: 475985122
483+
frame_id: ''
484+
name: []
485+
position:
486+
- 0.17141407117840998
487+
- 0.17141407117840998
488+
- 0.17141407117840998
489+
- 0.17141407117840998
490+
- 0.17141407117840998
491+
- 0.17141407117840998
492+
velocity: []
493+
effort: []
494+
495+
496+

sas_tutorial_workspace/src/sas_robot_driver_myrobot/src/sas_robot_driver_myrobot.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class RobotDriverMyrobot::Impl
4141
bool motor_on{false};
4242

4343
VectorXd joint_positions_;
44-
VectorXd target_joint_positions_;
44+
4545

4646
Impl()
4747
{
@@ -93,7 +93,7 @@ void RobotDriverMyrobot::set_target_joint_positions(const VectorXd &desired_join
9393
if(desired_joint_positions_rad.size() != 6)
9494
throw std::runtime_error("Incorrect vector size in RobotDriverMyrobot::set_target_joint_positions");
9595

96-
impl_->target_joint_positions_ = desired_joint_positions_rad;
96+
impl_->joint_positions_ = desired_joint_positions_rad;
9797
}
9898

9999
/**
@@ -133,7 +133,7 @@ void RobotDriverMyrobot::initialize()
133133
{
134134
impl_->motor_on = true;
135135

136-
impl_->target_joint_positions_ = impl_->joint_positions_;
136+
137137
}
138138

139139
/**
@@ -143,7 +143,7 @@ void RobotDriverMyrobot::initialize()
143143
void RobotDriverMyrobot::deinitialize()
144144
{
145145
impl_->motor_on = false;
146-
impl_->target_joint_positions_ = VectorXd();
146+
147147
}
148148

149149
/**

0 commit comments

Comments
 (0)