Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dynamixel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
labrobotica
drivers
dynamixel
Commits
11997e3d
Commit
11997e3d
authored
5 years ago
by
Sergi Hernandez
Browse files
Options
Downloads
Patches
Plain Diff
Moved some static variables of the thread to the class to allow multiple instances of the class.
parent
ab197094
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/dynamixel_slave.cpp
+36
-37
36 additions, 37 deletions
src/dynamixel_slave.cpp
src/dynamixel_slave.h
+24
-0
24 additions, 0 deletions
src/dynamixel_slave.h
with
60 additions
and
37 deletions
src/dynamixel_slave.cpp
+
36
−
37
View file @
11997e3d
...
@@ -21,6 +21,9 @@ CDynamixelSlave::CDynamixelSlave(const std::string& cont_id,dyn_version_t dyn_ve
...
@@ -21,6 +21,9 @@ CDynamixelSlave::CDynamixelSlave(const std::string& cont_id,dyn_version_t dyn_ve
this
->
dyn_ver
=
dyn_ver
;
this
->
dyn_ver
=
dyn_ver
;
this
->
comm_dev
=
NULL
;
this
->
comm_dev
=
NULL
;
this
->
data_phase
=
false
;
this
->
num_bytes
=
0
;
this
->
length
=
0
;
}
}
void
*
CDynamixelSlave
::
process_packets_thread
(
void
*
params
)
void
*
CDynamixelSlave
::
process_packets_thread
(
void
*
params
)
...
@@ -31,10 +34,6 @@ void *CDynamixelSlave::process_packets_thread(void *params)
...
@@ -31,10 +34,6 @@ void *CDynamixelSlave::process_packets_thread(void *params)
unsigned
char
data
[
1024
];
unsigned
char
data
[
1024
];
bool
end
=
false
;
bool
end
=
false
;
static
bool
data_phase
=
false
;
static
unsigned
char
packet
[
64
*
1024
];
static
int
num_bytes
=
0
,
length
=
0
;
// wait until the comm device becomes valid
// wait until the comm device becomes valid
while
(
!
end
)
while
(
!
end
)
{
{
...
@@ -71,81 +70,81 @@ void *CDynamixelSlave::process_packets_thread(void *params)
...
@@ -71,81 +70,81 @@ void *CDynamixelSlave::process_packets_thread(void *params)
slave
->
comm_access
.
exit
();
slave
->
comm_access
.
exit
();
for
(
i
=
0
;
i
<
num
;
i
++
)
for
(
i
=
0
;
i
<
num
;
i
++
)
{
{
if
(
!
data_phase
)
if
(
!
slave
->
data_phase
)
{
{
switch
(
num_bytes
)
switch
(
slave
->
num_bytes
)
{
{
case
0
:
if
(
data
[
i
]
==
0xFF
)
case
0
:
if
(
data
[
i
]
==
0xFF
)
{
{
packet
[
num_bytes
]
=
data
[
i
];
slave
->
packet
[
slave
->
num_bytes
]
=
data
[
i
];
num_bytes
++
;
slave
->
num_bytes
++
;
}
}
break
;
break
;
case
1
:
if
(
data
[
i
]
==
0xFF
)
case
1
:
if
(
data
[
i
]
==
0xFF
)
{
{
packet
[
num_bytes
]
=
data
[
i
];
slave
->
packet
[
slave
->
num_bytes
]
=
data
[
i
];
num_bytes
++
;
slave
->
num_bytes
++
;
}
}
else
else
num_bytes
--
;
slave
->
num_bytes
--
;
break
;
break
;
case
2
:
if
(
data
[
i
]
==
0xFD
)
// version 2 header
case
2
:
if
(
data
[
i
]
==
0xFD
)
// version 2 header
{
{
if
(
slave
->
dyn_ver
==
dyn_version2
)
// the module is configured for version 2
if
(
slave
->
dyn_ver
==
dyn_version2
)
// the module is configured for version 2
{
{
packet
[
num_bytes
]
=
data
[
i
];
slave
->
packet
[
slave
->
num_bytes
]
=
data
[
i
];
num_bytes
++
;
slave
->
num_bytes
++
;
}
}
else
else
num_bytes
=
0
;
// ignore packet and restart synchronization
slave
->
num_bytes
=
0
;
// ignore packet and restart synchronization
}
}
else
if
(
data
[
i
]
!=
0xFF
)
else
if
(
data
[
i
]
!=
0xFF
)
{
{
packet
[
num_bytes
]
=
data
[
i
];
slave
->
packet
[
slave
->
num_bytes
]
=
data
[
i
];
num_bytes
++
;
slave
->
num_bytes
++
;
}
}
break
;
break
;
case
3
:
packet
[
num_bytes
]
=
data
[
i
];
case
3
:
slave
->
packet
[
slave
->
num_bytes
]
=
data
[
i
];
if
(
slave
->
dyn_ver
==
dyn_version1
)
if
(
slave
->
dyn_ver
==
dyn_version1
)
{
{
length
=
data
[
i
];
slave
->
length
=
data
[
i
];
num_bytes
++
;
slave
->
num_bytes
++
;
/* read packet_data */
/* read packet_data */
data_phase
=
true
;
slave
->
data_phase
=
true
;
}
}
else
else
num_bytes
++
;
slave
->
num_bytes
++
;
break
;
break
;
case
4
:
packet
[
num_bytes
]
=
data
[
i
];
case
4
:
slave
->
packet
[
slave
->
num_bytes
]
=
data
[
i
];
num_bytes
++
;
slave
->
num_bytes
++
;
break
;
break
;
case
5
:
packet
[
num_bytes
]
=
data
[
i
];
case
5
:
slave
->
packet
[
slave
->
num_bytes
]
=
data
[
i
];
num_bytes
++
;
slave
->
num_bytes
++
;
length
=
data
[
i
];
slave
->
length
=
data
[
i
];
break
;
break
;
case
6
:
packet
[
num_bytes
]
=
data
[
i
];
case
6
:
slave
->
packet
[
slave
->
num_bytes
]
=
data
[
i
];
num_bytes
++
;
slave
->
num_bytes
++
;
length
+=
(
data
[
i
]
<<
8
);
slave
->
length
+=
(
data
[
i
]
<<
8
);
/* read packet_data */
/* read packet_data */
data_phase
=
true
;
slave
->
data_phase
=
true
;
break
;
break
;
default
:
break
;
default
:
break
;
}
}
}
}
else
// data phase
else
// data phase
{
{
packet
[
num_bytes
]
=
data
[
i
];
slave
->
packet
[
slave
->
num_bytes
]
=
data
[
i
];
num_bytes
++
;
slave
->
num_bytes
++
;
length
--
;
slave
->
length
--
;
if
(
length
==
0
)
if
(
slave
->
length
==
0
)
{
{
data_phase
=
false
;
slave
->
data_phase
=
false
;
memcpy
(
slave
->
new_packet
,
packet
,
num_bytes
);
memcpy
(
slave
->
new_packet
,
slave
->
packet
,
slave
->
num_bytes
);
if
(
slave
->
dyn_ver
==
dyn_version1
)
if
(
slave
->
dyn_ver
==
dyn_version1
)
slave
->
dynamixel_loop_v1
();
slave
->
dynamixel_loop_v1
();
else
else
slave
->
dynamixel_loop_v2
();
slave
->
dynamixel_loop_v2
();
num_bytes
=
0
;
slave
->
num_bytes
=
0
;
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/dynamixel_slave.h
+
24
−
0
View file @
11997e3d
...
@@ -101,7 +101,31 @@ class CDynamixelSlave
...
@@ -101,7 +101,31 @@ class CDynamixelSlave
*
*
*/
*/
unsigned
char
slave_answer
[
1024
];
unsigned
char
slave_answer
[
1024
];
/**
* \brief
*
*/
unsigned
int
slave_answer_length
;
unsigned
int
slave_answer_length
;
/**
* \brief
*
*/
bool
data_phase
;
/**
* \brief
*
*/
unsigned
char
packet
[
64
*
1024
];
/**
* \brief
*
*/
unsigned
int
num_bytes
;
/**
* \brief
*
*/
unsigned
int
length
;
protected:
protected:
/**
/**
* \brief mutual exclusion mechanism to access the usb
* \brief mutual exclusion mechanism to access the usb
...
...
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