Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
crosbot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Crosbot
crosbot
Commits
641c0ccc
Commit
641c0ccc
authored
11 years ago
by
Rescue Group
Browse files
Options
Downloads
Plain Diff
Merge rescuelap2.local:workspace/crosbot/src
parents
395859c6
6353e6b1
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
crosbot_ui/include/crosbot_ui/renders/robot/jointcontrol.hpp
+41
-0
41 additions, 0 deletions
crosbot_ui/include/crosbot_ui/renders/robot/jointcontrol.hpp
crosbot_ui/src/renders/robot/jointcontrol.cpp
+116
-0
116 additions, 0 deletions
crosbot_ui/src/renders/robot/jointcontrol.cpp
with
157 additions
and
0 deletions
crosbot_ui/include/crosbot_ui/renders/robot/jointcontrol.hpp
0 → 100644
+
41
−
0
View file @
641c0ccc
/*
* jointcontrol.hpp
*
* Created on: 27/06/2013
* Author: rescue
*/
#ifndef CROSBOT_JOINTCONTROL_HPP_
#define CROSBOT_JOINTCONTROL_HPP_
#include
<ros/ros.h>
#include
<crosbot/thread.hpp>
namespace
crosbot
{
class
JointController
{
protected:
class
Joint
{
public:
std
::
string
name
;
double
pos
,
desiredPos
;
Joint
(
const
std
::
string
&
name
)
:
name
(
name
),
pos
(
NAN
),
desiredPos
(
NAN
)
{}
};
static
ReadWriteLock
jLock
;
static
std
::
vector
<
Joint
>
joints
;
static
Joint
*
findJoint
(
const
std
::
string
&
joint
);
public
:
static
void
connect
();
static
void
shutdown
();
static
double
getPos
(
const
std
::
string
&
joint
);
static
void
setPos
(
const
std
::
string
&
joint
,
double
pos
);
static
void
zero
(
const
std
::
vector
<
std
::
string
>&
joints
);
friend
class
JointControlConnection
;
};
}
// namespace crosbot
#endif
/* CROSBOT_JOINTCONTROL_HPP_ */
This diff is collapsed.
Click to expand it.
crosbot_ui/src/renders/robot/jointcontrol.cpp
0 → 100644
+
116
−
0
View file @
641c0ccc
/*
* jointcontrol.hpp
*
* Created on: 27/06/2013
* Author: rescue
*/
#include
<ros/ros.h>
#include
<crosbot_ui/renders/robot/jointcontrol.hpp>
#include
<sensor_msgs/JointState.h>
namespace
crosbot
{
class
JointControlConnection
{
public:
ros
::
Subscriber
jointSub
;
ros
::
Publisher
jointPub
;
void
callbackJoints
(
const
sensor_msgs
::
JointStateConstPtr
&
state
)
{
for
(
size_t
i
=
0
;
i
<
state
->
name
.
size
();
++
i
)
{
JointController
::
Joint
*
joint
=
JointController
::
findJoint
(
state
->
name
[
i
]);
{{
Lock
lock
(
JointController
::
jLock
,
true
);
if
(
joint
==
NULL
)
{
JointController
::
joints
.
push_back
(
JointController
::
Joint
(
state
->
name
[
i
]));
joint
=
&
JointController
::
joints
[
JointController
::
joints
.
size
()
-
1
];
}
joint
->
pos
=
state
->
position
[
i
];
}}
}
}
void
connect
()
{
ros
::
NodeHandle
nh
;
if
(
!
jointSub
)
jointSub
=
nh
.
subscribe
(
"/joint_states"
,
2
,
&
JointControlConnection
::
callbackJoints
,
this
);
if
(
!
jointPub
)
jointPub
=
nh
.
advertise
<
sensor_msgs
::
JointState
>
(
"/joint_control"
,
1
);
}
void
shutdown
()
{
jointPub
.
shutdown
();
jointSub
.
shutdown
();
}
};
JointControlConnection
connection
;
ReadWriteLock
JointController
::
jLock
;
std
::
vector
<
JointController
::
Joint
>
JointController
::
joints
;
void
JointController
::
connect
()
{
connection
.
connect
();
}
void
JointController
::
shutdown
()
{
connection
.
shutdown
();
}
JointController
::
Joint
*
JointController
::
findJoint
(
const
std
::
string
&
joint
)
{
Lock
lock
(
jLock
);
for
(
size_t
i
=
0
;
i
<
joints
.
size
();
++
i
)
{
if
(
joints
[
i
].
name
==
joint
)
{
return
&
joints
[
i
];
}
}
return
NULL
;
}
double
JointController
::
getPos
(
const
std
::
string
&
joint
)
{
Lock
lock
(
jLock
);
for
(
size_t
i
=
0
;
i
<
joints
.
size
();
++
i
)
{
Joint
&
j
=
joints
[
i
];
if
(
j
.
name
==
joint
)
return
j
.
pos
;
}
return
NAN
;
}
void
JointController
::
setPos
(
const
std
::
string
&
joint
,
double
pos
)
{
if
(
!
connection
.
jointPub
)
return
;
Joint
*
j
=
findJoint
(
joint
);
sensor_msgs
::
JointState
state
;
state
.
header
.
stamp
=
ros
::
Time
::
now
();
state
.
name
.
push_back
(
joint
);
state
.
position
.
push_back
(
pos
);
if
(
j
!=
NULL
)
{
j
->
desiredPos
=
pos
;
}
connection
.
jointPub
.
publish
(
state
);
}
void
JointController
::
zero
(
const
std
::
vector
<
std
::
string
>&
joints
)
{
if
(
joints
.
size
()
==
0
||
!
connection
.
jointPub
)
return
;
sensor_msgs
::
JointState
state
;
state
.
header
.
stamp
=
ros
::
Time
::
now
();
for
(
size_t
i
=
0
;
i
<
joints
.
size
();
++
i
)
{
Joint
*
j
=
findJoint
(
joints
[
i
]);
if
(
j
==
NULL
)
continue
;
state
.
name
.
push_back
(
j
->
name
);
state
.
position
.
push_back
(
0
);
j
->
desiredPos
=
0
;
}
connection
.
jointPub
.
publish
(
state
);
}
}
// namespace crosbot
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment