ROBOTC.net Blog  

ROBOTC News

Archive for the ‘cortex’ tag

Programming the VEX Gyro in ROBOTC

with one comment

The new VEX Yaw Rate Gyro is one of the more sophisticated sensors in the VEX Robotics System – but it’s also one of the most useful and powerful. Among other things, the Gyro allows your robot to make very precise, consistent turns.

Other sensors, like the Shaft Encoders, allow you to control your robot’s turns… but indirectly. The Shaft Encoders can measure the rotation of the axles (or shafts) of your robot’s drive train. By monitoring how much the axles spin, you can also monitor and control how much your robot moves forward or turns. (As a side note, some great tutorials on using the Shaft Encoders to do just that can be found in the Movement section of the VEX Cortex Video Trainer.)

The Gyro, on the other hand, actually measures the rotation of your robot. Factors such as wheel slippage and varying surface friction that cause inconsistencies with Shaft Encoder-based turns are far less problematic with the Gyro; your robot will turn until it reaches the target you set – no matter how much the wheels slip or how long it takes!

There are a number of different ways that electronic Gyros work. The VEX Gyro includes a sensing element kept in continuous oscillation which reacts when angular rate is applied, based on the “Coriolis effect”. The Coriolis effect is a deflection of moving objects when they are viewed in a rotating reference frame. In a reference frame with clockwise rotation, the deflection is to the left of the motion of the object; in one with counter-clockwise rotation, the deflection is to the right. This effect is caused by the rotation of the Earth and the inertia of the mass experiencing the effect.

Thus, the Gyro is able to detect whether the robot is turning clockwise or counter-clockwise and provide different sensor values based on how much it’s been rotated. For a more thorough explanation of the Coriolis effect, visit this Wikipedia article. For more technical information on the on the internals of the VEX Gyro, you can check out its datasheet.For this tutorial, we mounted the VEX Gyro on our Swervebot robot model and connected it to Analog port 8 on the Cortex.

ROBOTC includes a number of sample programs for the Gyro. You can open the sample program below by going to File > Open Sample Program > Gyroscope > “Gyro Based Turns – Basic.c”.

A few additional notes about the Gyro and the program:
  • Typically all sensors are configured in ROBOTC using the Motors and Sensors Setup window. This can still be done with the Gyro, but lines 23-28 do so manually. The Gyro is an extremely sensitive sensor – it’s readings are affected by heat, fluctuations in voltage, and how long the sensor has been in use. These factors cause the sensor to accumulate an error, or drift, over time. By setting Analog Port 8 to “sensorNone” on line 24, all of the drift is wiped out from previous runs. The sensor is then reconfigured as a “sensorGyro” on line 27.
  • After the Gyro is configured on line 27, it’s very important that your robot is kept completely still for at least 1.1 seconds. During this time, ROBOTC and the Gyro perform a calibration process. The 2-second wait on line 28 is more than enough time for this process to occur.
  • There is a small amount of variance between each Gyro. ROBOTC has default values used for scaling the readings from the VEX Gyro into useful SensorValues, but you may need to make a slight adjustment for your sensor. The “SensorScale[]” command (commented out on line 31) allows you to do just that. If you find that your robot is turning too far or too little, un-comment line 31 and adjust the “260″ value as needed.
  • As the Gyro is turned, the values it returns are in tenths of degrees, positive and negative. Thus, a SensorValue of 3600 equals 360 degrees, or one full rotation. When the sensor is mounted horizontally, counter-clockwise movements will return values from 0 to -3600; clockwise movements will return values from 0 to 3600. Once the gyro completes one full revolution, the sensor value will “roll-over” to 0 by default (for example: …3597, 3598, 3599, 3600, 0, 1, 2, 3,…). To change the “roll-over” point, un-comment line 33 and change the value of “SensorFullCount” from 3600 to the desired value (7200, 18000, ect)
  • For a much more thorough explanation of the program, check out the tutorial video we produced, here.
#pragma config(Motor, port2, rightMotor, tmotorNormal, openLoop)
 #pragma config(Motor, port3, leftMotor, tmotorNormal, openLoop, reversed)
 //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/*+++++++++++++++++++++++++++++++++++++++++++++| Notes |++++++++++++++++++++++++++++++++++++++++++++
 Gyro Based Turns - Basic
 -This program instructs your robot to turn for the specified number of degrees in "degrees10".
 -For best sensor results, clear out the gyro and manually configure it at the begging of the code.
 -The Gyro is configured by default to provide values from 0 to -3600 for clockwise rotation,
 and 0 to 3600 for counter-clockwise rotation

Robot Model(s): Swervebot

