Thingsquare Router-Node - contiki

I´m newbie with Thingsquare
I'm traying to create a IP64 Gateway with MB851 Board (STM32W108CC microprocessor)
I send and receive data (IPv6 Radio) using 2 MB851 Boards with Thingsquare udp-multicast example.
I modified mist-mb851 platform to include an enc28j60-arch.c file to implement the platform code of SPI functions that are called by the enc28j60 driver
I modified ip64-conf.h to include enc28j60 driver and fallback interface
include "ip64-eth-interface.h"
include "enc28j60-ip64-driver.h"
define IP64_CONF_UIP_FALLBACK_INTERFACE ip64_eth_interface
define IP64_CONF_INPUT ip64_eth_interface_input
define IP64_CONF_DHCP 1
define IP64_CONF_ETH_DRIVER enc28j60_ip64_driver
I modified Contiki/platform/mb851 to include STM32 PeripheralLibs to create the SPI driver
The enj28j60 driver is tested
I compile the Thingsquare Router-Node example but when initialize the DHCP process
ip64_init();--->ip64_ipv4_dhcp_init();--->ip64_dhcpc_request();--->handle_dhcp();--->send_discover();
Nothing happens
Debugging the code when tcpip_ipv6_output(); function is call to send the packet the function ip64_6to4(...); fails and i don´t know why
Best Regards

Related

DiagramBuilder: Cannot operate on ports of System plant until it has been registered using AddSystem

I have an issue working with DiagramBuilder and ManipulationStation classes.
It appears to me, that c++ API and the python bindings work differently in my case.
C++ API behaves as expected, while the python bindings result in the runtime error:
DiagramBuilder: Cannot operate on ports of System plant until it has been registered using AddSystem
How I use C++ API
In one of the ManipulationStation::Setup...() methods I inject a block of code, that adds an extra manipuland
const std::string sdf_path = FindResourceOrThrow("drake/examples/manipulation_station/models/bolt_n_nut.sdf");
RigidTransform<double> X_WC(RotationMatrix<double>::Identity(), Vector3d(0.0, -0.3, 0.1));
bolt_n_nut_ = internal::AddAndWeldModelFrom(sdf_path, "nut_and_bolt", lant_->world_frame(), "bolt", X_WC, plant_);
I inject another block of code into the method ManipulationStation::Finalize:
auto zero_torque = builder.template AddSystem<systems::ConstantVectorSource<double>>(Eigen::VectorXd::Zero(plant_->num_velocities(bolt_n_nut_)));
builder.Connect(zero_torque->get_output_port(), plant_->get_actuation_input_port(bolt_n_nut_));
With these changes, the simulation runs as expected.
How I use python bindings
plant = station.get_multibody_plant()
manipuland_path = get_manipuland_resource_path()
bolt_with_nut = Parser(plant=plant).AddModelFromFile(manipuland_path)
X_WC = RigidTransform(RotationMatrix.Identity(), [0.0, -0.3, 0.1])
plant.WeldFrames(plant.world_frame(), plant.GetFrameByName('bolt', bolt_with_nut), X_WC)
...
station.Finalize()
zero_torque = builder.AddSystem(ConstantValueSource(AbstractValue.Make([0.])))
builder.Connect(zero_torque.get_output_port(), plant.get_actuation_input_port(bolt_with_nut_model))
This triggers a RuntimeError with a message as above; The port, which causes this error is nut_and_bolt_actuation.
My vague understanding of the problem is the (in) visibility of nut_and_bolt System, due to having two distinct DiagramBuilders in a process: 1) a one is inside ManipulationStation 2) another is in the python code, that instantiates this ManipulationStation object.
Using ManipulationStation via python bindings is a preference for me, because that way I would've avoided depending on a custom build of drake library.
Thanks for your insight!
I agree with your assessment: you have two different DiagramBuilder objects here. This does not have anything to due with C++ or Python; the ManipulationStation is itself a Diagram (created using its own DiagramBuilder), and you have a second DiagramBuilder (in either c++ or python) that is connecting the ManipulationStation together with other elements. You are trying to connect a system that is in the external diagram to a port that is in the internal diagram, but is not exposed.
The solution would be to have the ManipulationStation diagram expose the extra nut and bolt actuation port so that you can connect to it from the second builder.
If you prefer Python, I've switched my course to using a completely python version of the manipulation station. I find this version is much easier to adapt to different student projects. (To be clear, the setup is in python, but at simulation time all of the elements are c++ and it doesn't call back to python; so the performance is almost identical.)

ROS - How do I publish a message and get the subscribed callback immediately

