View unanswered posts | View active topics It is currently Fri Apr 20, 2018 10:19 pm

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Noob PLTW teacher with programming question
Author Message
Rookie

Joined: Mon Nov 12, 2012 1:17 pm
Posts: 2
Noob PLTW teacher with programming question
Let me apologize immediately if I placed this is the wrong forum. I didn't intend to.

I am a new PLTW teacher, and we do not have the VEX in the curriculum yet. However, I am involved in a robot competition, and I need to help with programming a space elevator winch.

I want to have the winch climb with the following commands and then brake. If I delete the else statement, the buttons work as described, although the motor is on until I give a different command. I would like the motor to stop when no command is given. Later, I might have to add a percent of motor to compensate for added weight and free fall.

When I give a 0 or a 10 in the else statement, the motor chudders during any of the other commands. I realize this is a simple issue to many of you, but if you could help me with my limited knowledge, I would greatly appreciate it.

#pragma config(Motor, port2, winch, tmotorVex393, openLoop)
#pragma config(Motor, port3, rotatearm, tmotorVex269, openLoop)
#pragma config(Motor, port4, armextend, tmotorVex269, openLoop)
#pragma config(Motor, port5, claw, tmotorServoStandard, openLoop)
#pragma config(Motor, port6, clawtilt, tmotorServoStandard, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{
while (1==1)
{
{
if (vexRT[Btn5U]==1) // button 5U pressed
motor[winch]=127; // climb high speed
if (vexRT[Btn5D]==1) // button 5D pressed
motor[winch]=-40; // decend high speed
if (vexRT[Btn7U]==1) // button 7U pressed
motor[winch]=63; // climb low speed
if (vexRT[Btn7D]==1) // button 7D pressed
motor[winch]=-10; // decend low speed
else (motor[winch]=0);} // this turns the motor off

{motor[armextend]=vexRT[Ch3]/3;} //extends/retracts arm using joystick

{if (vexRT[Btn6U]==1) //button 6U pressed
motor[claw]=127; //claw clamp
if (vexRT[Btn6D]==1) //button 6D pressed
motor[claw]=-127;} //claw unclamp

{if (vexRT[Btn8U]==1) //button 8U pressed
motor[clawtilt]=127; //claw tiltup
if (vexRT(Btn8D)==1) //button 8D pressed
motor[clawtilt]=-127;} //claw tiltdown
}

}

Mon Nov 12, 2012 1:36 pm
Moderator

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Re: Noob PLTW teacher with programming question
OK, lets take a look at some pseudo code, and I think you'll realize the mistake right away. If my program says:

 Code:while(true){    if (up button is pressed) { go up }    else { stop }    if (down button is pressed) { go down }    else { stop }}

Lets walk though what will happen when I press the up button line by line:

up button is pressed, so motor goes up;
skips else since up button is pressed;
down button is not pressed, so does not go down;
down button is not pressed, so the else statement stops the motor;
repeat;

Do you see what is happening here? you're giving the motor conflicting commands for stop and go rapidly, so it starts stuttering. One way to implement the behavior you want is as follows:

 Code:while(true){    if (up button is pressed) { go up }    else if (down button is pressed) { go down }    else { stop }}

Does that clear things up?

_________________
sudo rm -rf /

Mon Nov 12, 2012 2:10 pm
Rookie

Joined: Mon Nov 12, 2012 1:17 pm
Posts: 2
Re: Noob PLTW teacher with programming question
Thanks

It helped a lot.

Also, is there a way to use the analog stick on the controller but set a lower range? We have delicate work to do in areas, we need less of a range, but the control of the stick.

Mon Nov 12, 2012 7:15 pm
Moderator

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Re: Noob PLTW teacher with programming question
There are a few ways to go about this. One of the simplest is to divide the input. For example, using vexRT[Ch2]/2 will halve your input range.

_________________
sudo rm -rf /

Mon Nov 12, 2012 9:29 pm
Novice

Joined: Sun Oct 21, 2012 10:01 pm
Posts: 76
Re: Noob PLTW teacher with programming question
We don't use VEX at school (I'm used to programming for the NXT in RobotC), but we set up a system such that when a button is pressed on the controller, we divide input by a number before feeding it to a motor. Here's a pseudocode example.

 Code:float scaleJoystick = 1.0;float joystickValue = 0;while (true){   if (buttonPressed() == kPressed)      scaleJoystick = 0.5;  // When button is pressed, divide motor power by two.     else      scaleJoystick = 1.0;   joystickValue = scaleJoystick * readJoystick();   motor = joystickValue;}

Or something along those lines.

EDIT: You can actually write it in fewer lines using RobotC's ternary operator...
 Code:motor = readJoystick() * (buttonPressed() == kPressed ? 0.5 : 1.0);

Wed Nov 14, 2012 2:13 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 5 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.