How to implement new node shapes - cytoscape

I am plotting a network in Cytoscape, and it would be convenient to add several node shapes that mimic the pch shapes in R so that my networks match all of my other figures for a publication.
Network layouts in R generally look bad, however I can format the nodes to be very similar to those in other plots. On the other hand, Cytoscape makes much better layouts however the node shapes and styles are limited.
Is it possible to implement additional shapes in Cytoscape (such as through a plugin), or alternatively, can I export a network layout from Cytoscape and use it in R? Thank you!

I solved this on my own. The answer was to use the "RCy3" R package. I made a layout of my network in Cytoscape, then connected to Cytoscape in R through RCy3. This package has the function getNodePosition which will return the node positions of the current network in Cytoscape.
The following code will get this layout (Cytoscape must be running and open to the desired network):
cytoscapePing()
mygraph<-createIgraphFromNetwork()
mylayout<-getNodePosition()
mylayout$x_location<-as.numeric(as.character(mylayout$x_location))
mylayout$y_location<-as.numeric(as.character(mylayout$y_location))
colnames(mylayout)<-c("x","y")
This can then be plotted using ggraph or other network plotting packages in R, with the R pch symbols as node shapes.

Related

How to map the generalized coordinate vector of the multi-body plant to the generalized coordinate vector of the rigid body tree in Drake?

A humanoid robot can be described by a kinematic tree in a URDF file. I found that the order of the elements in the generalized coordinate vectors of the rigid body tree and the multi-body plant are different. There is a code snippet online showing the way to achieve the mapping.
# q_rbt = X*q_mbp
# rigid_body_tree is an instance of RigidBodyTree()
# multi_body_plant is an instance of MultibodyPlant()
B_rbt = rigid_body_tree.B
B_mbp = multi_body_plant.MakeActuationMatrix()
X = np.dot(B_rbt[6:,:],B_mbp[6:,:].T)
However, RigidBodyTree has been deprecated in the new Drake. Hence, how can I achieve the mapping now? In addition, I am curious about why Drake does not use the same order for the generalized coordinate vectors.
You might like the workflow I used in this littledog example. I have a PR in flight to enable that workflow directly in Drake. You can track the progress on in with this issue.
In general the recommendation, and I would recommend this even if we hadn’t implemented it a particular way in Drake, is that if you have something as complicated as humanoid, don’t try to work with the vectors based on indices. Find a way to access the elements via their names, or in Drake via their joint accessors. Working with the raw vector is very error prone.

Best method to add generalized forces to Linearized (or LQR) MultiBodyPlant?

I'm trying to add generalized forces on a free-floating system that has been linearized from a MultiBodyPlant. For a fixed base, the generalized forces basically correspond to the joint torques but for a free-floating case, it includes the base torques/forces as well. However, these are not included in the actuation port of the MultiBodyPlant system and hence while providing the actuation port for linearization (or LQR), the base wrenches are not included in the actuation matrix B post-linearization. For my work, I'd like to include the base torques/forces as well in the linearization. For this, I can think of 2 approaches in drake but I'm not sure which would be a better/correct decision architecturally. I plan to use this later for making a TVLQR controller to stabilize trajectories.
Idea 1: Change B matrix in LQR after linearization: Manually edit B matrix after using LinearQuadraticRegulator(system, context, Q, R, plant_actuation_input_pot())
Idea 2: Create a LeafeSystem class (similar to this) with output port connecting to get_applied_generalized_force_input_port() and input port exposed outside diagram (using ExportOutput()) and then linearized this system as a whole (containing the CustomLeafSystem connected to MultiBodyPlant). I assume doing this will add the base actuation to the B matrix of the linearized system.
Actually these two ideas is what I would've done myself. For your case it'd seem that Idea 1 is simpler to implement?
Matrix B maps actuation indexes to generalized velocity indexes. Therefore you have to make sure that you place the necessary "ones" in the right places of B. You can find the free floating body indexes with Body::floating_velocities_start() which returns the start index within the full state x (therefore you'd need to subtract MultibodyPlant::num_positions() for indexing within B). For floating bodies generalized velocities are angular velocity w_WB and translational velocity v_WB, in that order. Therefore the generalized forces corresponds to the torque t_Bo_W and f_Bo_W applied at B about its origin Bo and expressed in the world frame.

Differential Drive robot simulation in Drake

I want to simulate a differential drive robot in drake. However, its not easy figuring out the closest tutorial to start as a reference.
In addition, can drake incorporate sensors like RFID or magnetometer. Any help will be appreciated.
I do have sdf file of my differential drive robot.
There is one example of PR2, which also has a differential drive (DD). This example models the DD as three fully actuated joints: prismatic x, prismatic y and revolute theta. Then you can build a constrained controller to control the basis. By constrained controller, I mean the target position of (x, y, theta) should satisfy the differential constraint.
I have an ongoing branch that tries to add some controllers to the PR2. It's raw but should be able to get you started.

drake: search for fixed points and trim points of a system

I have a LeafSystem in drake, with dynamics \dot{x} = f(x,u) written in DoCalcTimeDerivatives. The fixed points and trim points of this system are not trivial to find. Therefore, I image one would need to write a nonlinear optimization problem to find the fixed points:
find x, u;
s.t. f(x,u)=0
or
find x,u;
min f(x,u)^2
I am wondering, how should I take advantage of the dynamics that I have already written in DoCalcTimeDerivatives of the LeafSystem, and write a non-linear optimization to search over x and u to find the fixed points and trim points in drake? Some existing examples in drake would be greatly appreciated!
It's simple to write for your case (and only slightly harder to write for the general case... it's on my TODO list).
Assuming your plant supports symbolic, then looking at the trajectory optimization will give you a sense for how you might write the constraint:
https://github.com/RobotLocomotion/drake/blob/master/systems/trajectory_optimization/direct_transcription.cc#L212
(the autodiff version is just below):
fwiw, the general case from the old matlab version is here:
https://github.com/RobotLocomotion/drake/blob/last_sha_with_original_matlab/drake/matlab/solvers/FixedPointProgram.m

Is it impossible to monitor tensorflow weight tensor in IDE(Pycharm)?

I'm trying to learn various ways to monitor tensorflow weight tensor.
I know we can watch these variable tensors through Session.run(), tf.Print(), tf.py_func()and tools like tensorboard, tdb, tfdbg
(https://wookayin.github.io/tensorflow-talk-debugging/#1)
But is it impossible to use IDE(like Pycharm) for this?
I tried by myself, and couldn't find some places to set a breakpoint.
Please tell me if you succeed tensor debugging using IDE. Thank you!
I debug TF daily in Pycharm. I set breakpoints as usual in the left column of the editor next to the line numbers. You can also hover over the tensors (see the yellow tooltip) to see their shape and summarized contents.

Resources