- class Link
-
{
-
public:
-
// function to calculate DH parameter
-
double DHP()
-
{
-
int rows=4;
-
double **R = (double **) malloc(rows * sizeof(double *));
-
-
if (joint_type == 0)
-
{
-
// theta = q + joint_offset;
-
R[0][0] = cos(theta);
-
R[1][0] = sin(theta);
-
R[2][0] = 0.0;
-
R[3][0] = 0.0;
-
R[0][1] = -cos(alpha)*sin(theta);
-
R[1][1] = cos(alpha)*cos(theta);
-
R[2][1] = sin(alpha);
-
R[3][1] = 0.0;
-
R[0][2] = sin(alpha)*sin(theta);
-
R[1][2] = -sin(alpha)*cos(theta);
-
R[2][2] = cos(alpha);
-
R[3][2] = 0.0;
-
R[0][3] = a*cos(theta);
-
R[1][3] = a*sin(theta);
-
R[2][3] = d;
-
R[3][3] = 1.0;
-
}
-
else
-
{
-
// d = q +joint_offset;
-
R[0][0] = cos(theta);
-
R[1][0] = sin(theta);
-
R[2][0] = 0.0;
-
R[3][0] = 0.0;
-
R[0][1] = -cos(alpha)*sin(theta);
-
R[1][1] = cos(alpha)*cos(theta);
-
R[2][1] = sin(alpha);
-
R[3][1] = 0.0;
-
R[0][2] = sin(alpha)*sin(theta);
-
R[1][2] = -sin(alpha)*cos(theta);
-
R[2][2] = cos(alpha);
-
R[3][2] = 0.0;
-
R[0][3] = 0.0;
-
R[1][3] = 0.0;
-
R[2][3] = d;
-
R[3][3] = 1.0;
-
}
-
-
return(**R);
-
}
-
};
-
-
int main()
-
{
-
Link links[6] = { Link(0,90,0,0,-90,-160,160,10),
-
Link(0,0,149.09,431.8,0,-225,45,10),
-
Link(0,90,0,-20.32,90,-45,225,10),
-
Link(0,-90,0,0,-90,-110,170,10),
-
Link(0,0,0,0,90,-100,100,10),
-
Link(0,0,56.25,0,0,-266,266,10) };
-
double dhpl1[4][4], dhpl2[4][4],dhpl[4][4];
-
**dhpl1 = links[0].DHP();
-
**dhpl2 = links[1].DHP();
-
-
int i, j, k, val;
-
for (i=0; i<4; i++)
-
{
-
for (j=0; j<4; j++)
-
{
-
val = 0;
-
for (k=0; k<4; k++)
-
{
-
val += dhpl1[i][k] * dhpl2[k][j];
-
}
-
dhpl[i][j] = val;
-
}
-
}
-
-
cout << dhpl[1][1];
-
-
return(0);
-
}
<MODERATOR NOTE: Some code has been removed. See our FAQ for the reasons.>
no error in compiling and linking..but no output also..
please help
7 1435
Well, the DHP() function you are calling returns one double value, and this value is assigned to one spot in dhpl1 and dhpl2 - but then your loops try to add every element of dhpl1 and dhpl2 to dhpl. Maybe your DHP() function should be returning a double** rather than a double, so that the pointers in main() are assigned all the values generated in the DHP() function.
Also, please don't double post. The second thread you created on the same topic has been deleted.
thanks alot for ur response..
but i tried with changes but its not working..its returning garbage value..
can u please tell me where should i do changes to make it run...
about another thread..that was similar program without classes..
i was fed up with this program so i tried to write using functions..but it also didnt wok..please tell me where to change in the program...
Something I missed in the first run (thanks to Banfa for pointing this out) is that your initialization for R is incorrect. You properly set the rows of the array to double* pointers, but then you need to initialize each row (each double*) to an array of doubles. You can use a for loop and another malloc() call to do this.
Hello!
I initialized R as per the directions..
its linking without output...
Is initializtion is o.k.?
please help - class Link
-
{
-
public:
-
-
// function to calculate DH parameter
-
double DHP()
-
{
-
double rows=4; double **R ;
-
// double **R = (double **) malloc(rows * sizeof(double *));
-
for(int i=0;i<4;i++)
-
{
-
for(int j=0;j<4;j++)
-
R = (double **) malloc(rows * sizeof(double **));
-
}
-
-
if (joint_type == 0)
-
{
-
// theta = q + joint_offset;
-
R[0][0] = cos(theta);
-
R[1][0] = sin(theta);
-
R[2][0] = 0.0;
-
R[3][0] = 0.0;
-
// other such assignment statements...
-
}
-
else
-
{
-
// d = q +joint_offset;
-
R[0][0] = cos(theta);
-
R[1][0] = sin(theta);
-
R[2][0] = 0.0;
-
R[3][0] = 0.0;
-
// other such assignment statements...
-
}
-
return(**R);
-
}
-
};
-
-
int main()
-
{
-
Link links[6] = {
-
Link(0,90,0,0,-90,-160,160,10),
-
Link(0,0,149.09,431.8,0,-225,45,10),
-
Link(0,90,0,-20.32,90,-45,225,10),
-
Link(0,-90,0,0,-90,-110,170,10),
-
Link(0,0,0,0,90,-100,100,10),
-
Link(0,0,56.25,0,0,-266,266,10)
-
};
-
double dhpl1[4][4], dhpl2[4][4],dhpl[4][4];
-
**dhpl1 = links[0].DHP();
-
**dhpl2 = links[1].DHP();
-
-
-
int i, j, k;
-
-
for (i=0; i<4; i++)
-
{
-
for (j=0; j<4; j++)
-
{
-
dhpl[i][j] = 0;
-
for (k=0; k<4; k++)
-
{
-
dhpl[i][j] = dhpl[i][j] + dhpl1[i][k] * dhpl2[k][j];
-
}
-
-
}
-
}
-
-
-
cout << dhpl[0][0];
-
-
return(0);
-
}
Actually, R should be initialized using something like this: - R = (double**)malloc(/*ROWS * Size of a double**/);
-
for (/*EACH ROW*/) {
-
R[index] = (double*)malloc(/*COLS * Size of a double*/);
-
}
int rows=16, cols=16;
double **R ;
R = (double**)malloc(rows*sizeof(double *));
for( i=0;i<rows;i++)
{
R[i]= (double*)malloc(cols*sizeof(double));
}
this is how i initialized the R..
still its giving only garbage value as output..
I used vectors instead of pointer...
its working nicely..
thanks for all ur response
Sign in to post your reply or Sign up for a free account.
Similar topics
by: jrlen balane |
last post by:
basically what the code does is transmit data to a hardware and then
receive data that the hardware will transmit.
import serial
import string
import time
from struct import *
ser =...
|
by: Curt |
last post by:
If this is the complete program (ie, the address of the const is never
taken, only its value used) is it likely the compiler will allocate ram for
constantA or constantB? Or simply substitute the...
|
by: Ricky |
last post by:
thanks for the replysir.
i have made this code so far in declaring the NFA. In fact i do know what am
i supposed to do , i just cant get it right.
please have a look at the following code and tell...
|
by: Orgad |
last post by:
I wrote a simple program (in which I reused a data structure), but it
refuses to link. Can anyone here please help me?
Notice that Region2D.cpp IS in the compilation, and the "unresolved"...
|
by: tele-commuter |
last post by:
Hi folks,
I want to understand how exactly is an image(compiled
c code and loaded into memory) stored in memory.
What exactly is a linker script?
I work with a lot of c code on a daily...
|
by: scottyman |
last post by:
I can't make this script work properly. I've gone as far as I can with
it and the rest is out of my ability. I can do some html editing but
I'm lost in the Java world. The script at the bottom of...
|
by: Mike Kent |
last post by:
It's often useful for debugging to print something to stderr, and to
route the error output to a file using '2>filename' on the command
line.
However, when I try that with a python script, all...
|
by: sulekhasweety |
last post by:
Hi,
can any one give a brief outline of the different stages in the
execution of a C program , in terms of compilation, pre-processing,
linking etc
|
by: fido19 |
last post by:
Once upon a time, there lived a chimpanzee called Luycha Bandor (aka Playboy Chimp).
Luycha was unhappily married to Bunty Mona, a short but cute little lady chimp. Luycha
was tall and handsome –...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |