ROBOTC.net forums
http://www.robotc.net/forums/

Programming help!
http://www.robotc.net/forums/viewtopic.php?f=11&t=9594
Page 1 of 1

Author:  jago2132 [ Mon Oct 20, 2014 9:16 am ]
Post subject:  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:)

Author:  CARBOT [ Mon Oct 20, 2014 11:01 pm ]
Post subject:  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.

Author:  jago2132 [ Wed Oct 22, 2014 8:34 am ]
Post subject:  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 :(

Author:  terbos [ Wed Oct 22, 2014 4:48 pm ]
Post subject:  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

Author:  terbos [ Wed Oct 22, 2014 4:55 pm ]
Post subject:  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

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/