Skip to content

Commit

Permalink
Each turtlebots sensor/actuator made as DEECo plugin. Bacause BeeClick
Browse files Browse the repository at this point in the history
is dependent on RosServices but may run independently on a bot. Until
now the RosServices instantiated also turtlebots sensors/actuators. Now
these are separate. ROS node for Bee Click was removed since now it was
redundant and ROS node for RosServices is the only ROS node used by
DEECo.
  • Loading branch information
Robot committed Jul 21, 2015
1 parent cfeae1d commit a745bcd
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*
* @author Dominik Skoda <skoda@d3s.mff.cuni.cz>
*/
public class BeeClickComm extends TopicSubscriber implements DEECoPlugin {
public class BeeClick extends TopicSubscriber {

/**
* The name of ROS service used for broadcasting.
Expand Down Expand Up @@ -67,7 +67,7 @@ private class BeeClickDevice extends Device {
* The ROS topic for packet receiving.
*/
private Subscriber<IEEE802154ReceivedPacket> packetReceiveTopic = null;

/**
* The maximum number of bytes that can be sent in a single
* transmission.
Expand All @@ -82,7 +82,7 @@ private class BeeClickDevice extends Device {

/**
* Provides the unique identifier of the device. The identifier is not v
* until the {@link BeeClickComm#init(DEECoContainer)} method is called.
* until the {@link BeeClick#init(DEECoContainer)} method is called.
*
* @return The unique identifier of the device.
*/
Expand Down Expand Up @@ -130,23 +130,27 @@ public void send(byte[] data, Address address) {
}

// Create new message
IEEE802154BroadcastPacketRequest request = beePacketService.newMessage();
IEEE802154BroadcastPacketRequest request = beePacketService
.newMessage();
// Fill the data into the message
request.setData(ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, data));
request.setData(ChannelBuffers.wrappedBuffer(
ByteOrder.LITTLE_ENDIAN, data));

// Send the message, don't wait for the result
beePacketService.call(request,
new ServiceResponseListener<IEEE802154BroadcastPacketResponse>() {
@Override
public void onSuccess(IEEE802154BroadcastPacketResponse arg0) {
Log.d("BeeClickDevice sucessfully sent data.");
}
beePacketService
.call(request,
new ServiceResponseListener<IEEE802154BroadcastPacketResponse>() {
@Override
public void onSuccess(
IEEE802154BroadcastPacketResponse arg0) {
Log.d("BeeClickDevice sucessfully sent data.");
}

@Override
public void onFailure(RemoteException arg0) {
Log.w("BeeClickDevice failed to send data.");
}
});
@Override
public void onFailure(RemoteException arg0) {
Log.w("BeeClickDevice failed to send data.");
}
});
}

