Skip to content

Instantly share code, notes, and snippets.

View yabberyabber's full-sized avatar
🐐

Andrew Nelson yabberyabber

🐐
  • Arista Networks
  • San Luis Obispo, California
  • 00:47 (UTC -07:00)
View GitHub Profile
import enchant
d = enchant.Dict("en_US")
num_mappings = {
1: [],
2: ['a', 'b', 'c'],
3: ['d', 'e', 'f'],
4: ['g', 'h', 'i'],
5: ['j', 'k', 'l'],
# These are the people who are invited to my wedding
GUESTS = [
"Linda",
"Paige",
"Lauren",
"Melissa",
"Ragnor",
"Thor",
"Gertrude",
"Yoshi",
#include <stdio.h>
#include <cmath>
struct TalonPIDConfig {
float p = 0.0;
float i = 0.0;
float d = 0.0;
float f = 0.0;
};
def calculate_percentile(sample, samples):
"""
|samples| is a list that contains |sample|
Return what percentile |sample| is in |samples|
"""
samples = sorted(samples)
position = samples.find(sample)
return position / len(samples)
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#pragma new_rule restrict preemptive .* nonreentrant
int printf(const char *formststr, ...) TAG(nonreentrant);
void sig_handler(int signo) TAG(preemptive) {
printf("Received signal %d\n", signo);
MyClass::MyClass(int argument)
: m_memberVariableA("apples")
, m_memberVariableB(15)
{
printf("I'm a constructor and I do stuff\n");
}
@yabberyabber
yabberyabber / monitorable.cpp
Created September 22, 2017 23:07
Easy live monitoring using zeromq and matplotlib
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <zhelpers.h> /* https://github.com/booksbyus/zguide/blob/master/examples/C/zhelpers.h */
int main() {
void *context = zmq_ctx_new();
void *publisher = zmq_socket(context, ZMQ_PUB);
int rc = zmq_bind(publisher, "tcp://*:5556");
assert(rc == 0);
@yabberyabber
yabberyabber / a_execute.sh
Last active June 6, 2017 04:09
Python macros. Transform some valid python code into other valid python code using a set of user-defined transformations.
./e_apply_macros.py b_example_macros.py c_input_file.py > d_output_file.py

Foldback Current Limit for CANTalon

The Algorithm

The CanTalon library provides one method for limiting current limiting: SetCurrentLimit. It kind of sucks. Meh

We need a more advanced method of Current limiting. Specifically, we need a temporary peak current limit that will fold back to a lower, safe, current limit when the motors are under heavy use.

There shall be 4 configurable parameters:

  • Peak current limit (the highest allowable current under any circumstances)
/**
* The following preprocessor form allows one to wrap C functions
*/
#define-func-decorator <any> critical_region(args, func)
{
bool enable_interrupts = false;
if (are_interrupts_enabled()) {
DISABLE_INTERRUPTS();
enable_interrupts = true;