Giter VIP home page Giter VIP logo

pyntcore's Introduction

RobotPy: Python for FRC cRIO Robot Controller

Author: Peter Johnson, FRC Team 294
Author: Dustin Spicuzza, FRC Team 2423/1418
Copyright: Copyright © 2010, Peter Johnson, Ross Light, Dustin Spicuzza

About RobotPy

RobotPy is a distribution of Python intended to be used for the FIRST Robotics Competition. Teams can use this to write their robot code in Python, a powerful dynamic programming language.

Features

  • Python is simple to learn and easy to maintain.
  • RobotPy lets you reload code without restarting.
  • RobotPy provides access to the WPILib class library.
  • You don't need to use WindRiver (unless you're rebuilding RobotPy itself).

Installation for most people

Download the binary releases from our FIRSTForge site, unpack them, and run install.py. Download from: http://firstforge.wpi.edu/sf/projects/robotpy

Installation from Source using our build VM

Using the provided build virtual machine is the easiest way to build RobotPy from source. See build-vm/README.txt for instructions.

Installation from Source (Advanced Users Only)

Step 1: Install Python

Python 2.7.5 is known to work. Ensure that you add your python installation directory to your PATH variable.

Note: This step is required for SIP installation

Step 2: Install SIP v4.15.3:

The cmake build process currently checks for exact versions of SIP, as the generated code changes from release to release.

http://www.riverbankcomputing.com/static/Docs/sip4/installation.html

Note: Installation of SIP on Windows requires Visual Studio or MinGW installed, see the SIP build instructions for more details.

Step 3: Build the source tree

TODO: Update these instructions for Windows too?

The RobotPy build process uses cmake to build the RobotPy distribution. frcmake is a wrapper around cmake that sets the build environment up to build for the cRio.

RobotPy currently uses the GCC 4.8 compiler distributed at the following URL to build the binary distribution. Wind River may be used, but we haven't built it with Wind River, so you may run into trouble using it with frcmake.

http://firstforge.wpi.edu/sf/projects/c--11_toochain

Create a directory (the 'binary directory') outside of the RobotPy source tree, and run this:

$ frcmake /path/to/robotpy

Once you've done this, you can build the code:

$ make

To copy the build output to the 'dist' directory, run this command from your binary directory:

$ make install

To build a binary release, just run the following command and a zip file will be created in your build directory.

$ make package

Step 4: Robot Installation

From the 'dist' directory inside of your binary directory, run install.py

Alternatively, you can FTP the contents of the 'robot' directory to your cRio directly. However, install.py is easier.

Development tools

See the utilities directory for useful development tools that may make your RobotPy development experience easier.

The pyfrc python package is a recommended development package that provides unit testing and other capabilities for your robot code.

https://github.com/robotpy/pyfrc

Technical Overview

RobotPy is a packaging of a patched Python 3.2 interpreter (found in the RobotPy/Python subdirectory of the source code). All access to the WPILib is generated by a SIP interface, which is found in Packages/wpilib/sip/. When the robot is started, it initializes the Python interpreter and runs the file py/boot.py. From there, all responsibility is given to the boot.py script, which is referred to as the bootloader.

If boot.py ever exits (due to an exception, for example), the C++ code exits. The default boot.py simply exits on any user exception. If this happens, you can reboot easily via NetConsole by simply typing "reboot" followed by hitting the enter key. This is how code reloads are performed. As boot.py is written in Python, this behavior can be customized as desired.

Major Differences from standard Python

  • Several Python modules with large and/or incompatible dependencies removed, namely: curses, dbm, gdbm, tkinter, nis, ossaudiodev, resource, spwd, syslog, termios, audioop, bz2, crypt, grp, ssl, pwd, and mmap.

Licensing

A brief overview of licensing terms:

If you redistribute RobotPy and add other libraries, please include their licensing information here.

RobotPy

Copyright © 2010 Peter Johnson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pyntcore's People

Contributors

archduketim avatar auscompgeek avatar thetriplev avatar virtuald avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyntcore's Issues

