View unanswered posts | View active topics It is currently Sat Jun 15, 2019 8:36 pm

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Author Message
Rookie

Joined: Thu Feb 04, 2016 6:27 pm
Posts: 1
I am trying to make a program with tank drive controls. I want to adjust the speed with the remote control. The motors will be divided by the variable Schange. The problem is that the motors don't run when Schange is greater than one.
Here's the code,

#pragma config(Motor, port2, LeftDrive, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port3, RightDrive, tmotorVex393_MC29, openLoop, reversed)
#pragma config(Motor, port4, testor, tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

float Channel2; //Right Joystick
float Channel3; //Left Joystick

float Schange; //the value the is divids the speed

{
if ((vexRT[Btn5D])==1)
{
Schange = 1;
}
if ((vexRT[Btn6D])==1)
{
Schange = Schange + 1;
}
return Schange;
}

{
if ( abs(vexRT[Ch2]) > threshold)
Channel2 = vexRT[Ch2]/Schange;
else
Channel2 = 0;
if (abs(vexRT[Ch3]) > threshold)
Channel3 = vexRT[Ch3]/Schange;
else
Channel3 = 0;
}
{
Schange = 1;
while(1==1)
{
motor[LeftDrive] = Channel2;
motor[RightDrive] = Channel3;
}
}

Any help would be greatly appreciated.

Thu Feb 04, 2016 6:38 pm
Moderator

Joined: Tue May 19, 2015 3:07 pm
Posts: 91
Okay so what is happening is a simple case of your code executing multiple times while the button is held down. So imagine that the code runs through 1 time per second and you held the button down for 60 seconds. What would the value be of Schange at the end of the 60 seconds?

The code on the robot runs thousands of times per second so any period the button is held down causes the button to be increased multiple times. Once this gets above 127 the motor will not run at all. What we want is for the variable to only be incremented once per button press. Rather than check if the button is held down what we do is check if the button is held down AND last time it wasn't.

Also currently speedadjusting returning Schange does not do anything so I made it a void function. The function sets the variable Schange so it doesn't need to return it. (I can explain this a lot better if this isn't clear)

 Code:#pragma config(Motor, port2, LeftDrive, tmotorVex393_MC29, openLoop)#pragma config(Motor, port3, RightDrive, tmotorVex393_MC29, openLoop, reversed)#pragma config(Motor, port4, testor, tmotorVex393_MC29, openLoop)//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//float Channel2; //Right Joystickfloat Channel3; //Left Joystickint threshold; //the actual deadzonefloat Schange; //the value that divides the speedbool Btn6DLast=false;void speedadjusting(){   if ((vexRT[Btn5D])==1)   {      Schange = 1;   }   if ((vexRT[Btn6D])==1&&Btn6DLast==0)   {      Schange = Schange + 1;   }   Btn6DLast=vexRt[Btn6D];}void deadZoneCheck(){   if ( abs(vexRT[Ch2]) > threshold)      Channel2 = vexRT[Ch2]/Schange;   else      Channel2 = 0;   if (abs(vexRT[Ch3]) > threshold)      Channel3 = vexRT[Ch3]/Schange;   else      Channel3 = 0;}task main(){   Schange = 1;   while(1==1)   {      speedadjusting();      deadZoneCheck();      motor[LeftDrive] = Channel2;      motor[RightDrive] = Channel3;      wait1Msec(50);//Don't hog CPU   }}

Fri Feb 05, 2016 2:10 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 2 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