View unanswered posts | View active topics It is currently Sun Apr 20, 2014 2:30 pm






Reply to topic  [ 10 posts ] 
DC motor name on RobotC 
Author Message
Rookie

Joined: Tue Oct 11, 2011 5:12 pm
Posts: 5
Post DC motor name on RobotC
In the previous version of RobotC i was able to use the name MotorD and MotorE for the DC motors. but with this new version of RobotC i get an error "**Error**:Undefined variable 'motorD'. 'short' assumed." i was using a previous program that worked fine untill i downloaded a the newer version. anything would help


Tue Oct 11, 2011 5:21 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: DC motor name on RobotC
You can go into the Motors and Sensors menu under Robot, and name different motors.

_________________
sudo rm -rf /


Tue Oct 11, 2011 6:23 pm
Profile
Rookie

Joined: Tue Oct 11, 2011 5:12 pm
Posts: 5
Post Re: DC motor name on RobotC
i have allready gone and tried that but i can only rename motors A,B, and C and those three only control the nxt motors. what i cant figure out is how to get the tetrix DC motors to move. i have tried motor[motorD] motor[rightmotor] and the #pragma config line will accept any of two names but when i type it into my joystick line i come with the error **Error**:Undefined variable 'rightmotor'. 'short' assumed. i dont think that i have done anything wrong in the programing but you never know :lol: this is what i have so far

#pragma config(Motor, mtr_S1_C1_1, motorleft, tmotorNormal, openLoop, encoder)
#pragma config(Motor, mtr_S1_C1_2, motorright, tmotorNormal, openLoop, reversed, encoder)
#pragma config(Servo, srvo_S1_C2_1, servo1, tServoNone)
#pragma config(Servo, srvo_S1_C2_2, servo2, tServoNone)
#pragma config(Servo, srvo_S1_C2_3, servo3, tServoNone)
#pragma config(Servo, srvo_S1_C2_4, servo4, tServoNone)
#pragma config(Servo, srvo_S1_C2_5, servo5, tServoNone)
#pragma config(Servo, srvo_S1_C2_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c" // This file does all of the processing of the BT Packet
task main()
{
while (true)
{
getJoystickSettings(joystick);
//Check for new BT Packet and update the variables for the joystick positions


motor[motorright] = joystick.joy1_y1;
motor[motorleft] = joystick.joy1_y2;
}
}


Thu Oct 13, 2011 5:16 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1343
Post Re: DC motor name on RobotC
I am assuming your motor D and E are your left and right motors. If so, the name you defined are motorleft and motorright, not rightmotor. So motor[motorright] should work for you.


Thu Oct 13, 2011 7:05 pm
Profile
Rookie

Joined: Tue Oct 11, 2011 5:12 pm
Posts: 5
Post Re: DC motor name on RobotC
i changed the motor name from motorright to rightmotor but i still get the error message
**Error**:Undefined variable 'rightmotor'. 'short' assumed.
**Error**:Undefined variable 'leftmotor'. 'short' assumed.

i also changed the name in the #pragma config line and it accepts that but in the line that tells the motor to move it rejects it :breakcomputer:


Tue Oct 25, 2011 5:20 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1343
Post Re: DC motor name on RobotC
Would you post your code? It's hard to figure out what's wrong without seeing it.


Tue Oct 25, 2011 6:15 pm
Profile
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 137
Post Re: DC motor name on RobotC
I would double check that your platform is still set to LEGO NXT + TETRIX.
A simple copy/paste of your code works fine for me until I reset the platform type to plain old LEGO NXT and then I get the same error you describe.


Tue Oct 25, 2011 10:02 pm
Profile
Rookie

Joined: Tue Oct 11, 2011 5:12 pm
Posts: 5
Post Re: DC motor name on RobotC
l0jec helped fix part of our problem :bigthumb: but now when we try to compile and download our program we get the popup widow that says

Byte Code Interpreter Exception:
Program Slot: 0. Task ID: main[0]
Error at PC: Task: main+0x0042
Task PC: Task offset start(0).
TaskState: 'Exception'
Exception Type: 'Motor out of range (2)'

Our Robot is only 3 feet away from the laptop. Our code as of now:


#pragma config(Motor, mtr_S1_C1_1, motorLeft, tmotorNormal, openLoop, encoder)
#pragma config(Motor, mtr_S1_C1_2, motorRight, tmotorNormal, openLoop,encoder)
#pragma config(Servo, srvo_S1_C2_1, servo1, tServoNone)
#pragma config(Servo, srvo_S1_C2_2, servo2, tServoNone)
#pragma config(Servo, srvo_S1_C2_3, servo3, tServoNone)
#pragma config(Servo, srvo_S1_C2_4, servo4, tServoNone)
#pragma config(Servo, srvo_S1_C2_5, servo5, tServoNone)
#pragma config(Servo, srvo_S1_C2_6, servo6, tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

#include "JoystickDriver.c" // This file does all of the processing of the BT Packet
task main()
{
while (true)
{
getJoystickSettings(joystick);
//Check for new BT Packet and update the variables for the joystick positions


motor[motorLeft] = joystick.joy1_y1;
motor[motorRight] = joystick.joy1_y2;
}
}


Thu Oct 27, 2011 5:17 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1343
Post Re: DC motor name on RobotC
One unrelated obvservation. It wouldn't fix your problem though.
joystick has a range of -128 to +127 but motor is in the range of -100 to 100. So you need to scale the joystick range to the motor range. I use these macros:
Code:
#ifndef DEADBAND_INPUT_THRESHOLD
    #define DEADBAND_INPUT_THRESHOLD 20
#endif

/**
 *  These macros ignore input value (n) that is within the DEADBAND_THRESHOLD.
 *  This is necessary because analog joysticks do not always centered at zero.
 *  So if the joystick is at the rest position, we will consider it zero even
 *  though the value is non-zero but within DEADBAND_THRESHOLD.
 */
#define DEADBAND(n,t)           ((abs(n) > (t))? (n): 0)
#define DEADBAND_INPUT(n)       DEADBAND(n, DEADBAND_INPUT_THRESHOLD)

#define NORMALIZE(n,sl,sh,tl,th) (int)(((long)(n) - (sl))*((th) - (tl))/((sh) - (sl)) + (tl))

motor[motorLeft] = NORMALIZE(DEADBAND_INPUT(joystick.joy1_y1), -128, 127, -100, 100);
motor[motorleft] = NORMALIZE(DEADBAND_INPUT(joystick.joy1_y2), -128, 127, -100, 100);

The exception seems to be related to the motor index out of range which still points to incorrect motor configuration.


Thu Oct 27, 2011 5:52 pm
Profile
Expert

Joined: Mon Oct 27, 2008 9:59 pm
Posts: 137
Post Re: DC motor name on RobotC
MHTS wrote:
The exception seems to be related to the motor index out of range which still points to incorrect motor configuration.

I agree. From the snippet you copy/pasted, it appears to be missing the first configuration line which sets the controllers themselves. Rerun your Motor & Sensor Setup.


Fri Oct 28, 2011 9:48 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 10 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:  
cron



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