I have a ROS node that allows you to "publish" a data structure to it, to which it responds by publishing an output. The timestamp of what I published and what it publishes is matched.
Is there a mechanism for a blocking function where I send/publish and output, and it waits until I receive an output?
I think you need the ROS_Services (client/server) pattern instead of the publisher/subscriber.
Here is a simple example to do that in Python:
Client code snippet:
import rospy
from test_service.srv import MySrvFile
rospy.wait_for_service('a_topic')
try:
send_hi = rospy.ServiceProxy('a_topic', MySrvFile)
print('Client: Hi, do you hear me?')
resp = send_hi('Hi, do you hear me?')
print("Server: {}".format(resp.response))
except rospy.ServiceException, e:
print("Service call failed: %s"%e)
Server code snippet:
import rospy
from test_service.srv import MySrvFile, MySrvFileResponse
def callback_function(req):
print(req)
return MySrvFileResponse('Hello client, your message received.')
rospy.init_node('server')
rospy.Service('a_topic', MySrvFile, callback_function)
rospy.spin()
MySrvFile.srv
string request
---
string response
Server out:
request: "Hi, do you hear me?"
Client out:
Client: Hi, do you hear me?
Server: Hello client, your message received.
Learn more in ros-wiki
Project repo on GitHub.
[UPDATE]
If you are looking for fast communication, TCP-ROS communication is not your purpose because it is slower than a broker-less communicator like ZeroMQ (it has low latency and high throughput):
ROS-Service pattern equivalent in ZeroMQ is REQ/REP (client/server)
ROS publisher/subscriber pattern equivalent in ZeroMQ is PUB/SUB
ROS publisher/subscriber with waitformessage equivalent in ZeroMQ is PUSH/PULL
ZeroMQ is available in both Python and C++
Also, to transfer huge amounts of data (e.g. pointcloud), there is a mechanism in ROS called nodelet which is supported only in C++. This communication is based on shared memory on a machine instead of TCP-ROS socket.
What exactly is a nodelet?
Since you want to stick with publish/ subscribers, assuming from your comment, that services are to slow I would have a look at waitForMessage (Documentation).
And for an example on how to use it you can have a look at this ros answers question.
All you need to do is to publish your data and immediately call waitForMessage on the output topic and manually pass the received message to your "callback".
I hope this is what you were looking for.
To get this request/reply behaviour ROS has a mechanism called ROS service.
You can specify the input and output of your service in a service file similar to a ROS message definition. You can then call the service of a node with your input and the call will receive an output when the service is finished.
Here is a tutorial how to use this mechanism in python. If you prefer C++ there is also one, you should find it.

how to write driver for MX 6 and TJA1100 PHY?

I am working on new costume board based on (i. MX 6Solo6DualLite).and I use (TJA1100 100BASE-T1 PHY) for Automotive Ethernet..
please correct me if my questions don't make sense, or I am in the wrong way.
I want to write driver for this device.. and make sure that it works correctly.
1- I can make sure that the driver works properly in the U-boot step, Right? I mean no need to load Linux kernel, so I have just to add source code C driver in U-boot source code and compile it. I want to do this in U-boot step, so I can limit the numbers of files that initialise all peripheriques, and make it simple as possible since that U-boot can behave like (mini-Os)
2-I don't know how to write this driver (exactly..), so I am looking for the driver (source code) that initialise the Ethernet Controller in any other processor , and initialise another typeof ethernet phy, in order to get an idea and write a similar driver source code for I.MX6 and TJA1100,?
after this i think that i could maybe add some very basic file c For simple Protocol like ARP, for test purpose..
3- is this good idea writing driver code by inspiring from another driver code source?
4 - maybe, if you already have a driver for (i. MX 6Solo6DualLite and TJA1100 100BASE-T1 PHY) can you provide to me please... ?
for my second question i tried to extract from U-boot source code the C file that initialise Ethernet Controller in AM335x, and initialise LAN8710A phy,(in beaglebone black) in order to get an idea and write a similar driver source code but i couldn't found it .. i found network C file for protocol .... but that's disturp me i couldn't seperate them from the real C file that initialise ethernet controller and ethernent Phy .
http://www.denx.de/wiki/U-Boot/SourceCode
There is a driver published on the NXP forum:
https://community.nxp.com/thread/460767
It includes both some bare metal code that should be usable with U-Boot and a Linux driver.

Network Tables C++

