本文整理汇总了Java中org.ros.node.topic.Publisher类的典型用法代码示例。如果您正苦于以下问题:Java Publisher类的具体用法?Java Publisher怎么用?Java Publisher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Publisher类属于org.ros.node.topic包,在下文中一共展示了Publisher类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onStart
import org.ros.node.topic.Publisher; //导入依赖的package包/类
@Override
public synchronized void onStart(final ConnectedNode connectedNode) {
m_node = connectedNode;
m_cmdPublisher = connectedNode.newPublisher("command", CommandStamped._TYPE);
m_cmdPublisher.addListener(new DefaultPublisherListener<CommandStamped>() {
@Override
public void onNewSubscriber(Publisher<CommandStamped> publisher, SubscriberIdentifier subscriberIdentifier) {
while (!m_queue.isEmpty()) {
CommandStamped cmd = m_queue.poll();
publisher.publish(cmd);
}
synchronized(RobotNodeMain.this) {
m_ready = true;
}
}
});
Subscriber<AckStamped> subscriber = connectedNode.newSubscriber("mgt/ack", AckStamped._TYPE);
subscriber.addMessageListener(this);
Subscriber<EkfState> ekfSub = connectedNode.newSubscriber("gnc/ekf", EkfState._TYPE);
ekfSub.addMessageListener(new MessageListener<EkfState>() {
@Override
public void onNewMessage(final EkfState ekfState) {
synchronized(m_kinematics_lock) {
m_kinematics = new DefaultKinematics(ekfState);
}
}
});
}
示例2: onStart
import org.ros.node.topic.Publisher; //导入依赖的package包/类
@Override
public void onStart(final ConnectedNode connectedNode) {
// This CancellableLoop will be canceled automatically when the node shuts
// down.
final Publisher<Message> publisher = connectedNode.newPublisher(nodeName, publishType);
connectedNode.executeCancellableLoop(new CancellableLoop() {
@Override
protected void loop() throws InterruptedException {
semaphore.acquire();
publishMe.ifPresent(publishAction -> {
final Message message = publisher.newMessage();
publishAction.convert(message, connectedNode.getTopicMessageFactory());
publisher.publish(message);
});
}
});
}
示例3: onStart
import org.ros.node.topic.Publisher; //导入依赖的package包/类
@Override
public void onStart(ConnectedNode connectedNode) {
final Publisher<std_msgs.String> publisher = connectedNode.newPublisher(GraphName.of("time"), std_msgs.String._TYPE);
final CancellableLoop loop = new CancellableLoop() {
@Override
protected void loop() throws InterruptedException {
// retrieve current system time
String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
Log.i(TAG, "publishing the current time: " + time);
// create and publish a simple string message
std_msgs.String str = publisher.newMessage();
str.setData("The current time is: " + time);
publisher.publish(str);
// go to sleep for one second
Thread.sleep(1000);
}
};
connectedNode.executeCancellableLoop(loop);
}
示例4: onStart
import org.ros.node.topic.Publisher; //导入依赖的package包/类
@Override
public void onStart(ConnectedNode connectedNode) {
final Publisher<DiagnosticArray> batteryPublisher = connectedNode.newPublisher(TOPIC_NAME, DiagnosticArray._TYPE);
final DiagnosticArray diagnosticArray = batteryPublisher.newMessage();
final DiagnosticStatus deviceBattery = mMessageFactory.newFromType(DiagnosticStatus._TYPE);
deviceBattery.setName("/Power System/Laptop Battery");
KeyValue deviceKeyValueCapacity = mMessageFactory.newFromType(KeyValue._TYPE);
deviceKeyValueCapacity.setKey("Capacity (Ah)");
deviceKeyValueCapacity.setValue("100.0");
final KeyValue deviceKeyValueCharge = mMessageFactory.newFromType(KeyValue._TYPE);
deviceKeyValueCharge.setKey("Charge (Ah)");
deviceBattery.setValues(Arrays.asList(deviceKeyValueCapacity, deviceKeyValueCharge));
diagnosticArray.setStatus(Arrays.asList(deviceBattery));
connectedNode.executeCancellableLoop(new CancellableLoop() {
@Override
protected void loop() throws InterruptedException {
diagnosticArray.getHeader().setStamp(Time.fromMillis(System.currentTimeMillis()));
double deviceBatteryPercentage = mBatteryLevel.get();
if (deviceBatteryPercentage > 0) {
deviceKeyValueCharge.setValue(Double.toString(deviceBatteryPercentage));
}
batteryPublisher.publish(diagnosticArray);
Thread.sleep(1000);
}
});
}
示例5: onStart
import org.ros.node.topic.Publisher; //导入依赖的package包/类
@Override
public void onStart(ConnectedNode connectedNode) {
final Publisher<DiagnosticArray> batteryPublisher = connectedNode.newPublisher(TOPIC_NAME, DiagnosticArray._TYPE);
final DiagnosticArray diagnosticArray = batteryPublisher.newMessage();
final DiagnosticStatus robotBattery = mMessageFactory.newFromType(DiagnosticStatus._TYPE);
robotBattery.setName("/Power System/Battery");
final KeyValue robotKeyValueCapacity = mMessageFactory.newFromType(KeyValue._TYPE);
robotKeyValueCapacity.setKey("Capacity (Ah)");
robotKeyValueCapacity.setValue("100.0");
final KeyValue robotKeyValueCharge = mMessageFactory.newFromType(KeyValue._TYPE);
robotKeyValueCharge.setKey("Charge (Ah)");
robotBattery.setValues(Arrays.asList(robotKeyValueCapacity, robotKeyValueCharge));
diagnosticArray.setStatus(Arrays.asList(robotBattery));
connectedNode.executeCancellableLoop(new CancellableLoop() {
@Override
protected void loop() throws InterruptedException {
diagnosticArray.getHeader().setStamp(Time.fromMillis(System.currentTimeMillis()));
double baseBatteryVoltage = UnsignedBytes.toInt(mBaseDevice.getBaseStatus().getBattery()) * 0.1;
double baseBatteryPercentage =
(baseBatteryVoltage - BASE_MIN_VOLTAGE) /
(BASE_MAX_VOLTAGE - BASE_MIN_VOLTAGE) * 100.0;
robotKeyValueCharge.setValue(Double.toString(baseBatteryPercentage));
batteryPublisher.publish(diagnosticArray);
Thread.sleep(1000);
}
});
}
示例6: onStart
import org.ros.node.topic.Publisher; //导入依赖的package包/类
@Override
public void onStart(ConnectedNode connectedNode) {
Publisher<std_msgs.String> publisher = connectedNode.newPublisher(
getDefaultNodeName().join("out"),
std_msgs.String._TYPE);
mPublisher = publisher;
Subscriber<std_msgs.String> subscriber = connectedNode.newSubscriber(
getDefaultNodeName().join("in"),
std_msgs.String._TYPE);
subscriber.addMessageListener(this);
}
示例7: onStart
import org.ros.node.topic.Publisher; //导入依赖的package包/类
@Override
public void onStart(ConnectedNode connectedNode) {
Publisher<ff_msgs.CommandStamped> publisher = connectedNode.newPublisher(
"command", ff_msgs.CommandStamped._TYPE);
mPublisher = publisher;
Subscriber<AckStamped> subscriber = connectedNode.newSubscriber(
"mgt/ack", ff_msgs.AckStamped._TYPE);
subscriber.addMessageListener(this);
mNodeConfig = NodeConfiguration.newPrivate();
mMsgFac = mNodeConfig.getTopicMessageFactory();
}
示例8: onStart
import org.ros.node.topic.Publisher; //导入依赖的package包/类
@Override
public void onStart(ConnectedNode connectedNode) {
Publisher<ff_msgs.CommandStamped> publisher = connectedNode.newPublisher(
"command", ff_msgs.CommandStamped._TYPE);
mPublisher = publisher;
Subscriber<ff_msgs.AckStamped> subscriber = connectedNode.newSubscriber(
"mgt/ack", ff_msgs.AckStamped._TYPE);
subscriber.addMessageListener(this);
mNodeConfig = NodeConfiguration.newPrivate();
mMsgFac = mNodeConfig.getTopicMessageFactory();
}
示例9: onStart
import org.ros.node.topic.Publisher; //导入依赖的package包/类
@Override
public void onStart(ConnectedNode connectedNode) {
Log.i(TAG, "onStart: starting...");
if (mShutdownFuture != null) {
mShutdownFuture.cancel(false);
}
Publisher<sensor_msgs.PointCloud2> publisher =
connectedNode.newPublisher(getDefaultNodeName().join("image"),
sensor_msgs.PointCloud2._TYPE);
publisher.setLatchMode(false);
mPublisher = publisher;
mConnectedNode = connectedNode;
// Pre-fill a message
mCloud = publisher.newMessage();
mCloud.setIsDense(false);
mCloud.setIsBigendian(ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN);
mCloud.getHeader().setFrameId("perch_image_link");
MessageFactory mf = connectedNode.getTopicMessageFactory();
// Fill in the fields
int offset = 0;
for (final String name : Arrays.asList("x", "y", "z")){
final PointField pf = mf.newFromType(PointField._TYPE);
pf.setName(name);
pf.setCount(1);
pf.setOffset(offset);
pf.setDatatype(PointField.FLOAT32);
mCloud.getFields().add(pf);
offset += 4;
}
mCloud.setPointStep(offset);
}
示例10: onStart
import org.ros.node.topic.Publisher; //导入依赖的package包/类
@Override
public void onStart(ConnectedNode connectedNode) {
try {
Publisher<geometry_msgs.PoseStamped> publisher =
connectedNode.newPublisher("android/orientation", "geometry_msgs/PoseStamped");
orientationListener = new OrientationListener(publisher);
Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
// 10 Hz
sensorManager.registerListener(orientationListener, sensor, 500000);
} catch (Exception e) {
connectedNode.getLog().fatal(e);
}
}
示例11: onStart
import org.ros.node.topic.Publisher; //导入依赖的package包/类
@Override
public void onStart(ConnectedNode connectedNode) {
try {
Publisher<geometry_msgs.PoseStamped> publisher =
connectedNode.newPublisher("android/orientation", "geometry_msgs/PoseStamped");
orientationListener = new OrientationListener(publisher);
Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR);
// 10 Hz
sensorManager.registerListener(orientationListener, sensor, 500000);
} catch (Exception e) {
connectedNode.getLog().fatal(e);
}
}
示例12: onStart
import org.ros.node.topic.Publisher; //导入依赖的package包/类
@Override
public void onStart(ConnectedNode connectedNode) {
Subscriber<ff_msgs.CommandStamped> subscriber = connectedNode.newSubscriber(
getDefaultNodeName().join("command"), ff_msgs.CommandStamped._TYPE);
subscriber.addMessageListener(new MessageListener<ff_msgs.CommandStamped>() {
private static final String TAG = "Subscriber<Command>";
@Override
public void onNewMessage(final ff_msgs.CommandStamped cmd) {
Log.i(TAG, "I received a command");
if (!cmd.getCmdName().equals("set_color")) {
Log.e(TAG, "wrong command name");
return;
}
final List<ff_msgs.CommandArg> args = cmd.getArgs();
if (args.size() != 3) {
Log.e(TAG, "wrong number of args");
return;
}
final ff_msgs.CommandArg red = args.get(0);
final ff_msgs.CommandArg green = args.get(1);
final ff_msgs.CommandArg blue = args.get(2);
if (red.getDataType() != CommandArg.DATA_TYPE_INT ||
blue.getDataType() != CommandArg.DATA_TYPE_INT ||
green.getDataType() != CommandArg.DATA_TYPE_INT) {
Log.e(TAG, "args not integers");
return;
}
mMainHandler.post(new Runnable() {
@Override
public void run() {
mRed.setValue(red.getI());
mGreen.setValue(green.getI());
mBlue.setValue(blue.getI());
onColorChanged();
}
});
}
});
Publisher<std_msgs.ColorRGBA> publisher = connectedNode.newPublisher(
getDefaultNodeName().join("color"),
std_msgs.ColorRGBA._TYPE);
publisher.setLatchMode(true);
synchronized(mPublisherLock) {
mColorPublisher = publisher;
}
}
示例13: OrientationListener
import org.ros.node.topic.Publisher; //导入依赖的package包/类
private OrientationListener(Publisher<geometry_msgs.PoseStamped> publisher) {
this.publisher = publisher;
}