Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ Install roslibjs with any NPM-compatible package manager via, for example,
npm install roslib
```

~Pre-built files can be found in either [roslib.js](build/roslib.js) or [roslib.min.js](build/roslib.min.js).~

As we are updating to v2, we don't provide pre-built files anymore in the repo.

Alternatively, you can use the v1 release via the [JsDelivr](https://www.jsdelivr.com/) CDN: ([full](https://cdn.jsdelivr.net/npm/roslib@1/build/roslib.js)) | ([min](https://cdn.jsdelivr.net/npm/roslib@1/build/roslib.min.js))

## Troubleshooting
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"scripts": {
"build": "vite build",
"doc": "typedoc src/RosLib.ts",
"doc": "typedoc src/RosLib.ts --treatWarningsAsErrors",
"lint": "eslint .",
"test": "vitest",
"prepublishOnly": "npm run test",
Expand Down
15 changes: 12 additions & 3 deletions src/RosLib.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/**
* @fileOverview
* @author Russell Toris - [email protected]
*/

/** @description Library version */
/** Library version */
export const REVISION = import.meta.env.VITE_ROSLIBJS_VERSION;

// Core exports
export { default as Ros } from "./core/Ros.js";
export { default as Ros, type TypeDefDict } from "./core/Ros.js";
export { default as Topic } from "./core/Topic.js";
export { default as Param } from "./core/Param.js";
export { default as Service } from "./core/Service.js";
export { default as Action } from "./core/Action.js";
export { type GoalStatus } from "./core/GoalStatus.js";

// Core Transport exports
export {
Expand Down Expand Up @@ -45,6 +45,7 @@ export { default as UrdfCylinder } from "./urdf/UrdfCylinder.js";
export { default as UrdfLink } from "./urdf/UrdfLink.js";
export { default as UrdfMaterial } from "./urdf/UrdfMaterial.js";
export { default as UrdfMesh } from "./urdf/UrdfMesh.js";
export { default as UrdfJoint } from "./urdf/UrdfJoint.js";
export {
default as UrdfModel,
type UrdfModelOptions,
Expand All @@ -61,3 +62,11 @@ export {
type UrdfDefaultOptions,
} from "./urdf/UrdfTypes.js";
export { isElement, parseUrdfOrigin } from "./urdf/UrdfUtils.js";

// Only export the types Typedoc requires you to export - those are our API. Anything else is internal.
export type { rosapi } from "./types/rosapi";
export type { actionlib_msgs } from "./types/actionlib_msgs";
export type { std_msgs } from "./types/std_msgs";
export type { tf2_msgs } from "./types/tf2_msgs";
export type { geometry_msgs } from "./types/geometry_msgs";
export type { RosbridgeMessage } from "./types/protocol.js";
53 changes: 30 additions & 23 deletions src/actionlib/ActionClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ export default class ActionClient<
omitFeedback?: boolean;
omitStatus?: boolean;
omitResult?: boolean;
feedbackListener: Topic<{
#feedbackListener: Topic<{
status: actionlib_msgs.GoalStatus;
feedback: TFeedback;
}>;
statusListener: Topic<actionlib_msgs.GoalStatusArray>;
resultListener: Topic<{
#statusListener: Topic<actionlib_msgs.GoalStatusArray>;
#resultListener: Topic<{
status: actionlib_msgs.GoalStatus;
result: TResult;
}>;
goalTopic: Topic<{ goal: TGoal; goal_id: actionlib_msgs.GoalID }>;
cancelTopic: Topic<Partial<actionlib_msgs.GoalID>>;
#goalTopic: Topic<{ goal: TGoal; goal_id: actionlib_msgs.GoalID }>;
#cancelTopic: Topic<Partial<actionlib_msgs.GoalID>>;
/**
* @param options
* @param options.ros - The ROSLIB.Ros connection handle.
Expand Down Expand Up @@ -84,43 +84,43 @@ export default class ActionClient<
this.omitResult = omitResult;

// create the topics associated with actionlib
this.feedbackListener = new Topic({
this.#feedbackListener = new Topic({
ros: this.ros,
name: `${this.serverName}/feedback`,
messageType: `${this.actionName}Feedback`,
});

this.statusListener = new Topic({
this.#statusListener = new Topic({
ros: this.ros,
name: `${this.serverName}/status`,
messageType: "actionlib_msgs/GoalStatusArray",
});

this.resultListener = new Topic({
this.#resultListener = new Topic({
ros: this.ros,
name: `${this.serverName}/result`,
messageType: `${this.actionName}Result`,
});

this.goalTopic = new Topic({
this.#goalTopic = new Topic({
ros: this.ros,
name: `${this.serverName}/goal`,
messageType: `${this.actionName}Goal`,
});

this.cancelTopic = new Topic({
this.#cancelTopic = new Topic({
ros: this.ros,
name: `${this.serverName}/cancel`,
messageType: "actionlib_msgs/GoalID",
});

// advertise the goal and cancel topics
this.goalTopic.advertise();
this.cancelTopic.advertise();
this.#goalTopic.advertise();
this.#cancelTopic.advertise();

// subscribe to the status topic
if (!this.omitStatus) {
this.statusListener.subscribe((statusMessage) => {
this.#statusListener.subscribe((statusMessage) => {
this.receivedStatus = true;
statusMessage.status_list.forEach((status) => {
const goal = this.goals[status.goal_id.id];
Expand All @@ -133,7 +133,7 @@ export default class ActionClient<

// subscribe the the feedback topic
if (!this.omitFeedback) {
this.feedbackListener.subscribe((feedbackMessage) => {
this.#feedbackListener.subscribe((feedbackMessage) => {
const goal = this.goals[feedbackMessage.status.goal_id.id];
if (goal) {
goal.emit("status", feedbackMessage.status);
Expand All @@ -144,7 +144,7 @@ export default class ActionClient<

// subscribe to the result topic
if (!this.omitResult) {
this.resultListener.subscribe((resultMessage) => {
this.#resultListener.subscribe((resultMessage) => {
const goal = this.goals[resultMessage.status.goal_id.id];

if (goal) {
Expand All @@ -166,24 +166,31 @@ export default class ActionClient<
/**
* Cancel all goals associated with this ActionClient.
*/
cancel() {
const cancelMessage = {};
this.cancelTopic.publish(cancelMessage);
cancel(id?: string) {
const cancelMessage = {
id,
};
this.#cancelTopic.publish(cancelMessage);
}

sendGoal(goal: { goal: TGoal; goal_id: actionlib_msgs.GoalID }) {
this.#goalTopic.publish(goal);
}

/**
* Unsubscribe and unadvertise all topics associated with this ActionClient.
*/
dispose() {
this.goalTopic.unadvertise();
this.cancelTopic.unadvertise();
this.#goalTopic.unadvertise();
this.#cancelTopic.unadvertise();
if (!this.omitStatus) {
this.statusListener.unsubscribe();
this.#statusListener.unsubscribe();
}
if (!this.omitFeedback) {
this.feedbackListener.unsubscribe();
this.#feedbackListener.unsubscribe();
}
if (!this.omitResult) {
this.resultListener.unsubscribe();
this.#resultListener.unsubscribe();
}
}
}
7 changes: 2 additions & 5 deletions src/actionlib/Goal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class Goal<
* @param [timeout] - A timeout length for the goal's result.
*/
send(timeout?: number) {
this.actionClient.goalTopic.publish(this.goalMessage);
this.actionClient.sendGoal(this.goalMessage);
if (timeout) {
setTimeout(() => {
if (!this.isFinished) {
Expand All @@ -94,9 +94,6 @@ export default class Goal<
* Cancel the current goal.
*/
cancel() {
const cancelMessage = {
id: this.goalID,
};
this.actionClient.cancelTopic.publish(cancelMessage);
this.actionClient.cancel(this.goalID);
}
}
Loading