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
e89257fa
Commit
e89257fa
authored
12 years ago
by
Sergi Hernandez
Browse files
Options
Downloads
Patches
Plain Diff
Added functions to read from and write to an arbitrary length of the internal memory of the device.
parent
ccf8ff3c
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.cpp
+202
-0
202 additions, 0 deletions
src/dynamixel.cpp
src/dynamixel.h
+10
-0
10 additions, 0 deletions
src/dynamixel.h
with
212 additions
and
0 deletions
src/dynamixel.cpp
+
202
−
0
View file @
e89257fa
...
...
@@ -629,6 +629,208 @@ void CDynamixel::registered_word_write(unsigned char address, unsigned short int
}
}
void
CDynamixel
::
write_registers
(
unsigned
char
address
,
unsigned
char
*
data
,
unsigned
int
length
)
{
unsigned
char
*
packet
;
std
::
list
<
std
::
string
>
events
;
unsigned
char
answer
[
6
];
std
::
string
error_msg
;
int
num
=
0
,
read
=
0
,
it
=
0
;
bool
rx_tx_ok
=
false
;
unsigned
int
i
=
0
;
if
(
this
->
usb_dev
!=
NULL
)
{
if
(
address
+
length
>
255
)
{
/* handle exceptions */
throw
CDynamixelException
(
_HERE_
,
"Invalid address range"
,
this
->
node_address
);
}
else
{
events
.
push_back
(
this
->
usb_rx_event_id
);
while
(
!
rx_tx_ok
)
{
packet
=
new
unsigned
char
[
length
+
7
];
this
->
usb_access
->
enter
();
packet
[
0
]
=
0xFF
;
packet
[
1
]
=
0xFF
;
packet
[
2
]
=
this
->
node_address
;
packet
[
3
]
=
length
+
3
;
packet
[
4
]
=
0x03
;
packet
[
5
]
=
(
unsigned
char
)
address
;
for
(
i
=
0
;
i
<
length
;
i
++
)
packet
[
i
+
6
]
=
data
[
i
];
packet
[
length
+
6
]
=
this
->
compute_checksum
(
packet
,
length
+
6
);
if
(
this
->
usb_dev
->
write
(
packet
,
length
+
7
)
!=
(
length
+
7
))
{
/* handle exceptions */
this
->
usb_access
->
exit
();
delete
[]
packet
;
throw
CDynamixelException
(
_HERE_
,
"Unexpected error while writing to the dynamixel device"
,
this
->
node_address
);
}
else
{
delete
[]
packet
;
try
{
while
(
read
<
6
)
{
this
->
event_server
->
wait_all
(
events
,
100
);
num
=
this
->
usb_dev
->
get_num_data
();
this
->
usb_dev
->
read
(
&
answer
[
read
],
num
);
read
+=
num
;
}
if
(
this
->
compute_checksum
(
answer
,
6
)
!=
0
)
{
/* handle exceptions */
this
->
usb_access
->
exit
();
it
++
;
if
(
it
==
NUM_RETRIES
)
throw
CDynamixelSyncException
(
"Invalid packet checksum"
);
else
read
=
0
;
}
else
{
rx_tx_ok
=
true
;
// transmission ok
this
->
usb_access
->
exit
();
}
}
catch
(
CEventTimeoutException
&
e
){
this
->
resync
();
this
->
usb_access
->
exit
();
}
}
}
if
(
answer
[
4
]
!=
0x00
)
{
/* handle exceptions */
if
(
answer
[
4
]
&
0x01
)
error_msg
+=
"
\n
The supply voltage is out of range"
;
if
(
answer
[
4
]
&
0x02
)
error_msg
+=
"
\n
The goal position is out of range"
;
if
(
answer
[
4
]
&
0x04
)
error_msg
+=
"
\n
The internal temperature is too high"
;
if
(
answer
[
4
]
&
0x08
)
error_msg
+=
"
\n
The provided parameter is out of range"
;
if
(
answer
[
4
]
&
0x10
)
error_msg
+=
"
\n
The packet sent to the dynamixel device had an invalid checksum"
;
if
(
answer
[
4
]
&
0x20
)
error_msg
+=
"
\n
Overload"
;
if
(
answer
[
4
]
&
0x40
)
error_msg
+=
"
\n
Invalid instruction"
;
throw
CDynamixelAlarmException
(
_HERE_
,
error_msg
,
this
->
node_address
,
answer
[
4
]);
}
}
}
else
{
/* handle exceptions */
throw
CDynamixelException
(
_HERE_
,
"The communication device is not ready to send data"
,
this
->
node_address
);
}
}
void
CDynamixel
::
read_registers
(
unsigned
char
address
,
unsigned
char
*
data
,
unsigned
int
length
)
{
unsigned
char
packet
[
8
]
=
{
0xFF
,
0xFF
,
0x00
,
0x04
,
0x02
,
0x00
,
0x00
,
0x00
};
int
num
=
0
,
read
=
0
,
it
=
0
,
read_length
=
length
+
6
;
std
::
list
<
std
::
string
>
events
;
unsigned
char
*
answer
;
std
::
string
error_msg
;
bool
rx_tx_ok
=
false
;
unsigned
int
i
=
0
;
if
(
this
->
usb_dev
!=
NULL
)
{
events
.
push_back
(
this
->
usb_rx_event_id
);
while
(
!
rx_tx_ok
)
{
this
->
usb_access
->
enter
();
packet
[
2
]
=
this
->
node_address
;
packet
[
5
]
=
(
unsigned
char
)
address
;
packet
[
6
]
=
length
;
packet
[
7
]
=
this
->
compute_checksum
(
packet
,
8
);
if
(
this
->
usb_dev
->
write
(
packet
,
8
)
!=
8
)
{
/* handle exceptions */
this
->
usb_access
->
exit
();
throw
CDynamixelException
(
_HERE_
,
"Unexpected error while writing to the dynamixel device"
,
this
->
node_address
);
}
else
{
try
{
answer
=
new
unsigned
char
[
length
+
6
];
while
(
read
<
read_length
)
{
this
->
event_server
->
wait_all
(
events
,
100
);
num
=
this
->
usb_dev
->
get_num_data
();
this
->
usb_dev
->
read
(
&
answer
[
read
],
num
);
read
+=
num
;
if
(
read
>
5
&&
answer
[
4
]
!=
0x00
)
read_length
=
6
;
}
if
(
this
->
compute_checksum
(
answer
,
read_length
)
!=
0
)
{
/* handle exceptions */
this
->
usb_access
->
exit
();
it
++
;
if
(
it
==
NUM_RETRIES
)
{
delete
[]
answer
;
throw
CDynamixelSyncException
(
"Invalid packet checksum"
);
}
else
{
read
=
0
;
read_length
=
length
+
6
;
}
}
else
{
rx_tx_ok
=
true
;
// transmission ok
this
->
usb_access
->
exit
();
}
}
catch
(
CEventTimeoutException
&
e
){
this
->
resync
();
this
->
usb_access
->
exit
();
}
}
}
if
(
answer
[
4
]
!=
0x00
)
{
/* handle exceptions */
if
(
answer
[
4
]
&
0x01
)
error_msg
+=
"
\n
The supply voltage is out of range"
;
if
(
answer
[
4
]
&
0x02
)
error_msg
+=
"
\n
The goal position is out of range"
;
if
(
answer
[
4
]
&
0x04
)
error_msg
+=
"
\n
The internal temperature is too high"
;
if
(
answer
[
4
]
&
0x08
)
error_msg
+=
"
\n
The provided parameter is out of range"
;
if
(
answer
[
4
]
&
0x10
)
error_msg
+=
"
\n
The packet sent to the dynamixel device had an invalid checksum"
;
if
(
answer
[
4
]
&
0x20
)
error_msg
+=
"
\n
Overload"
;
if
(
answer
[
4
]
&
0x40
)
error_msg
+=
"
\n
Invalid instruction"
;
delete
[]
answer
;
throw
CDynamixelAlarmException
(
_HERE_
,
error_msg
,
this
->
node_address
,
answer
[
4
]);
}
else
{
for
(
i
=
0
;
i
<
length
;
i
++
)
data
[
i
]
=
answer
[
i
+
5
];
delete
[]
answer
;
}
}
else
{
/* handle exceptions */
throw
CDynamixelException
(
_HERE_
,
"The communication device is not ready to send data"
,
this
->
node_address
);
}
}
void
CDynamixel
::
reset
(
void
)
{
unsigned
char
packet
[
6
]
=
{
0xFF
,
0xFF
,
0x00
,
0x02
,
0x06
,
0x00
};
...
...
This diff is collapsed.
Click to expand it.
src/dynamixel.h
+
10
−
0
View file @
e89257fa
...
...
@@ -106,6 +106,16 @@ class CDynamixel
*
*/
void
registered_word_write
(
unsigned
char
address
,
unsigned
short
int
data
);
/**
* \brief Function to write to a register
*
*/
void
write_registers
(
unsigned
char
address
,
unsigned
char
*
data
,
unsigned
int
length
);
/**
* \brief Function to write to a register
*
*/
void
read_registers
(
unsigned
char
address
,
unsigned
char
*
data
,
unsigned
int
length
);
/**
* \brief
*
...
...
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