/**
Expand All @@ -157,25 +161,30 @@ public void onFailure(RemoteException arg0) {
*/
public void subscribe(ConnectedNode connectedNode) {
// Subscribe packet received topic
packetReceiveTopic = connectedNode
.newSubscriber(BEE_RECEIVE_TOPIC, IEEE802154ReceivedPacket._TYPE);
packetReceiveTopic = connectedNode.newSubscriber(BEE_RECEIVE_TOPIC,
IEEE802154ReceivedPacket._TYPE);
packetReceiveTopic
.addMessageListener(new MessageListener<IEEE802154ReceivedPacket>() {
@Override
public void onNewMessage(IEEE802154ReceivedPacket message) {
public void onNewMessage(
IEEE802154ReceivedPacket message) {
// Inject new event into the timer
timer.interruptionEvent(new TimerEventListener() {
@Override
public void at(long time) {
// When the event is invoked process the
// received data
ChannelBuffer bufferData = message.getData();
ChannelBuffer bufferData = message
.getData();
byte[] backingArray = bufferData.array();
byte[] messageData = Arrays.copyOfRange(backingArray,
bufferData.arrayOffset(),
backingArray.length);
receive(messageData, new MANETBroadcastAddress(
String.format("%d", message.getSrcSAddr())));
byte[] messageData = Arrays.copyOfRange(
backingArray,
bufferData.arrayOffset(),
backingArray.length);
receive(messageData,
new MANETBroadcastAddress(String
.format("%d", message
.getSrcSAddr())));
}
}, "BeeClickComm_receive", null);
Log.d("BeeClickDevice received data.");
Expand All @@ -184,8 +193,8 @@ public void at(long time) {

// Subscribe packet sending service
try {
beePacketService = connectedNode.newServiceClient(BEE_SEND_SERVICE,
IEEE802154BroadcastPacket._TYPE);
beePacketService = connectedNode.newServiceClient(
BEE_SEND_SERVICE, IEEE802154BroadcastPacket._TYPE);
} catch (ServiceNotFoundException e) {
throw new RuntimeException(e);
}
Expand All @@ -198,26 +207,26 @@ public void at(long time) {
* The ROS node on which the DEECo node runs.
*/
public void unsubscribe(Node node) {
if(beePacketService != null){
if (beePacketService != null) {
beePacketService.shutdown();
}
if(packetReceiveTopic != null){
if (packetReceiveTopic != null) {
packetReceiveTopic.shutdown();
}
}
}

/**
* The {@link BeeClickDevice} associated with this {@link BeeClickComm}
* The {@link BeeClickDevice} associated with this {@link BeeClick}
* instance.
*/
public final BeeClickDevice beeClickDevice;

/**
* Initialize new {@link BeeClickComm} instance and associate new
* Initialize new {@link BeeClick} instance and associate new
* {@link BeeClickDevice} with it.
*/
public BeeClickComm() {
public BeeClick() {
beeClickDevice = new BeeClickDevice();
}

Expand All @@ -243,27 +252,32 @@ protected void subscribeDescendant(ConnectedNode connectedNode) {
void unsubscribe(Node node) {
beeClickDevice.unsubscribe(node);
}

/**
* A list of DEECo plugins the {@link BeeClickComm} depends on.
* A list of DEECo plugins the {@link BeeClick} depends on.
*
* @return a list of DEECo plugins the {@link BeeClickComm} depends on.
* @return a list of DEECo plugins the {@link BeeClick} depends on.
*/
@SuppressWarnings("unchecked")
@Override
public List<Class<? extends DEECoPlugin>> getDependencies() {
return Arrays.asList(new Class[] { Network.class, RosServices.class });
List<Class<? extends DEECoPlugin>> dependencies = super.getDependencies();
if (!dependencies.contains(Network.class)) {
dependencies.add(Network.class);
}
return dependencies;
}

/**
* Initialize the {@link BeeClickComm} DEECo plugin. Launch the ROS node
* Initialize the {@link BeeClick} DEECo plugin. Launch the ROS node
* that handles the Bee Click device.
*
* @param contained
* is the DEECo container of this DEECo node.
*/
@Override
public void init(DEECoContainer container) throws PluginInitFailedException {
super.init(container);

// Assign the device ID
beeClickDevice.container = container;

Expand All @@ -272,17 +286,5 @@ public void init(DEECoContainer container) throws PluginInitFailedException {
// Register BeeClickDevice
Layer1 l1 = container.getPluginInstance(Network.class).getL1();
l1.registerDevice(beeClickDevice);

// Subscribe to ROS
RosServices rosServices = container
.getPluginInstance(RosServices.class);
BeeClickNode beeClickNode = new BeeClickNode(this);
rosServices.rosExecute(beeClickNode);

// Wait defined time until subscribed
if (!rosServices.isInitialized(this)) {
throw new PluginInitFailedException(
"The BeeClickComm was not subscribed within defined timeout.");
}
}
}
105 changes: 0 additions & 105 deletions jdeeco-ros/src/cz/cuni/mff/d3s/jdeeco/ros/BeeClickNode.java

This file was deleted.

5 changes: 2 additions & 3 deletions jdeeco-ros/src/cz/cuni/mff/d3s/jdeeco/ros/Bumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ public class Bumper extends TopicSubscriber {
private BumperValue bumper;

/**
* Internal constructor enables the {@link RosServices} to be in the control
* of instantiating {@link Bumper}.
* Create a new instance of {@link Bumper}.
*/
Bumper() {
public Bumper() {
bumper = BumperValue.RELEASED;
}

Expand Down
5 changes: 2 additions & 3 deletions jdeeco-ros/src/cz/cuni/mff/d3s/jdeeco/ros/Buttons.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ public class Buttons extends TopicSubscriber {
private Map<ButtonID, ButtonState> buttonState;

/**
* Internal constructor enables the {@link RosServices} to be in the control
* of instantiating {@link Buttons}.
* Create a new instance of {@link Buttons}.
*/
Buttons(){
public Buttons(){
buttonState = new HashMap<>();
for (ButtonID button : ButtonID.values()) {
buttonState.put(button, ButtonState.RELEASED);
Expand Down
5 changes: 2 additions & 3 deletions jdeeco-ros/src/cz/cuni/mff/d3s/jdeeco/ros/DockIR.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ public class DockIR extends TopicSubscriber {
private Map<DockingIRDiod, DockingIRSignal> dockingIRSignal;

/**
* Internal constructor enables the {@link RosServices} to be in the control
* of instantiating {@link DockIR}.
* Create a new instance of {@link DockIR}.
*/
DockIR() {
public DockIR() {
dockingIRSignal = new HashMap<>();
for (DockingIRDiod diod : DockingIRDiod.values()) {
dockingIRSignal.put(diod, DockingIRSignal.INFINITY);
Expand Down
5 changes: 2 additions & 3 deletions jdeeco-ros/src/cz/cuni/mff/d3s/jdeeco/ros/FloorDistance.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ public class FloorDistance extends TopicSubscriber {
private Map<FloorSensorID, Short> floorDistances;

/**
* Internal constructor enables the {@link RosServices} to be in the control
* of instantiating {@link FloorDistance}.
* Create a new instance of {@link FloorDistance}.
*/
FloorDistance() {
public FloorDistance() {
floorSensorStates = new HashMap<>();
floorDistances = new HashMap<>();
for (FloorSensorID sensor : FloorSensorID.values()) {
Expand Down
5 changes: 2 additions & 3 deletions jdeeco-ros/src/cz/cuni/mff/d3s/jdeeco/ros/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ public class Info extends TopicSubscriber {
private String softwareInfo;

/**
* Internal constructor enables the {@link RosServices} to be in the control
* of instantiating {@link Info}.
* Create a new instance of {@link Info}.
*/
Info() {
public Info() {
firmwareInfo = "";
hardwareInfo = "";
softwareInfo = "";
Expand Down
5 changes: 2 additions & 3 deletions jdeeco-ros/src/cz/cuni/mff/d3s/jdeeco/ros/LEDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public class LEDs extends TopicSubscriber {
private Map<LedID, Publisher<Led>> ledTopics;

/**
* Internal constructor enables the {@link RosServices} to be in the control
* of instantiating {@link LEDs}.
* Create a new instance of {@link LEDs}.
*/
LEDs(){
public LEDs(){
ledColor = new HashMap<>();
ledTopics = new HashMap<>();
}
Expand Down
Loading

0 comments on commit a745bcd

Please sign in to comment.