[I/O Port] [Name] [Type] [Description]
 Motor Port 2 rightMotor VEX Motor Right side motor
 Motor Port 3 leftMotor VEX Motor Left side motor
 Analog Port 8 in8 VEX Gyro Top-center mounted,
 away from the Cortex
 --------------------------------------------------------------------------------------------------*/

task main()
 {
 //Completely clear out any previous sensor readings by setting the port to "sensorNone"
 SensorType[in8] = sensorNone;
 wait1Msec(1000);
 //Reconfigure Analog Port 8 as a Gyro sensor and allow time for ROBOTC to calibrate it
 SensorType[in8] = sensorGyro;
 wait1Msec(2000);

//Adjust SensorScale to correct the scaling for your gyro
 //SensorScale[in8] = 260;
 //Adjust SensorFullCount to set the "rollover" point. 3600 sets the rollover point to +/-3600
 //SensorFullCount[in8] = 3600;

//Specify the number of degrees for the robot to turn (1 degree = 10, or 900 = 90 degrees)
 int degrees10 = 900;

//While the absolute value of the gyro is less than the desired rotation...
 while(abs(SensorValue[in8]) < degrees10)
 {
 //...continue turning
 motor[rightMotor] = 25;
 motor[leftMotor] = -25;
 }

//Brief brake to stop some drift
 motor[rightMotor] = -5;
 motor[leftMotor] = 5;
 wait1Msec(250);
 }

Here’s a video of the robot moving, based on the code:

And again, just in case you missed it, a more detailed explanation of the program can be found in this tutorial video:

The VEX Gyro can be purchased from the RoboMatter store.

Written by Jesse Flot

October 13th, 2011 at 5:08 pm

Posted in Cortex,General News,VEX

Tagged with , , ,

Controlling the MINDS-i Lunar Rover with a VEX Cortex

with one comment

Article written by Steve Comer

Remote control cars are great for having fun. They can be driven off-road, taken off jumps, and raced among other things. VEX robots are great for learning. They can be used to teach programming, math, problem solving, and other engineering skills. What do you get if you put them together??

Well, I can tell you. You get a rugged 4WD truck that is still tons of fun to drive around outside, but can also be used as a teaching tool.

Follow this link for more photos: http://s1081.photobucket.com/albums/j353/comeste10/VEX%20Rover%20Extras/

I started off with a MINDS-i Lunar Rover kit which is driven by a 7.2V DC motor and steered with a standard hobby servo. I removed the solar panel from the Rover and in its place put a VEX Cortex microcontroller and an LCD screen. On each side, I attached a VEX flashlight from the VEXplorer kit and I mounted an ultrasonic sensor to the front. It just so happens that VEX bolts and nuts fit quite easily into the beams of the MINDS-i rover.

I did all the programming in RobotC. See bottom of the page to view my RobotC code.

In order to control the stock motor and servo with the Cortex, I had to make a few modifications. I soldered the two wires to a 2-pin head which I then connected to the Cortex with a VEX motor controller.

For the servo, I used three single male-to-male jumper cables.

The video demonstrates the rover in autonomous mode where it makes use of the ultrasonic sensor to avoid bumping into walls. Remote control is also demonstrated using the VEXnet controller over Wi-Fi.

This is just a small sampling of the possibilities with this combination type of platform. Don’t let my initial direction limit you. It would be great to see some new combination robots. Get out there and start building!

This is my RobotC Code for the behaviors seen in the video.

AUTONOMOUS MODE:


