<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Suave101</title>
    <description>The latest articles on Forem by Suave101 (@suave101).</description>
    <link>https://forem.com/suave101</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1004244%2Ff1a64abc-18cd-49c5-876b-1b276b796d50.png</url>
      <title>Forem: Suave101</title>
      <link>https://forem.com/suave101</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/suave101"/>
    <language>en</language>
    <item>
      <title>How to use NtCore with PyRobot for FRC?</title>
      <dc:creator>Suave101</dc:creator>
      <pubDate>Mon, 09 Jan 2023 02:07:26 +0000</pubDate>
      <link>https://forem.com/suave101/how-to-use-ntcore-with-pyrobot-for-frc-3ibf</link>
      <guid>https://forem.com/suave101/how-to-use-ntcore-with-pyrobot-for-frc-3ibf</guid>
      <description>&lt;p&gt;As of 1/8/2023 the PyRobot documentation page has not released the documentation for NtCore or NetworkTables version 4. Therefore, the techniques used here may change between versions of RobotPy. In this case, we are using the following specifications:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pyntcore==2023.1.1.0
wpilib==2023.1.1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The new NetworkTables 4.0 library implements a publisher and subscriber system where you have individual objects in your code that are read only or write only. Here is an example of publishing controller information to a network table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import wpilib, ntcore


class MyRobot(wpilib.TimedRobot):
    def robotInit(self):
        # Network Table Server Configuration
        self.networkTablesServer = ntcore.NetworkTableInstance.getDefault()

        # Starting the Network Tables Server
        self.networkTablesServer.startServer()

        # Create a Network Table named "Controller Data"
        self.controllerDataNetworkTable = self.networkTablesServer.getTable("ControllerData")

        # Create Double (64 bit float) publishable topic on Controller Data Network Table
        self.networkTableLeftY = self.controllerDataNetworkTable.getDoubleTopic("Left-Y").publish()
        self.networkTableRightY = self.controllerDataNetworkTable.getDoubleTopic("Right-Y").publish()

        # Controller Configuration
        self.controller = wpilib.XboxController(0)

    def robotPeriodic(self):
        # Periodically set the Network Table value to Y Values
        self.networkTableLeftY.set(self.controller.getLeftY())
        self.networkTableRightY.set(self.controller.getRightY())


if __name__ == "__main__":
    wpilib.run(MyRobot)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This shows the basic layout of a data publishing system but, what if we want to get user input? Then we would need to subscribe to a topic. Here is an example of user input changing our output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import wpilib, ntcore


class MyRobot(wpilib.TimedRobot):
    def robotInit(self):
        # Network Table Server Configuration
        self.networkTablesServer = ntcore.NetworkTableInstance.getDefault()

        # Starting the Network Tables Server
        self.networkTablesServer.startServer()

        # Create a Network Table named "Motor Data"
        self.controllerDataNetworkTable = self.networkTablesServer.getTable("Motor-Data")

        # Create Double (64 bit float) publishable topic on Controller Data Network Table
        self.networkTableLeftY = self.controllerDataNetworkTable.getDoubleTopic("Left-Motor-Percent").publish()
        self.networkTableRightY = self.controllerDataNetworkTable.getDoubleTopic("Right-Motor-Percent").publish()

        # Create Motor Performance Object
        self._motorPerformance = self.controllerDataNetworkTable.getDoubleTopic("Motor Percentage").publish()
        self._motorPerformance.set(50)

        # Get Double (64 bit float) topic and subscribe
        self.motorPerformance = self.controllerDataNetworkTable.getDoubleTopic("Motor Percentage").subscribe(50)

        # Controller Configuration
        self.controller = wpilib.XboxController(0)

    def robotPeriodic(self):
        # Periodically set the Network Table value to Y Values
        if self.motorPerformance.get() &amp;gt; 100:
            self.networkTableLeftY.set(self.controller.getLeftY())
            self.networkTableRightY.set(self.controller.getRightY())
        else:
            self.networkTableLeftY.set(self.controller.getLeftY() * (self.motorPerformance.get()/100))
            self.networkTableRightY.set(self.controller.getRightY() * (self.motorPerformance.get()/100))


if __name__ == "__main__":
    wpilib.run(MyRobot)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>watercooler</category>
      <category>learning</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
