DC Motor with adjustment speed

This code is to control 2 DC motor with speed adjustment via manual joystick PS2.


while(1)
{

Left_val=ps_joy(add_ps,joy_ll);
Right_val=ps_joy(add_ps,joy_lr);

speedRy=ps_joy(add_ps,joy_ry);
if( ps_sw(add_ps,2)==0)
{

bh_1_brake(add_bh);
bh_2_brake(add_bh);
}

else
{
if (speedRy128)
{

speedRy=speedRy-128;
bh_1_cw(add_bh); // Run motor 1 in clockwise
bh_2_ccw(add_bh); // Run motor 1 in clockwise
}
else
{
speedRy=0;
}

if(speedRy>Left_val)
speedcountL=(speedRy<<1)-(Left_val<Right_val)
speedcountR=(speedRy<<1)-(Right_val<<1);
else
speedcountR=0;

bh_1_speed(add_bh,speedcountL); // motor 1 speed
bh_2_speed(add_bh,speedcountR); //motor 2 speed

}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: