Go to Post Making GP a rule would be the equivalent of making a law that says you have to help get kittens out of trees. - Molten [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 25-01-2005, 00:07
Alex Wijtowych Alex Wijtowych is offline
Registered User
#1419
 
Join Date: Jan 2005
Location: Courtice, Ontario
Posts: 3
Alex Wijtowych is on a distinguished road
Array Problems: Possible<stdio.h>

Hello, I would appreciate if anyone can help me out with this arrray statement. I'm not sure if I have to put it in a function or import a header library so I can use an array. Here is my code, also it is available to anyone who wants to use it. It uses one joystick to drive a a 2 wheel drive bot with the wheels in the centre, like a tank. It also solves the problem of having the joystick go forward and the bot turn and vice versa.

/*Alex Wijtowych's Little addition to the code to make a dual axis drive system with a smoother control!!!*/
/*Let PWM 09 represent the right wheel of the bot and PWM 10 represent the left wheel of the bot*/
int speed_array[255] ={0,0,0,0,0,0,0,4,8,12,16,20,23,27,30,34,37,40,43, 45,
48,51,53,56,58,60,63,65,67,69,71,73,75,76,78,80,81 ,83,84,86,87,88,90,91,
92,93,94,96,97,98,99,100,100,101,102,103,104,105,1 05,106,107,107,108,
109,109,110,111,111,112,112,113,113,114,114,114,11 5,115,116,116,116,
117,117,117,118,118,118,119,119,119,119,120,120,12 0,120,121,121,121,
121,121,122,122,122,122,122,122,123,123,123,123,12 3,123,123,124,124,
124,124,124,127,127,127,127,127,127,127,127,127,12 7,127,127,127,127,
127,127,127,127,127,127,127,130,130,130,130,130,13 1,131,131,131,131,
131,131,132,132,132,132,132,132,133,133,133,133,13 3,134,134,134,134,
135,135,135,135,136,136,136,137,137,137,138,138,13 8,139,139,140,140,
140,141,141,142,142,143,143,144,145,145,146,147,14 7,148,149,149,150,
151,152,153,154,154,155,156,157,158,160,161,162,16 3,164,166,167,168,
170,171,173,174,176,178,179,181,183,185,187,189,19 1,194,196,198,201,
203,206,209,211,214,217,220,224,227,231,234,238,24 2,246,250,254,255,
255,255,255,255,255,255};
if (p1_y > 127 )
{
if (p1_x > 127)
{
pwm09 = speed_array[255 - (2 *(p1_x - 127))];
pwm10 = speed_array[p1_y];
}
else if (p1_x < 127)
{
pwm09 = speed_array[255 - p1_y];
pwm10 = speed_array[255 - (2 *(127 - p1_x))];
}
else if (p1_x == 127)
{
pwm09 = speed_array[p1_y - 127];
pwm10 = speed_array[p1_y];
}
}
else if (p1_y < 127)
{
if (p1_x > 127)
{
pwm09 = speed_array[255 - (2 *(p1_x - 127))];
pwm10 = speed_array[p1_y];
}
else if (p1_x < 127)
{
pwm09 = speed_array[255 - p1_y];
pwm10 = speed_array[2 *(127 - p1_x)];
}
else if (p1_x == 127)
{
pwm09 = speed_array[127 + (127 - p1_y)];
pwm10 = speed_array[p1_y];
}
}
else if (p1_y == 127)
{
if (p1_x < 127)
{
pwm09 = speed_array[127 + (127 - p1_x)];
pwm10 = speed_array[p1_x];
}
else if (p1_x > 127)
{
pwm09 = speed_array[127 - (p1_x - 127)];
pwm10 = speed_array[p1_x];
}
else if (p1_x == 127)
{
pwm09 = 127;
pwm10 = 127;
}
}

Last edited by Alex Wijtowych : 25-01-2005 at 00:22.
  #2   Spotlight this post!  
Unread 25-01-2005, 01:08
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: Array Problems: Possible<stdio.h>

You may want to consider making your array a "rom const".
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...
  #3   Spotlight this post!  
Unread 25-01-2005, 09:04
Unsung FIRST Hero
Matt Leese Matt Leese is offline
Been-In-FIRST-Too-Long
FRC #1438 (The Aztechs)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1998
Location: Long Beach, CA
Posts: 937
Matt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond repute
Send a message via AIM to Matt Leese
Re: Array Problems: Possible<stdio.h>

You don't need to include anything or do anything special to use an array. It's just a variable like anything else.

Matt
  #4   Spotlight this post!  
Unread 25-01-2005, 12:01
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: Array Problems: Possible<stdio.h>

I had to change two things to make your code compile. First, I changed the array dimension to 256, since you have 256 initializer values. (Remember the range from 0 to 255 contains 256 values.)

I also had to change the array definition from "int speed_array" to "rom const int speed_array" as Mike suggested. Without the "rom const", the linker complained: "Error - section '.idata_user_routines.o' can not fit the section. Section '.idata_user_routines.o' length=0x00000208".

It would probably be possible to edit the .LKR file to make the data fit without making it "rom const", but this way is easier. There's no reason to sweat making data fit into RAM when the program will never change it.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
  #5   Spotlight this post!  
Unread 25-01-2005, 13:50
Ssbfalcon's Avatar
Ssbfalcon Ssbfalcon is offline
The beta version
AKA: Arthur
FRC #1546 (Chaos Inc.)
Team Role: Alumni
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Baldwin, New York
Posts: 8
Ssbfalcon is an unknown quantity at this point
Send a message via AIM to Ssbfalcon
Re: Array Problems: Possible<stdio.h>

Personally I would have come up with a formula to automate this for you.

Either way, you shouldn't use an integer array as the values range from 0-255. Because of that, all you need are unsigned chars, which range from 0 to 255.

Just incase you're unsure of the syntax...
Code:
 unsigned char speed_array[255] ={0,0, ... 255};
Ints normally use 2 bytes, while chars use 1 byte. The integer array of 256 would be 512 bytes while the char array only 256 bytes. That's one method of code optimization that you should look out for. It's easy to just write ints for everything, when all that's required is a char whether it's signed or unsigned. Remember that the system we're coding under has limited resources, and little things like these can mean cutting off an extra feature.

Still, if we had some more resources...
__________________
Don't Lick Dry Ice!
  #6   Spotlight this post!  
Unread 25-01-2005, 18:26
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Array Problems: Possible<stdio.h>

If a look-up table is semetric (meaning the values below 127 are just as low as the values above are high), then you can cut the table size in half.

Here's my code for it:
Code:
const rom signed char JOYSTICK_SMOOTHING[128] = 
{
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2,
2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 7, 7, 8,
8, 9, 9, 10, 10, 11, 11, 12, 13, 13, 14, 14, 15, 16, 17, 17,
18, 19, 20, 20, 21, 22, 23, 24, 25, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 48, 49,
50, 51, 53, 54, 55, 56, 58, 59, 61, 62, 63, 65, 66, 68, 69, 71,
72, 74, 75, 77, 78, 80, 81, 83, 85, 86, 88, 89, 91, 93, 95, 96,
98, 100, 102, 103, 105, 107, 109, 111, 113, 114, 116, 118, 120, 122, 124, 126
};

void Drive_Joystick(char Left, char Right)
{
	if(Left > 127)
	{
		Left_CIM = Left_Drill =  (128 + JOYSTICK_SMOOTHING[Left - 127]);
	}
	else
	{
		Left_CIM = Left_Drill = (127 - JOYSTICK_SMOOTHING[127 - Left]);
    }
    
//	Right_CIM = Right_Drill = Right;
   	if(Right > 127)
	{
		Right_CIM = Right_Drill =  (128 + JOYSTICK_SMOOTHING[Right - 127]);
	}
	else
	{
		Right_CIM = Right_Drill = (127 - JOYSTICK_SMOOTHING[127 - Right]);
    }
}
Note: Each side had 2 motors which always had to be the same value. They were named CIM and Drill (guess what kind they were). So Left_CIM and Left_Drill were the left-side motors and Right_CIM and Right_Drill were the right-side motors.

This could be reduced to a macro:
Code:
#define SMOOTHED_VALUE(joy) ( (128 + JOYSTICK_SMOOTHING[(((joy)>127) ? ((joy) - 127) : (127 - (joy)))]) )
(Macros are kinda like Perl one-liners: only the author really knows what's going on.)
  #7   Spotlight this post!  
Unread 25-01-2005, 23:14
Chris Bright's Avatar
Chris Bright Chris Bright is offline
Registered User
#1023 (Bedford Express)
Team Role: Webmaster
 
Join Date: Feb 2003
Rookie Year: 2003
Location: Temperance, MI
Posts: 54
Chris Bright will become famous soon enough
Send a message via AIM to Chris Bright
Re: Array Problems: Possible<stdio.h>

When the array is stored in the ROM does that mean the array has to be global? I had a smoothing function last year but i just called the array like so: motor1 = smooth[joy]; However, this year i wanted to put it in function and i kept getting errors saying the stack size was too large. I have a feeling this is due to a variable's scope in a function. Could i use static to place the variables in a function?
__________________
2003 - National Rookie All-stars
2003 - Great Lake Rookie All -stars
  #8   Spotlight this post!  
Unread 26-01-2005, 04:39
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: Array Problems: Possible<stdio.h>

Quote:
Originally Posted by Chris Bright
When the array is stored in the ROM does that mean the array has to be global?
No, it doesn't have to be global. If it's outside a function, it will have global scope by default. But you can restrict its visibility to the file only by assigning it "static" storage class. You can also hide the array inside a function. It compiled cleanly when I defined it as "static rom const unsigned char speed_array[256]..." inside a function. (Thank you Arthur(Ssbfalcon) for pointing out that all the data values in the array would fit in char sized elements.)
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
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
PC problems. . . opnickc IT / Communications 5 12-01-2005 16:53
Robot Rodeo - fixing control problems Gary Dillard Off-Season Events 7 26-10-2004 00:46
Do you all have problems with.... Munkaboo Website Design/Showcase 19 03-03-2003 19:51
Joystick problems archiver 2001 3 24-06-2002 02:40
Radio problems -- not archiver 2000 1 23-06-2002 22:23


All times are GMT -5. The time now is 03:07.

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