Go to Post I see all these people complaining about the FIRST game having perverse penalties for playing defense...then we play without defense, and still people complain. - MrForbes [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 30-01-2009, 15:16
BrandonD-1528's Avatar
BrandonD-1528 BrandonD-1528 is offline
Mentor
AKA: Brandon Dusseau
FRC #1528 (Monroe Trojan Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Ann Arbor, MI
Posts: 118
BrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the rough
Drive code not working; any suggestions?

We are testing code for our motors/servos. Apparently after downloading the code to our cRIO, nothing seems to function. It builds, so we are sure it is not a syntax error.
The code is as follows:

Code:
#include "WPILib.h"

void update_drive;

class RobotDemo : public SimpleRobot 
{ 
	RobotDemo(void)
	{ 	// put initialization code here
		pwm leftmotor(1);
		pwm rightmotor(2);
		joystick leftjoy(1);
		joystick rightjoy(2);
	}
	void Autonomous(void)
	{ 	// put autonomous code here
		
	}
	void OperatorControl(void)
	{ 	// put operator control code here
		update_drive();
	}
};


	start_robot_class(RobotDemo);


void update_drive()
{
	int k = /*your value here*/;		//speed increase/decrease value
	
	if (leftjoy:gety() >= (255 - k))		//if left joystick is near max
	{	//overshot security
		leftmotor:rawset(leftjoy:gety());
	}
	
	if (leftjoy:gety() <= k)				//if left joystick is near min
	{	//undershot security
		leftmotor:rawset(leftjoy:gety());
	}
	
	if ((leftjoy:gety() < (255 - k)) && (leftjoy:gety() > k))		//otherwise...
	{	//standard control
		if (leftjoy:gety() > leftmotor:rawget())
		{	//speed up
			int leftmotortemp1 = leftmotor:rawget();
			leftmotor:rawset(leftmotortemp1 + k);
			if (leftjoy:gety() < leftmotor:rawget())
			{	//overshot security
				leftmotor:rawset(leftjoy:gety());
			}
		}
		if (leftjoy:gety() < leftmotor:rawget())
		{	//slow down
			int leftmotortemp1 = leftmotor:rawget();
			leftmotor:rawset(leftmotortemp1 - k);
			if (leftjoy:gety() > leftmotor:rawget())
			{	//undershot security
				leftmotor:rawset(leftjoy:gety());
			}
		}
	}
	
	
	
	
	if (rightjoy:gety() >= (255 - k))		//if right joystick is near max
	{	//overshot security
		rightmotor:rawset(rightjoy:gety());
	}
	
	if (rightjoy:gety() <= k)				//if right joystick is near min
	{	//undershot security
		rightmotor:rawset(rightjoy:gety());
	}
	
	if ((rightjoy:gety() < (255 - k)) && (rightjoy:gety() > k))		//otherwise...
	{	//standard control
		if (rightjoy:gety() > rightmotor:rawget())
		{	//speed up
			int rightmotortemp1 = rightmotor:rawget();
			rightmotor:rawset(rightmotortemp1 + k);
			if (rightjoy:gety() < rightmotor:rawget())
			{	//overshot security
				rightmotor:rawset(rightjoy:gety());
			}
		}
		if (rightjoy:gety() < rightmotor:rawget())
		{	//slow down
			int rightmotortemp1 = rightmotor:rawget();
			rightmotor:rawset(rightmotortemp1 - k);
			if (rightjoy:gety() > rightmotor:rawget())
			{	//undershot security
				rightmotor:rawset(rightjoy:gety());
			}
		}
	}
}
Any suggestions would be greatly appreciated. Our team is really falling behind this year, and nothing seems to be going right.

Thanks,
iPirates 1528

Last edited by BrandonD-1528 : 30-01-2009 at 15:46.
  #2   Spotlight this post!  
Unread 30-01-2009, 16:26
Analog's Avatar
Analog Analog is offline
Registered User
AKA: Bob Most
FRC #2619 (The Charge)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Midland, Michigan
Posts: 53
Analog will become famous soon enoughAnalog will become famous soon enough
Re: Drive code not working; any suggestions?

When you say "nothing seems to function", do you mean it doesn't respond AT ALL, or does it not do exactly what you want? There's a big difference.

Also, just because you have no syntax issues, doesn't mean the cRio is happy. Did you use an RS-232 link to the cRIO to see what the response was after the download? Did you reboot after download?

Does the control box say "no code"?

These details are critical.
  #3   Spotlight this post!  
Unread 30-01-2009, 16:40
BrandonD-1528's Avatar
BrandonD-1528 BrandonD-1528 is offline
Mentor
AKA: Brandon Dusseau
FRC #1528 (Monroe Trojan Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Ann Arbor, MI
Posts: 118
BrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the rough
Re: Drive code not working; any suggestions?

It does not respond at all...

No, we did not use the RS-232 link, but we did reboot after uploading the code.

And yes, the control box says "No Code"

We re-imaged the C-Rio, and the code that that it put in worked, so it's not a hardware problem.
  #4   Spotlight this post!  
Unread 30-01-2009, 16:44
virtuald's Avatar
virtuald virtuald is online now
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,086
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Drive code not working; any suggestions?

You're not building the right thing apparently, since theres no way that code will build as pasted. For starters, none of your types are correct (joystick instead of Joystick, pwm instead of PWM). Second, you need to have your update_drive() function inside the class definition.

And... the list goes on. Start with the SimpleTemplate, and make *simple* changes first. Then work your way up.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
  #5   Spotlight this post!  
Unread 30-01-2009, 16:45
virtuald's Avatar
virtuald virtuald is online now
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,086
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: Drive code not working; any suggestions?

Quote:
Originally Posted by BrandonD-1528 View Post
It does not respond at all...

No, we did not use the RS-232 link, but we did reboot after uploading the code.
If you are not deploying the code, then you should not reboot otherwise the code goes away on reboot.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
  #6   Spotlight this post!  
Unread 30-01-2009, 16:47
MattD's Avatar
MattD MattD is offline
Registered User
AKA: Matthew Douglas
FRC #0228 (GUS Robotics)
Team Role: Alumni
 
Join Date: Feb 2006
Rookie Year: 2005
Location: Indianapolis, IN
Posts: 185
MattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to beholdMattD is a splendid one to behold
Send a message via AIM to MattD
Re: Drive code not working; any suggestions?

I'm really surprised that this compiles... are you sure you're building the correct project?

One thing I do notice is that the OperatorControl code is only going to execute once. You need to do something like this:

Code:
void OperatorControl()
{
     while (IsOperatorControl())
     {
            update_drive();
     }
}
Additionally, your joysticks and PWM objects need to be declared as member variables within the class, rather than local variables in the class constructor. As it is in your code right now, leftmotor, rightmotor, leftjoy, rightjoy are all only available to use in the constructor.

I'd also recommend against using the PWM class directly. Instead you should use Victor or Jaguar.

Also, take note that the Joystick class will return a float from -1.0 to +1.0 when you look at an axis, not an 8-bit uint from 0-255.

You should have something more like this:

Code:
#include "WPILib.h"

class MyRobot : public SimpleRobot
{
    Victor leftMotor(1);
    Victor rightMotor(2);
    Joystick leftStick(1);
    Joystick rightStick(2);

    void Autonomous()
    {
        // Autonomous code goes here.
    }
    void OperatorControl()
    {
           while (IsOperatorControl())
           {
                // Drive code goes here.
           }
     }
};

START_ROBOT_CLASS(MyRobot);
Hope this is enough to get you started.
__________________
GUS Robotics Team 228

2010 WPI Engineering Inspiration Award
2010 WPI Regional Champions (Thanks 230 & 20!)
2010 CT VEX Champions
2010 CT VEX Innovate Award
2009 QCC VEX Champions
2009 CT Motorola Quality Award
2007 CT J&J Sportsmanship Award
2006 CT Best Website Award
  #7   Spotlight this post!  
Unread 30-01-2009, 16:49
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Drive code not working; any suggestions?

Others have posted since I started writing this, but I'll post since I had a few details that the others didn't include.

As has been stated, I'm not sure how there aren't syntax errors.

You have many capitalization errors in your post (maybe it was a poor transcription?). For example, you have pwm when it should be PWM. This brings up the question of why you're using PWM directly and not going through the Victor or Jaguar class?

Your function prototype of update_drive should be giving you an error. You have
Code:
void update_drive;
when it needs to be
Code:
void update_drive(void);
The way you're trying to access class members is incorrect and should be giving you an error. You have
Code:
leftjoy:gety()
when it should be
Code:
leftjoy.GetY()
And what's with this line? The compiler would most definitely complain about that
Code:
int k = /*your value here*/;		//speed increase/decrease value
In summary, the code that you posted should not compile. Double check that you're not getting errors.
  #8   Spotlight this post!  
Unread 30-01-2009, 17:04
BrandonD-1528's Avatar
BrandonD-1528 BrandonD-1528 is offline
Mentor
AKA: Brandon Dusseau
FRC #1528 (Monroe Trojan Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Ann Arbor, MI
Posts: 118
BrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the rough
Re: Drive code not working; any suggestions?

We're definately having some communication issues between programmers. We're currently working on correcting all these errors (and we didn't notice the blank variable declarations >.<) and we'll post the new code as soon as we test it. Thanks for the help
  #9   Spotlight this post!  
Unread 30-01-2009, 17:49
BrandonD-1528's Avatar
BrandonD-1528 BrandonD-1528 is offline
Mentor
AKA: Brandon Dusseau
FRC #1528 (Monroe Trojan Robotics)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Ann Arbor, MI
Posts: 118
BrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the roughBrandonD-1528 is a jewel in the rough
Re: Drive code not working; any suggestions?

We took all of your suggestions into consideration, and here's our revised code. It's still not building and maybe we were wrong about the syntax error.

Code:
#include <WPILib.h>
#include <Jaguar.h>
#include <Victor.h>



class RobotDemo : public SimpleRobot 
{ 
	RobotDemo(void)
	{ 	// put initialization code here
		Jaguar leftmotor(1);
		Victor rightmotor(2);
		Joystick leftjoy(1);
		Joystick rightjoy(2);
	}
	void Autonomous(void)
	{ 	// put autonomous code here
		
	}
	void OperatorControl(void)
	{ 	// put operator control code here
		update_drive();
	}
	
	
	void update_drive()
	{
	int k = 1;		//speed increase/decrease value
	
	if (leftjoy.GetY() >= (255 - k))		//if left joystick is near max
	{	//overshot security
		leftmotor.rawset(leftjoy.GetY());
	}
	
	if (leftjoy.GetY() <= k)				//if left joystick is near min
	{	//undershot security
		leftmotor.rawset(leftjoy.GetY());
	}
	
	if ((leftjoy.GetY() < (255 - k)) && (leftjoy.GetY() > k))		//otherwise...
	{	//standard control
		if (leftjoy.GetY() > leftmotor.rawget())
		{	//speed up
			int leftmotortemp1 = leftmotor.rawget();
			leftmotor.rawset(leftmotortemp1 + k);
			if (leftjoy.GetY() < leftmotor.rawget())
			{	//overshot security
				leftmotor.rawset(leftjoy.GetY());
			}
		}
		if (leftjoy.GetY() < leftmotor.rawget())
		{	//slow down
			int leftmotortemp1 = leftmotor.rawget();
			leftmotor.rawset(leftmotortemp1 - k);
			if (leftjoy.GetY() > leftmotor.rawget())
			{	//undershot security
				leftmotor.rawset(leftjoy.GetY());
			}
		}
	}
	
	
	
	
	if (rightjoy.GetY() >= (255 - k))		//if right joystick is near max
	{	//overshot security
		rightmotor.rawset(rightjoy.GetY());
	}
	
	if (rightjoy.GetY() <= k)				//if right joystick is near min
	{	//undershot security
		rightmotor.rawset(rightjoy.GetY());
	}
	
	if ((rightjoy.GetY() < (255 - k)) && (rightjoy.GetY() > k))		//otherwise...
	{	//standard control
		if (rightjoy.GetY() > rightmotor.rawget())
		{	//speed up
			int rightmotortemp1 = rightmotor.rawget();
			rightmotor.rawset(rightmotortemp1 + k);
			if (rightjoy.GetY() < rightmotor.rawget())
			{	//overshot security
				rightmotor.rawset(rightjoy.GetY());
			}
		}
		if (rightjoy.GetY() < rightmotor.rawget())
		{	//slow down
			int rightmotortemp1 = rightmotor.rawget();
			rightmotor.rawset(rightmotortemp1 - k);
			if (rightjoy.GetY() > rightmotor.rawget())
			{	//undershot security
				rightmotor.rawset(rightjoy.GetY());
			}
		}
	}
	}
};


	Start_Robot_Class(RobotDemo);
Edit: The code has been corrected for the most part. Please let us know if you can find any other problems.
__________________
Brandon Dusseau (website)
Monroe Trojan Robotics mentor
Software Engineer
Michigan Tech alumnus

Last edited by BrandonD-1528 : 30-01-2009 at 18:12.
  #10   Spotlight this post!  
Unread 30-01-2009, 21:06
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Drive code not working; any suggestions?

Some advice - when something isn't compiling and you ask for help, provide the people helping with the compiler error. Most of the time someone with an experience can provide a ton of help just by seeing that output.

I highly suggest that you start to learn how to read the errors that a compiler is giving you. It will save you a ton of time if you can start understanding what it is actually telling you. One hint is to always start at the first error. More than likely, by cleaning up the first error you will inherently fix some of the ones below it.

Now, on to the problems in this revision. Go back and compare your code to that in MattD's above. There are three major things that are different.

1. He has his objects as members of his class, not local variables in his constructor like you do.
2. Your constructor is taking a void argument. That isn't correct syntax. For constructors you need to have empty parenthesis following the classname (i.e RobotDemo())
3. C and C++ are case sensitive languages. Therefore your Start_Robot_Class is not the same as the macro that is actually defined START_ROBOT_CLASS
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Camera Code not Working in Autonomous? Mikesername Programming 6 28-01-2009 10:14
Any suggestions for Gyro displacement code? windell747 Programming 0 17-02-2008 16:03
Incrementation Code not working benhulett Programming 6 12-02-2007 17:39
easyc demo code not working sniggel Programming 5 28-01-2007 16:40
Camera code not working.... DemonYawgmoth Programming 5 11-02-2006 09:21


All times are GMT -5. The time now is 21:47.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi