View unanswered posts | View active topics It is currently Sat Dec 07, 2019 7:28 am






Reply to topic  [ 5 posts ] 
Programming help! 
Author Message
Rookie

Joined: Mon Oct 20, 2014 9:04 am
Posts: 2
Post Programming help!
I'm very new to robotc and I have searched the web for answers but I can't find what I'm looking for. I have been trying to program a motor to a button on the controller and everything i have tried has failed. this is the code i have so far:


Code:
#pragma config(UART_Usage, UART1, uartVEXLCD, baudRate250000, IOPins, None, None)
#pragma config(UART_Usage, UART2, uartNotUsed, baudRate4800, IOPins, None, None)
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Sensor, I2C_2,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Sensor, I2C_3,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Sensor, I2C_4,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Sensor, I2C_5,  ,               sensorQuadEncoderOnI2CPort,    , AutoAssign)
#pragma config(Motor,  port2,           Motor2,        tmotorVex393HighSpeed_MC29, PIDControl, driveRight, encoderPort, I2C_1)
#pragma config(Motor,  port3,           Motor3,        tmotorVex393HighSpeed_MC29, PIDControl, reversed, driveLeft, encoderPort, I2C_3)
#pragma config(Motor,  port4,           Motor4,        tmotorVex393HighSpeed_MC29, PIDControl, driveLeft, encoderPort, I2C_4)
#pragma config(Motor,  port5,           Motor5,        tmotorVex393HighSpeed_MC29, PIDControl, reversed, driveRight, encoderPort, I2C_5)
#pragma config(Motor,  port6,           Motor6,        tmotorVex393HighSpeed_MC29, PIDControl, encoderPort, I2C_2)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
   while(1==1)
   {
      motor[Motor2] = vexRT[Ch2];
      motor[Motor5] = vexRT[Ch2];
      motor[Motor4] = vexRT[Ch3];
      motor[Motor3] = vexRT[Ch3];
      turnLEDOn(digitalPort);
                               
   }
   motor[port6] = vexRT[Btn6U];
}
 


Any and all help is greatly appreciated:)


Mon Oct 20, 2014 9:16 am
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post Re: Programming help!
If the problem is that it will not compile you may want to just remove the line
turnLEDOn(digitalPort);
since digitalPort is not defined anywhere.


Mon Oct 20, 2014 11:01 pm
Profile
Rookie

Joined: Mon Oct 20, 2014 9:04 am
Posts: 2
Post Re: Programming help!
I took that out but that wasn't the problem the problem is the "motor[port6] = vexRT[Btn6U];" part. I am trying to assign the motor to the buttons on the top and nothing I try is working. I don't know what I'm doing wrong :(


Wed Oct 22, 2014 8:34 am
Profile
Rookie

Joined: Wed Feb 24, 2010 11:51 pm
Posts: 31
Post Re: Programming help!
The problem is that the
Code:
motor[port6] = vexRT[Btn6U];
is outside the while loop. Try moving it up a line (inside the {} ) so it will be executed with the other motor assignments.

Terry

_________________
Vex & FLL Coach and robotics instructor


Wed Oct 22, 2014 4:48 pm
Profile
Rookie

Joined: Wed Feb 24, 2010 11:51 pm
Posts: 31
Post Re: Programming help!
Oops, almost forgot...

The buttons produce two values: 0=not pressed 1=pressed
But the motor expects values from -127 to +127.

That means that the pressing the button will make the motor run *very* slowly (or not at all, because 1 isn't enough power to even move).

To make it go faster, multiply the button by the speed you want:
Code:
motor[port6] = vexRT[Btn6U] * 50;


If you want buttons to go both directions, make one negative:
Code:
motor[port6] = vexRT[Btn6U] * 50 + vexRT[Btn6D] * -50;


Terry

_________________
Vex & FLL Coach and robotics instructor


Wed Oct 22, 2014 4:55 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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

Search for:
Jump to:  



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