#pragma config(UART_Usage, UART2, VEX_2x16_LCD)
#pragma config(Sensor, dgtl1,  sonar,               sensorSONAR_inch)
#pragma config(Motor,  port1,           L,             tmotorServoStandard, openLoop)
#pragma config(Motor,  port2,           servo,         tmotorNormal, openLoop)
#pragma config(Motor,  port3,           drive,         tmotorNormal, openLoop)
#pragma config(Motor,  port10,          R,             tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
/////////////////////////////////////////////////////////////////////////
//  Author  : Steven Comer//  Program : Rover drives straight until near an object, it then slows,
//            stops, then backs up and turns.
//  Updated : 8 June 2011 @ 10:20 AM
/////////////////////////////////////////////////////////////////////////
task main()
{

  //pause at start and turn on headlights
  wait1Msec(2000);
  motor[R] = -127;
motor[L] = -127;
while(true)
{
clearLCDLine(0);
    displayNextLCDNumber(SensorValue(sonar), 3);

    //++++++++++++++++++++++++++++++CLEAR++++++++++++++++++++++++++++++++
if( SensorValue(sonar) > 20 || SensorValue(sonar) == -1 )
{
motor[servo] = -2;
motor[drive] = 50;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++APPROACH++++++++++++++++++++++++++++++
else if( SensorValue(sonar) <= 20 && SensorValue(sonar) > 15 )
{
motor[drive] = SensorValue(sonar) + 25; //power decreases
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++STOP AND TURN+++++++++++++++++++++++++++
else if( SensorValue(sonar) <= 15 )
{
//stop
motor[drive] = 0;
wait1Msec(500);
//back and turn
motor[servo] = random[50] + 60;
     //random degree
motor[drive] = -50;  //random power
wait1Msec(1000);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 }
}

REMOTE CONTROL MODE:


#pragma config(UART_Usage, UART2, VEX_2x16_LCD)
#pragma config(Sensor, dgtl1,  sonar,               sensorSONAR_inch)
#pragma config(Motor,  port1,           L,             tmotorServoStandard, openLoop)
#pragma config(Motor,  port2,           servo,         tmotorNormal, openLoop)
#pragma config(Motor,  port3,           drive,         tmotorNormal, openLoop)
#pragma config(Motor,  port10,          R,             tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
/////////////////////////////////////////////////////////////////////////
//  Author  : Steven Comer
//  Program : Remote control rover with VEXnet controller
//  Notes   : Throttle is Ch 2 (right joystick)
//            Steering is Ch 4 (left joystick)
//            Headlights are Ch 5U/5D and 6U/6D (on/off)
//  Updated : 10 June 2011 @ 12:30 PM
/////////////////////////////////////////////////////////////////////////
task main ()
{
 while(true)
{
//right headlight
if(vexRT[Btn6U] == 1)
motor[R] = -127;
if(vexRT[Btn6D] == 1)
motor[R] = 0;
//left headlight
if(vexRT[Btn5U] == 1)
motor[L] = -127;
if(vexRT[Btn5D] == 1)
motor[L] = 0;
//driving
motor[servo] = vexRT[Ch4];   //steering
motor[drive] = vexRT[Ch2];   //throttle
//LCD screen
displayLCDCenteredString(0,"VEX");
displayLCDCenteredString(1,"ROBOTICS");
}
}

Written by Jesse Flot

June 9th, 2011 at 3:31 pm

Posted in Cool projects,VEX

Tagged with , ,

Colored Object Tracking using the VEX Cortex and NXTCam

without comments

No official vision system available for the VEX Cortex? No problem.

Thanks to some really cool work by Xander, I2C sensors for the NXT can now be used on the Cortex as well (with a little bit of effort). As we’ve covered in some of our previous posts, ROBOTC and the VEX Cortex unlock a ton of cool robotic applications – controlling pneumatics, controlling high torque and high speed motors through relays, outputting to the LCD screen, ect. Being able to use the repository of I2C sensors available for the NXT on the Cortex unlocks many, many more.

To demonstrate this, we’ve chosen the Mindsensors NXTCam. With the NXTCam, you’re able to connect it to a computer over USB and “teach” it to track up to 8 different colors. Once it’s hooked up to your robot, it returns data related to the colors it’s tracking – size, x and y positions, ect. This make it ideal for tracking a colored object, distinguishing between multiple different colors, and even advanced line tracking (more on that in a future post).

In this video, we’ve trained the NXTCam to track the color red. ROBOTC code uses the data from the camera to center the robot on the red ball and drive up to it until it’s within a certain distance.

Written by Jesse Flot

April 26th, 2011 at 12:42 pm

Posted in Cortex,VEX

Tagged with , , , ,

Controlling Pneumatic Actuators in ROBOTC

with 4 comments

Pneumatic Actuators translate the force of compressed air into fast and powerful motion. In the VEX Robotics System, all pneumatic actuators create linear (in-and-out) motion, although rotary actuators do exist. The compressed air that powers the actuators is stored in a reservoir tank; differences in air pressure between the actuators and tank cause the actuators to move in and out.

The flow of air between the tank and the actuators (directly related to the differences in air pressure)  is controlled by a small switch, called an electromagnetic solenoid, which connects to the VEX PIC or Cortex using a standard 3-pin wire. It’s a common misconception that, since the solenoid enables motion, its 3-pin wire should plug into one of the MOTOR ports on the microcontroller. Actually, a solenoid is what’s considered a “Digital Output”, and should be plugged into one of the DIGITAL ports on the Cortex, or ANALOG/DIGITAL ports on the PIC.

To configure the solenoid in ROBOTC, go to the Motors and Sensors Setup menu, and select “Digital Out” as the sensor type.

 

 

 

 

 

 

 

 

 

 

 

 

 

Then, in ROBOTC, when you want to activate the pneumatic actuator controlled by the solenoid, you set its value equal to “1″. To deactivate it, set its value equal to “0″. In the sample code below, the remote control buttons are used to activate and deactivate the pneumatic actuator.

#pragma config(Sensor, dgtl7,  solenoid,            sensorDigitalOut)
//*!!Code automatically generated by ‘ROBOTC’ configuration wizard               !!*//

task main()
{
while(true)                   // Loop Forever
{
if(vexRT[Btn6U] == 1)           // If button 6U (upper right shoulder button) is pressed:
{
SensorValue[solenoid] = 1;  // …activate the solenoid.
}
else // If button 6U (upper right shoulder button) is  NOT pressed:
{
SensorValue[solenoid] = 0;  // ..deactivate the solenoid.
}
}
}

For more information on using pneumatic actuators, check out our Pneumatics lesson from the VEX 2.0 Curriculum.

Written by Jesse Flot

November 11th, 2010 at 4:12 pm

Traversing a Grand Challenge with the VEX Cortex

without comments

The Grand Challenge is a staff designed course which is not revealed to participants until the day of the competition. Before the competition, participants are provided with a list of conditions and situations to prepare their robots for.

On the day of the competition, the participant’s programming knowledge and preparation are put to the test as they work to traverse the course in a limited amount of time. The robot that makes the most progress without stalling out or deviating from the course wins!

In this iteration of the Grand Challenge, the Cortex-based robot must:

  • Navigate an obstructed path using feedback from the Shaft Encoders and Ultrasonic Rangefinder
  • Track an incomplete line up and down a ramp using feedback from the Line Tracking sensors
  • (Optional) Pick up the yellow ball and take it to the finish zone for extra points
  • Respond to remote-control commands only in the final zone
  • Avoid hitting obstacles in it’s path, walls on the field, and falling from the ramp

Check out this cool video of the robot completing the course.

To accomplish it’s task, the Cortex-based robot is equipped with:

  • Two driving motors, each with a Shaft Encoder
  • An Omni-wheel acting as a rear-caster wheel
  • Three Line Tracking Sensors
  • An Ultrasonic Rangefinder
  • Remote Control over VEXnet

Instructions for building this robot can be found here.

If you’d like ideas for creating your own Grand Challenge, check out this document for some inspiration.

Note: All materials are part of the VEX Cortex Video Trainer. Check it Out!

Written by Jesse Flot

November 3rd, 2010 at 10:40 am

BEST Competition Programming Templates

without comments

Hey all BEST Teams!

We’ve made a new library and sample program to help BEST teams up and running with using ROBOTC with their Cortex systems. This new template makes it really easy to customize your program for your robot without having to worry about loops, conditionals and variables too much. Here’s an example of some of the new functions.

  • ArcadeTwoWheelDrive(vexJSLeftV, vexJSLeftH, left, right);
    • Use this function to create a “arcade” (1 joystick) drive program. Pass 4 pieces of data to have the function do all the work for driving your robot.
      • 1st: MoveChannel – The joystick channel for forward and reverse.
      • 2nd: RotateChannel – The channel on the rotate port that controls left and right rotation. This value is mixed with the move channel.
      • 3rd:  leftMotor – The motor on the left side of the robot.
      • 4th:  rightMotor – The motor on the right side of the robot.
  • TankTwoWheelDrive(vexJSLeftV, vexJSRightV, left, right);
    • Use this function to create a “tank” (2 joystick) drive program. Pass 4 pieces of data to have the function do all the work for driving your robot.
      • 1st: MoveChannel – The joystick channel for “left” motor.
      • 2nd: RotateChannel – The joystick channel for “right” motor.
      • 3rd:  leftMotor – The motor on the left side of the robot.
      • 4th:  rightMotor – The motor on the right side of the robot.
  • MotorControlViaDigitalButtons(Btn7D, Btn7U, leftArm, -127,  +127,  0);
    • Use this function to control a motor via two digital buttons – Very customizable!
      • 1st:  Btn7D – The joystick button that controls speed decrease
      • 2nd: Btn7U – The joystick button that controls speed increase
      • 3rd: leftArm – The motor that is being controlled
      • 4th: -127 – The lowest value for the motor speed
      • 5th: +127 – The highest value for the motor speed
      • 6th: 0 – How fast to adjust the speed. 0 — fastest. 50 — 1.25 seconds to cover the compete range.

Download this new library and sample program today. To help you get started, we’ve written a “getting started” PDF that will help you get started with this library.

BEST Code Library V1
BEST Code Library “Getting Started

Written by Tim Friez

October 20th, 2010 at 2:37 pm

Posted in Cortex,PIC,VEX

Tagged with , , ,

FREE ROBOTC Webinar available for viewing!

without comments

Hi everyone!

Our very own VEX expert, Jesse Flot, has just recently recorded a webinar to help those using the CORTEX platform. Starting yesterday (Sept. 8th), Jesse will be recording weekly webinars (for 6 weeks) to help those who are looking for resources when working with the CORTEX system.

Jump to the Webinars area to view it

Please note that this webinar epsiode is geared towards the BEST competition, but that doesn’t mean that it won’t help you out.

The way that the webinars will be created is Jesse will take questions from the CORTEX Competition forum, and use those topics to record a webinar.

If you wish to submit a topic to talk about, please log onto the forum and post a topic!

Written by Vu Nguyen

September 9th, 2010 at 11:05 am

Posted in General News,VEX

Tagged with , , ,

ROBOTC for Cortex and PIC 2.25 released!

without comments

The Robotics Academy is happy to announce the release of ROBOTC for Cortex 2.25.

We’ve made lots of changes in ROBOTC from 2.20 to 2.25. We’re continuing to improve ROBOTC with the Cortex system. This new version is fully compatible with the VEX Cortex and the VEX PIC systems, along with the VEXnet upgrade system for the VEX PIC.

Click here to download the latest version

Firmware Downloader Built-In: Firmware Download for ROBOTC Firmware, Cortex Master Firmware and VEXnet Joystick Firmware built into ROBOTC now!

Download Method Chooser: Easier to choose how you want to download your program. Always defaults to VEXnet and USB, but you can manually choose to disable VEXnet and download over USB only.

Quick Preferences: This allows you to set key preferences with only the click of a button. Make ROBOTC work the way you want it to!

Other New Features and Bug Fixes:

  1. Build is able to program both PIC and Cortex platforms successfully.
  2. “Auto save” before compile was broken.
  3. “Previous Platform Type” was not being correctly saved into Windows Registry.
  4. Add code to handle “Device Removal” and “Device Acquire” without long hangs of application.
  5. Added a flag to Preferences -> Internal” to indicate whether firmware downloading should be read verified.
  6. Fix “Priority” column in “Task Status” debugger pane. It was not properly displaying.
  7. Move “Debug Stream” from Super-User to “Expert” menu.
  8. Add a 250 millisecond delay after telling Cortex to enter download mode before attempting the autobaud sequence.
  9. VEX Cortex Integrated Master Firmware Loader inside of ROBOTC.
  10. Add support for run-time strings in the VEX LCD display routines.
  11. Fix conlict between Digital pin 4 and 10. They both share the same external interrupt index and it was possible to hang the Cortex. Fix makes both pins work correctly — previously pin 10 was not working — for external interrupts. But the hardware prevents supporting sensors that require external interrupts on both pins at once.

Written by Vu Nguyen

September 2nd, 2010 at 5:31 pm

Posted in Releases,VEX

Tagged with , ,

IMPORTANT UPDATE: ROBOTC for Cortex & PIC version 2.20.1 Beta

without comments

Important update!

We have just released another update to ROBOTC for Cortex & PIC. This release is required to use Cortex motor ports 1 or 10. In earlier versions,  you may encounter a firmware bug that can cause the motor control circuits to overheat and burn out.

Click here to go to the download page – ROBOTC for Cortex & PIC

Cortex Microprocessor

Enhancements in this release include:

  1. Support for direct wired USB cable between PC and  VEX Cortex for downloading user programs and debugging added.
  2. Support for Debugger “Debug Stream” window added. User programs can easily write (“print”) to a text window on the PC.
  3. Faster firmware downloading. It now takes just 10 to 15 seconds. User programs download in just one or two seconds.
  4. Fix control of H-bridges for motors 1 and 10 to prevent “shoot through” and the potential for internal short circuits.
  5. A few minor bugs fixed in the compiler.

Written by Vu Nguyen

July 1st, 2010 at 9:05 am

Posted in General News,VEX

Tagged with ,

Want to be in the loop? Sign up to our mailing list!

with one comment

Hello fellow ROBOTC fans!

I just created a ROBOTC Mailing list for those of you who like to be in the “in” crowd. :)

Just go to www.robotc.net and type in your Name and Email address on the right side. Subscribe by clicking the “Subscribe” button, unsubscribe by clicking the “unsubscribe” button.

I’ll update you on when a new release or beta version is out. Or if any important information regarding ROBOTC needs to be announced.

Happy programming!

Written by Vu Nguyen

June 30th, 2010 at 2:22 pm

Posted in FTC,General News,NXT,VEX

Tagged with , , ,