Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added layout/static/imgs/pneumatics-subsystem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions pages/Coding/Raspberry Pi NetworkTables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Raspberry Pi NetworkTables

A Raspberry Pi is often used on a robot for onboard vision processing. In order to communicate the values that your vision algorithm detects back to your robot code, you can upload the values to NetworkTables and then read them from the robot code.

## WPILib Raspberry Pi OS

While most articles on the internet will tell you to use the WPILib OS for a Raspberry Pi, in my finding its best to avoid it. This is because WPILib disabled WiFi and pip installing because they didn't want there to accidentally be a WiFi connection left enabled on a robot that could interfere with other robots in a competition. However, being unable to pip install will mean that you have to manually upload your libraries through the website interface. In my testing, I ran into a bug that wouldn't let me unzip the tar.gz file that I uplaoded to the pi. This left me with having to download the libary, transfer the library to a flash drive, connect the drive to the pi, mount the drive, move the files, unzip the files, move the files to the python library directory, and even through all of this work we ran into version compatability errors that made it a colossal headache and waste of time. I strongly recommend to just use a stock Raspbian Desktop OS (The GUI will come in handy more than you think). This way you can pip install and not worry about library installation. All that you need to remember to do is setup crontab and disable WiFi (Just click the WiFi icon on the desktop and turn it off!).


### Setting Up Crontab

In order for your code to automatically run on startup, you will need to setup crontab to run the script whenever the pi boots up. To do this, first type
```python
crontab -e
```
You will then be prompted for the editor of your choice. For beginners, I would recommend nano, so type 1. Now, you should see a file at /tmp/crontab.jaPtgW/crontab with a bunch of comments. Go to the very bottom of the file and then type:
```python
@reboot python3 /home/pi/Desktop/script.py
```

replacing your path and filename accordingly.


## Python NetworkTables

```python
print("About to Connect to Network Tables")
team = 1477
ip = "10.14.77.2"
notified = False
condition = threading.Condition()

# notify as soon as connection is made
def connection_listener(connected, info):
with condition:
notified = False
condition.notify()

NetworkTables.initialize(server=ip)
NetworkTables.addConnectionListener(connection_listener, immediateNotify=True)
with condition:
if not notified:
condition.wait()

print("Connected to Network Tables")
ntinst = NetworkTablesInstance.getDefault()
tb = ntinst.getTable("cube_detection")
tb.getEntry("yawResidual").forceSetValue(1477)
```


## Java NetworkTables
To read a value:

```java
private NetworkTableInstance nTInstance = NetworkTableInstance.getDefault();
private NetworkTable nTTable = nTInstance.getTable("cube_table");
private Double entry = nTTable.getEntry("yawResidual").getDouble(9999);
```

To push a value:

```java
private NetworkTableInstance nTInstance = NetworkTableInstance.getDefault();
private NetworkTable nTTable = nTInstance.getTable("cube_table");
private Double entry = nTTable.getEntry("yawResidual").getDouble(9999);
entry.forceSetNumber(1234)
```
11 changes: 5 additions & 6 deletions pages/Vendor/Motor Controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

### What are PWM Motor Controllers?

Let’s say that you were to run a motor without any kind of motor controller, voltage setter, or anything, just simply plugged into a power supply. The motor would continuously speed up and up as it continued to get power and would not stay at a continuous, constant speed. This is obviously not ideal for many applications and robotics is no exception. Try and imagine an autonomous robot sequence where the robot has to drive forward at a certain speed, without a motor controller for the drive train the robot would speed up much too fast and likely crash into something hurting other people or itself.
Let’s say that you were to run a motor without any kind of motor controller, voltage setter, or anything, just simply plugged into a power supply. The motor would continuously speed up and up as it continued to get power and would not stay at a continuous, constant speed. Try and imagine an autonomous robot sequence where the robot has to drive forward at a certain speed, without a motor controller for the drive train the robot would speed up much too fast and likely crash into something hurting other people or itself.

Now you should be able to see that running a motor without any kind of controller would be very dangerous and that controllers are absolutely vital to the operation of the robot or any other motor-based appliance. But how exactly does a motor controller actually manage to keep a constant speed? The answer is pulse width modulation or PWM for short. The basic function of a PWM motor controller is to send small pulses of power to the motor to keep it going at a constant speed. Try and imagine turning on a switch for a motor and then quickly turning it off. The motor would have begun to speed up, and when you turned off the power, it would’ve begun to slow down. However, being able to perfectly control a motor through this means would be nearly impossible for a human, but because the motor controller is based on a computer, it is able to calculate the perfect length and strength of the pulses to keep the motor at a consistent speed. The pulses are not powerful or long enough to make the motor go too fast, nor are they too weak and short to make the motor underperform.
How exactly does a motor controller actually manage to keep a constant speed? The answer is pulse width modulation or PWM for short. The basic function of a PWM motor controller is to send small pulses of power to the motor to keep it going at a constant speed. It is similair to turning on a switch for a motor and then quickly turning it off. Being able to perfectly control a motor through this means would be nearly impossible for a human, but because the motor controller is based on a computer, it is able to calculate the perfect length and strength of the pulses to keep the motor at a consistent speed. The pulses are not powerful or long enough to make the motor go too fast, nor are they too weak and short to make the motor underperform.

### Differences between motor controllers

What are the differences between different motor controllers? There are a wide variety of motor controllers that are used in different scenarios for different purposes. Here at Texas Torque, the motor controllers that are most commonly used are VictorSPX, Talon SRX, and RevRobotics SparkMax. The main practical difference between the three is the price and the electrical wiring between the controllers. Victors, SparkMaxs and Talons can be linked by CAN meaning that each motor controller is daisy-chained making the electrical debugging a bit more complex. On the programming side, CAN motors need PIDs, and you can take advantage of the “.addFollower” command for your motors. On the other hand, you can chose to not utilize CAN and instead directly link each controller to the RoboRIO, meaning that each motor has to be set individually when controlling/setting the speed. This method does not require any kind of PID to be used.
What are the differences between different motor controllers? There are a wide variety of motor controllers that are used in different scenarios for different purposes. The motor controllers that are most commonly used are CTRE VictorSPX, VictorSP, and Talon SRX, and RevRobotics SparkMax. The main practical difference between the three is the price and the electrical wiring between the controllers. VictorSPXs are smaller and lighter than SPs and support CAN. SparkMax's, and Talons can also be linked by CAN and support encoders.

### Code

Here at Texas Torque, we utilize submodules to handle our vendordeps, so we can write out TorqueSparkMax to define a SparkMax, VictorSPX for VictorSPX's, and TalonSRX for TalonSRX's. To add a follower for a motor, simply rewrite the motor name on a new line with the .addFollower command afterwards with the motor that you wish to have be a follower in parenthesis. It is not neccesary to define the follower motor, it will automatically be done.
Here at Texas Torque, we utilize wrapper classes for motor controllers to handle our vendordeps, so we can write out TorqueSparkMax to define a SparkMax, VictorSPX for VictorSPX's, and TalonSRX for TalonSRX's. But for other teams you can define your controller object class with either a PWMSparkMax, CANSparkMax, or TalonSRX, VictorSP, or VictorSPX. Torques wrapper classes allows us to add a follower to a motor, so simply rewrite the motor name on a new line with the .addFollower command afterwards with the motor that you wish to have be a follower in parenthesis. It is not neccesary to define the follower motor, it will automatically be done.

```java
TorqueSparkMax leftDB1 = new TorqueSparkMax(Ports.LEFT_DB_1);
Expand All @@ -21,10 +21,9 @@ leftDB1.addFollower(Ports.LEFT_DB_2);

### Problems and Solutions

* Problem: The motor is moving strangely (Rolling after input is false, stuttering, etc.)
- Problem: The motor is moving strangely (Rolling after input is false, stuttering, etc.)
-Solution: Try to reconfigure the PID

## Credits

Initially written by [Omar Afzal](https://github.com/0mara) in October 2021

53 changes: 53 additions & 0 deletions pages/Vendor/Pneumatics and Solenoids.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Pneumatics and Solenoids

Pneumatics are pressurized air cylinders that are controlled by solenoids to either extend or retract. They are powered by compressors and can be used all over a robot to perform a variety of tasks. The difference between the two is that a double solenoid can be manually retracted from the extended position and also be set off, whereas a single solenoid will only be able to push out and when the solenoid is set to 0 it will retract.

## Programming

To program a pneumatic cylinder, you control the solenoid which controls the pneumatic device.

```java
import edu.wpi.first.wpilibj.Solenoid;

Solenoid solenoid = new Solenoid(PneumaticsModuleType.CTREPCM, Ports.SOLENOID);

if (controller.getSolenoidButton()) solenoid.set(true);
else solenoid.set(false);
```

```java
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.DoubleSolenoid.Value;

DoubleSolenoid doubleSolenoid = new DoubleSolenoid(PneumaticsModuleType.CTREPCM, Ports.DOUBLE_SOLENOID_OUT, Ports.DOUBLE_SOLENOID_IN);

if (controller.getSolenoidButton()) doubleSolenoid.set(Value.kForward);
else doubleSolenoid.set(Value.kReverse);
```

![SolenoidWiringDiagram](/static/imgs/pneumatics-subsystem.png)

## Wiring

To wire your pneumatics, you will first need to have a basic electronics setup including a PCM (Pneumatics Control Module). You can reference [this article](https://docs.wpilib.org/en/stable/docs/zero-to-robot/step-1/how-to-wire-a-robot.html). The PCM will be used to provide an output for the compressor, input for the pressure switch, and outputs for up to 8 solenoid channels (12V or 24V selectable). The PCM is connected to the roboRIO over the CAN bus and powered via 12V from the PDP. If there are not enough ports on the PCM for a robot, and additional one can be used.

### Compressor

The compressor can be wired from the Compressor Out port on the PCM and should use no higher than 18 gauge wire.

### Pressure Switch

The polarity of the terminals for the pressure switch are not important when connecting them to the input ports on the PCM. A pressure switch is required to compete in a FRC competition as it is what prevents a compressor from over compressing and causing a rupture.

### Solenoids

Each solenoid channel should be wired directly to a numbered pair of terminals on the PCM. A single acting solenoid will use one numbered terminal pair. A double acting solenoid will use two pairs. If your solenoid does not come with color coded wiring, check the datasheet to make sure to wire with the proper polarity.

### Solenoid Voltage Jumper

The PCM is capable of powering either 12V or 24V solenoids, but all solenoids connected to a single PCM must be the same voltage. The PCM ships with the jumper in the 12V position. To use 24V solenoids move the jumper from the left two pins to the right two pins. You may need to use a tool such as a small screwdriver, small pair of pliers, or a pair of tweezers to remove the jumper.

## Problems and solutions

- Problem: The solenoid light is turning on when the controller sends the signal, but the cylinder is not actuating.
Solution: Did you change the Voltage Jumper to the correct voltage?