GetXXX defaults should accept any python object

Currently, they only allow you to pass in the same type, but pynetworktables will allow any python object.

I think these can be done via the low level NT api?

[](NetworkTable * nt, wpi::StringRef key, py::object defaultValue) -> py::object {
  auto entry = nt->GetEntry(key);
  auto value = GetEntryValue(entry.handle());
  if (!value->IsBoolean()) {
  return defaultValue;
  }
  return value->GetBoolean();
}

Of course, there's a lot of duplication we're doing here (this is exactly what NetworkTableEntry does)... maybe there's a way to override some of it?

[BUG]: MemoryError when publishing arrays

Problem description

When setting an array value (int[], float[], double[], boolean[], string[], or raw) using a publisher or entry a MemoryError: std::bad_alloc is thrown. This does not occur for other types. Only tested on Raspbian.

Operating System

Raspbian

Installed Python Packages

pyntcore          2023.2.1.1
robotpy-wpinet    2023.2.1.0
robotpy-wpiutil   2023.2.1.0

Reproducible example code

ntcore.NetworkTableInstance.getDefault().getDoubleArrayTopic("/Topic").publish().set([])

NetworkTableEntry.setValue should take the inner types

Probably the best way to fix this is for pybind11 to auto-cast bool/int/float/str/bytes to nt::Value, so that we fix this across the board. Bonus points for auto-converting sequences.

(This is currently breaking magicbot.tunable and magicbot.feedback.)

See also: #2

Integers stored as Booleans

from networktables import NetworkTables
table = NetworkTables.getGlobalTable()
table.putValue('float', 35.5)
print(table.getValue('float').value()) # Outputs 35.5
table.putValue('integer', 950)
print(table.getValue('integer').value()) # Outputs True
print(table.getValue('integer').isBoolean()) # Outputs True

It appears that putValue fails to recognize integer values.

Linux ARM support?

Would it be feasible to distribute Linux ARM64 builds of pyntcore (and dependencies) for use on coprocessors like Raspberry Pis? It appears that only x86 Linux wheels are available via PyPI, and while pynetworktables is still functional it obviously doesn't allow us to take advantage of the benefits of NT4.

setDefaultValue doesn't accept values

It appears that #13 was not applied to NetworkTable.setDefaultValue

Calling it with any value results in:

TypeError: setDefaultValue(): incompatible function arguments. The following argument types are supported:
    1. (self: _pyntcore._ntcore.NetworkTable, key: str, defaultValue: nt::Value) -> bool

Listener examples in pynetworktables docs fail to complie with pyntcore

The Listener example in the pynetworktables docs throw the following error when complied with pyntcore:

NetworkTables.addConnectionListener(connectionListener, immediateNotify=True)
TypeError: addConnectionListener(): incompatible function arguments. The following argument types are supported:
    1. (self: _pyntcore._ntcore.NetworkTablesInstance, callback: Callable[[_pyntcore._ntcore.ConnectionNotification], None], immediate_notify: bool) -> int

Invoked with: <_pyntcore._ntcore.NetworkTablesInstance object at 0x7f67138851b0>, <function connectionListener at 0x7f6713879e50>; kwargs: immediateNotify=True

GetValue requires defaultValue argument

Since the fix for #20, it appears that there is a new required defaultValue argument to NetworkTables.getValue. Calling it without a second argument results in:

TypeError: getValue(): incompatible function arguments. The following argument types are supported:
    1. (self: _pyntcore._ntcore.NetworkTable, key: str, value: object) -> object

This does not match previous behavior or the C++ call. Was that change intentional? Would it be possible for that function to return None if no default is given and no value is found in the network table for the given key?

[BUG]: segfault on exit when using addListener

Problem description

segfault on exit when using addListener. Need to delete the listeners before exit, or detach the python objects from the std::function object.

Operating System

Windows, MacOS, Linux, RoboRIO, Raspbian

Installed Python Packages

No response

Reproducible example code

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.