Code Monkey home page Code Monkey logo

ftc_5421_2014-2015's Introduction

RM'd and Dangerous: FTC '14-'15

This repository contains the code for the RM'd and Dangerous (FTC #5421) 2014-2015 robot.


Checklist for debugging

  1. Check if robot is powered on.
  2. Check to see if you are compiling for PC emulator or Robot.
  3. Check battery levels.
  4. Check PID and motor configuration.
  5. Check for RobotC joystick misinterpretation.
  6. Check to see if the function you are debugging is being called.
  7. Check motor and servo configurations.

Special Thanks

To Frank for all of the mentoring help, and Jon for being the premier codemaster of RM Robotics. You both rock :)

Code was inspired partly by:


Useful Links

Debugging RobotC

RobotC v4 Help

Data Types in RobotC

NXT2Excel

Output Formatting in RobotC


Contact Information

You can contact our team at our email: rmrobots [at] gmail [dot] com.

ftc_5421_2014-2015's People

Contributors

jimmyli97 avatar thealchenmist avatar pmaldonado avatar stohan avatar

Stargazers

Andrew Mao avatar Bryan avatar  avatar Jonathan Damico avatar  avatar  avatar

Watchers

James Cloos avatar jxia avatar  avatar  avatar  avatar  avatar Simon Liu avatar  avatar  avatar Gregory avatar hedonium avatar  avatar kevin avatar

Forkers

maosef

ftc_5421_2014-2015's Issues

Add Accelertion Fxn

One issue we noticed is the robot being knocked off of course from start up jerking. Probable solution: accelerate and decelerate instead of jumping from speed values in autonomous.

Update Motor.h and Joystick.h to enforce hierarchy

Hierarchy:
TeleOp.c -> Joystick.h
-> Motor.h
TeleOp should send its own motor state to Motor.h and Joystick.h. To enforce hierarchy, we need to make it so that calling Motor.h functions doesn't modify its state

Write basic motor.h

Should define functions and a motor enum to receive power and motorname commands.

Add robot tip test

The robot can quite easily tip were we to drive off of the cliff side of the ramp during autonomous, so we should check for this and stop before we tip completely. This would most likely require using the gyro

Add emergency reset

This will most likely have to be done in Joystick.h - when a certain button sequence is held down, a flag is set that breaks out of the while loop and resets everything, then waits for a certain amount of time. So it might look something like this:

while(true) {
  while(true) {
    updateJoystickSettings(joystick);
    joystickInterpret(joystick);
    if(reset) {
       break;
    }
    ....
  }
  killAllMotors();
  wait1Msec(2000);
}

The Great Refactoring

One other thing we talked about was simplifying organization. I'm planning on doing this, this weekend.

Develop autonomous strategy

We are going to need to decide a way to implement sensors to align the robot with the centerpiece, find the tubes on the ground and then find the center piece tube and how to deposit balls. We have considered to use touch sensors, sonar sensors, and the infrared sensors. The touch sensor to locate the center goal and to locate where the pole is. The sonar sensor to determine the angle of the center piece and the infrared sensor to detect the IR beacon to find the high tube.

Gyro/accel stabilization for auton

This should most likely be implemented as a task that constantly reads/writes current velocity, position, and rotation. Care should be taken with the structure storing data (e.g. use a semaphore)

See this link for sample implementation of rotational stabilization.

See this link for an example of how to integrate the values outputted in order to determine velocity and position.

This link probably has the most advanced code (I haven't looked at it yet)

Solve issue of encapsulation of looping through all motors

Currently the way we loop through all motors requires the assumption that the motor definitions are initialized. This means that we have to include the code guard if(motorDefsInitialized), which is very ugly.

We don't want to force code outside of motor.h to use motorDefsInitialized, so all code that loops through motors (such as encoder functions) must be placed in motor.h.

We currently have one function that breaks this rule, which is driveResetEncoders in Drive.h

We have to figure out some way of letting any code loop through all motors. In python we could do this with a generator but this isn't python.. :(

Including #pragma config

See if it is possible to include a .c file with all pragma configurations (makes it so that we only have to change them in one place).

It probably isn't possible (Xander says you should just put them in each .c file), but it's so annoying I sort of want to check :)

Suggestions include:
-Changing Motor.h into Motor.c. All motor assignments should only be done in Motor.h, so in theory the pragmas are only need there
-Creating a Setup.c that only has pragmas and then including that file

Rewrite Drive.h encoder fns to use the PolarMecDrive function calculations