I am quite new to C++ socket programming. Since I am in an FRC team, I need to communicate between my application and the Compact RIO via an interface known as "Network Tables". I need to communicate from my C++ vision application to our robot code in Java. How do I implement NetworkTables in regular C++?
So here is what I did in python but the concept is the same. The goal would be to move motors based on values (sensor data) from what you receive in your driver station? so, how do I accomplish this... data transfers will be done through network tables
first, initlize...
from networktables import NetworkTables
# As a client to connect to a robot
NetworkTables.initialize(server='roborio-XXX-frc.local')
creating the instance you will be able to access NetworkTables conections, configure settings, listeners and create table objects which is what is actually being used to send data
next,
sd = NetworkTables.getTable('SmartDashboard')
sd.putNumber('someNumber', 1234)
otherNumber = sd.getNumber('otherNumber')
Here, we're interacting with the SmartDashboard and calling two methods, to send and recieve values.
another example, from API docs
#!/usr/bin/env python3
#
# This is a NetworkTables server (eg, the robot or simulator side).
#
# On a real robot, you probably would create an instance of the
# wpilib.SmartDashboard object and use that instead -- but it's really
# just a passthru to the underlying NetworkTable object.
#
# When running, this will continue incrementing the value 'robotTime',
# and the value should be visible to networktables clients such as
# SmartDashboard. To view using the SmartDashboard, you can launch it
# like so:
#
# SmartDashboard.jar ip 127.0.0.1
#
import time
from networktables import NetworkTables
# To see messages from networktables, you must setup logging
import logging
logging.basicConfig(level=logging.DEBUG)
NetworkTables.initialize()
sd = NetworkTables.getTable("SmartDashboard")
i = 0
while True:
print("dsTime:", sd.getNumber("dsTime", -1))
sd.putNumber("robotTime", i)
time.sleep(1)
i += 1

how to use VxWorks etherOutputHookAdd

I'm stumped trying to get etherOutputHookAdd() to work. Its counterpart, etherInputHookAdd(), seems to work fine. The OS version in question is VxWorks 5.4 .
The hook code looks like so (the code I intend to actually run is more complicated, but this serves for an example.)
int anCounter;
STATUS etherHook(struct ifnet *pif, char *buf, int size)
{
anCounter += 1;
return FALSE;
}
I can hook up etherInputHookAdd from the vxworks shell like so
etherInputHookAdd etherHook,"fei",0
This returns 0 (STATUS OK), after which examination of the 'anCounter' variable will indicate activity as expected. However, no such luck with the output direction. I've tried both of these command lines
etherOutputHookAdd etherHook,"fei",0
etherOutputHookAdd etherHook
Both of these return OK, but the hook routine doesn't seem to be getting called at all. My best hypotheses are (1) I'm missing an initialization step, or calling it wrong, (2) the etherOutputHookAdd implementation is just a stub, (3) you just can't call it from the shell, or (4) maybe my nic driver implementation is buggy.
Any ideas that solve the central problem - how do I see what's being sent off my board - are welcome.
The following VxWorks network drivers support both the input-hook and output-hook routines:
if_cpm - Motorola MC68EN360 QUICC network interface driver
if_eex - Intel EtherExpress 16
if_ei - Intel 82596 ethernet driver
if_elc - SMC 8013WC Ethernet driver
if_elt - 3Com 3C509 Ethernet driver
if_ene - Novell/Eagle NE2000 network driver
if_fn - Fujitsu MB86960 NICE Ethernet driver
if_ln - Advanced Micro Devices Am7990 LANCE Ethernet driver
if_sm - shared memory backplane network interface driver
if_sn - National Semiconductor DP83932B SONIC Ethernet driver
if_ultra - SMC Elite Ultra Ethernet network interface driver
if_gn - generic MUX interface layer
The following drivers support only the input-hook routines:
if_nic - National Semiconductor SNIC Chip (for HKV30)
if_sl - Serial Line IP (SLIP) network interface driver
The following drivers support only the output-hook routines:
if_ulip - network interface driver for User Level IP (VxSim)
The following drivers do not support either the input-hook or output-hook routines:
if_loop - software loopback network interface driver
To those few who might stumble this way .. It was the horrible 'hypothesis 4'!
It turns out that in order for etherOutputHookAdd() to work correctly, it is incumbent on the NIC device driver writer to include a call to the function pointed to by etherOutputHookRtn. All etherOutputHookAdd() does is add your proffered packet handler to a list, so that when a NIC driver calls etherOutputHookRtn, you get a copy of what's being transmitted. Sadly, there are many drivers where for whatever reason, this was simply not done.
So in cases such as this one, there are only two courses of action.
find a patch for your driver, or patch it yourself
change tactics entirely, e.g., try using etherInputHookAdd() on the other side.
In case you migrate to a newer version (>6.x) of VxWorks , etherLib is no longer supported. Instead, one can use muxLib for a similar purpose.
Hook inbound traffic: Use muxBind with MUX_PROTO_PROMISC or MUX_PROTO_OUTPUT.
Hook outbound traffic: Use muxBind with MUX_PROTO_OUTPUT.
You should provide a callback routine in both cases.

Resources