chip updates: IMU and ROS fun [updates]
So today, in the interest of getting the annoying nonsense of communications finally out of the way. We want to setup the ROS framework for the CHIP robot and here's how it's going to work.
And here's the ROS framework. So basically, what happens is this, anything in a box is a NODE, anything text is either a peripheral device or a TOPIC.
step one: writing the communicator node
The communicator node or communications node is responsible for a few things. First, it is responsible for simply reading data and sending data to the RoboRIO. It reads data from Network Tables and publishes it to three ROS topics, FOOT_POSITIONS which is an array of arrays.
[FL: [X,Y,Z], FR: , BL, BR] --> this is the convention we will follow.
THETAS which is also an array of arrays.
[FL: [T1,T2,T3], FR: , BL, BR]
LEG_CURRENTS which is an array.
[FL: total_current, FR: , BL, BR]
Let's write that publisher part first.
Now note: https://answers.ros.org/question/234028/how-to-publish-a-2-dimensional-array-of-known-values/ we follow this to find out how to publish a 2D array. I'm not sure if we can access it the same way we think we can, so we need to try it. At the moment though, we have a ROS Node that publishes the following things...
FOOT_POSITIONS --> [FLx, Fly, FLz, Fox, FRy...]
THETAS --> [FLx, Fly, FLz, Fox, FRy...]
LEG_CURRENTS --> [FL, FR, BL, BR]
DEAFULT_VALUE --> publishes the value that any of the above return if they AREN'T getting data so the system is aware.
I think we'll just publish them as a 1X12 stream. That's ok, won't have to deal with multi array.
As we can see, things are publishing over the ROS network. Let's go through the code step-by-step.
This part of the code imports the necessary helper libraries, it initializes the network tables communicator to the roborio with the robot's IP address written there. It creates the tables we will be reading from and writing to, and it creates some global variables that we can use to generate messages in ROS. It also creates some constants.
read_rio() is a function that takes in the data from the roboRIO and populates the global variables with that data.
The write() functions takes in data in the form of arrays and basically populates the network table to write the values to the roboRIO.
The callback() function is called when a new message pops up in the ROS system. This callback function populates three arrays FL, FR, BL, BR, with the data from the vector sent through the ROS network. And then calls the write() function.
Now the last two functions, the publisher_subscriber() itself creates the publishers, initializes the node, reads data and publishes it, it also subscribes to and reads from the "SETPOINT" topic and executes the callback function, and it keeps repeating at 60Hz.
That's all for this node. I think we'll probably write one node a day because this is tedious.