# Formula to code

hey there,

I'm trying to build a ROS node for mecanum wheel based robot with PID.

therefore i need to calculate V * cos and V * sin

when i create an int for the V and a name for the outcome like so

``````int V = 140;

int Vx = (V * sin);
int Vy = (V * cos);

``````

it compiles with this error

invalid operands of types 'int' and 'double(double)' to binary 'operator*'

I read some about it but but i can't find a good explanation of how to figure out witch integer to use.
any help would be highly appreciated

sin is a function

I suspect that the reason is that sin and cos are existing functions and you don't use them like that. Below demo code does not throw the error that you have.

``````void setup()
{
int V = 140;

int Vx = (V * sin(3.14));
int Vy = (V * cos(3.14));
}
``````
1 Like

thanks! i didn't knew that

This works!

``````void set()
{
int V = 140;

int Vx = (V * sin(3.14));
int Vy = (V * cos(3.14));

int FRW = (Vx + Vy);
int FLW = (Vx - Vy);
int BLW = (Vx + Vy);
int BRW = (Vx - Vy);
}
``````

thanks a lot!

Since sin(PI) and cos(PI) are known values (0 and -1) you could skip the math and just use:

``````  int FRW = -V;
int FLW = V;
int BLW = -V;
int BRW = V;
``````

Did you, perhaps, ever want to travel at an angle other than 180° (Pi radians)? If so, you should translate the angle to radians (angle * PI/180) and pass that to sin() and cos().

Thank you John!

In this case the sketch is for an omnidirectional driving system. It has to be able to travel in every degree.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.