The way we do the PolarMecDrive calculations makes it so that if we split off the calculations into a separate function, we can then feed that function either a maxSpeed of 100 or a maxSpeed of encoder value and it can spit out encoder values or speed values.

The calculation returns ratios to maxSpeed, so sending it an encoder value for maxSpeed will return the correct encoder ratio. This will make our code more consistent, and will also enable us to do arbitrary encoder fns for any speed, rotation, length.

Servo Definition

The servo isn't defining inside the servo.h. It doesn't seem to recognize that the servo was configured.

Redesign max power for PID control in Motor.h

Peter, I get what you were talking about with the 0-78 thing now :D

Previously, I thought that the old tetrix motors required you to set power to something less than 100 to let you effectively use PID control. Turns out that's wrong: you CAN set it to 100, but (here's what Peter was talking about) you can only set the new NeveRest motors to 78.

However what this means is that now we have to check if the tMotor we're assigning is a NeveRest or a normal tetrix motor, and then cap power respectively.

We'll probably have to do this using a similar technique to what I did with Servo.h - constructing an array of structs that maps each tMotor to its cap speed.

At this point, we should start thinking about whether we can code/get an implementation of a map in RobotC so we get faster lookup times for the motor, seeing as this will be called multiple times per second with each joystick update.

See 4251's helpful description of Tetrix vs. NeveRest.

Write a dynamic memory allocator

This will let us dynamically allocate variables so we can properly do stuff like get an array with variable size (instead of hardcoding arrays) .

This will probably consist of creating a byte array with some set size (nxt has 15k max for global variables), and then allocating it.

See this link for AVR's implementation of malloc.

We don't have to get that sophisticated - we could just keep a pointer to the last available memory space and just never free/realloc anything

Add some sort of encoder delay

Apparently (thanks again cougar robotics) this is a problem - sometimes the encoder will spit out an entirely wrong value and everything goes haywire. This will be tricky to solve because of the way our encoder code is written right now, as the function for limiting encoder values is not meant to have a delay as it's supposed to be called in a loop... but we can sacrifice that for this if necessary.

Add initialization library

This library should contain an initialize() function that is called by all autonomous/teleop programs.

This function should at the very least contain clearDebugStream(), and should also call all motor and servo initialization routines. This way we make sure we don't forget to initialize something that is important.

We can also write something to the debug stream, such as a diagnostic listing the current power level, at initialization after clearing the debug stream.

Shorten FCS timeout

Thank you Cougar Robotics :) This should be in JoystickDriver.c
nNoMessageCounterLimit = 150; //stop robot faster on disconnects (default is 750)

Simplify Math Fxn Names

Frank was talking to us today and told us to make simple functions have simple names, like Min, Max, Constrain, not anything super fancy that it hurts readability.

Controls "stick"

This could be possibly due to PID, but even if it is PID's fault we'll have to do something about it (such as write our own PID control...?)

Add a enum for motor names

Just so we can consistently refer to them - if names change (such as when Lisa makes us name them after the teenage mutant turtles)

Refactor drive power levels

Due to what Peter said about possibly having to replace two motors with non NeveRest motors and also in general, the DesiredMotorVals should always store power from 0 to 100, and only in Motor.h should that get modified

Add stall protection

This would involve checking to see if encoder is moving a significant amount, when power is above some certain level. If it isn't moving for a specified period of time, the motors should be turned off. If we want to disable braking as well (make it easier for another robot to push us), they should be set to float speed.

Float speed for HT DC motors (where braking is disabled) is -128 (see this link).

See this link for an example implementation - search for "DriveTask" function.

Add a low power level warning

Should probably be some sort of sequence of sounds (maybe it can spell out EXPLODING in morse code)

This would make sure that we always use a battery at a power level strong enough to last 3 minutes.

Debug protocol

What do you guys think of the following debug standard?

  • In initialize() of each file, clearDebugStream() must be called and then the name of the currently running program must be logged using writeDebugStream()
  • All error codes/errors that are not expected must be logged using writeDebugStream()
  • NO VARIABLES should be logged through writeDebugStream(). Instead, set variable allocation to Global Variables (View -> Preferences -> Global/Local Variable Settings, and then run the debugger to view variable contents. Remember to change it back!
  • No usage of nxtDisplayString (unless as part of a GUI, like program chooser) is allowed for debugging
  • For compilation at competition, RobotC should be set to compile for Best Realtime Performance (View -> Preferences -> Compiler Code Optimization.

Add parameter guards

Especially in JoyMecanumDrive, would help a great deal with fixing bugs by outputting messages to debugStream/datalog

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.