mav and motor commands

9 replies [Last post]
Tim Ellis
Title: NooBot
Joined: 12/15/2014
Posts:
BotPoints: 10
User offline. Last seen 2 years 46 weeks ago.

I am having trouble changing the speed at which the motor moves using the mav command. If I just use the mav command the motor does not move. If I include the motor command the motor moves but I cannot very the speed. Below is a code snipit. I have firmware version 2.0.3 in the link module and KISS Version 5.1.2 "Lithium"

#define POWER 100 // 100 to 0
#define SPEED 500 // 1000 to 0
#define TRAVEL_TOP 200
#define TRAVEL_BOTTOM 850
#define MOTOR0 0
printf("We will now move the motors\n");
printf("Press button A to start and stop the motor\n");

set_pid_gains( MOTOR0, 30, 0, -30, 70, 1, 51 );

vWaitForTopButtonPress();

mav(MOTOR0, SPEED);
motor(MOTOR0, POWER); // turn motor power to full

Any suggestions would be appreciated.
-tim

ruler501
ruler501's picture
Title: NooBot
Joined: 01/29/2012
Posts:
BotPoints: 367
User offline. Last seen 2 years 31 weeks ago.

My guess would be the problem lies in your set_pid_gains call. Try without it and see if you get the same problem

Tim Ellis
Title: NooBot
Joined: 12/15/2014
Posts:
BotPoints: 10
User offline. Last seen 2 years 46 weeks ago.

I originally did not have the set_pid_gains call in. I do not know the history of the LINK controller and I thought the autotuning of the PID had been run. In any case with or without the set_pid_gains call in it does the same thing. The values I used for the set_pid_gains came from the online documentation.

Does the autotuning of the PID coefficients work? Is there a way to set them back to the factory defaults if the ones in the manual were not correct?

bonnienichols
Title: NooBot
Joined: 03/07/2014
Posts:
BotPoints: 52
User offline. Last seen 1 year 37 weeks ago.

I think you should have to check your code again, may it contain some bugs or you have missed something.

aussie slot machines

ruler501
ruler501's picture
Title: NooBot
Joined: 01/29/2012
Posts:
BotPoints: 367
User offline. Last seen 2 years 31 weeks ago.

Could you give us your whole test program?

Tim Ellis
Title: NooBot
Joined: 12/15/2014
Posts:
BotPoints: 10
User offline. Last seen 2 years 46 weeks ago.

// Created on Sat December 13 2014
#include
void vMoveMotors();
void vMoveServos();
void vMotors();
void viRobot();
void vWaitForTopButtonPress();

#define MOTOR0 0
#define MOTOR1 1
#define FALSE 0
#define TRUE 1
int main()
{

printf("Hello, World!\n");

// vMoveMotors();
// vMotors();
// vMoveServos();
viRobot();

return 1;
}
void vMotors()
{
#define POWER 100 // 100 to 0
#define SPEED 500 // 1000 to 0
#define TRAVEL_TOP 200
#define TRAVEL_BOTTOM 850
printf("We will now move the motors\n");
printf("Press button A to start and stop the motor\n");

set_pid_gains( MOTOR0, 30, 0, -30, 70, 1, 51 );

vWaitForTopButtonPress();

mav(MOTOR0, SPEED);
motor(MOTOR0, POWER); // turn motor power to full

while(analog(2) > TRAVEL_TOP)
{
printf("1. Slider position %d\n",analog(2));
}

printf("Stop motor\n");
mav(MOTOR0, 0);

// Open and close the jaws
enable_servos(1);
set_servo_position(1, 2000);
msleep(1000);
set_servo_position(1, 100);
msleep(1000);
set_servo_position(1, 2000);
msleep(1000);

mav(MOTOR0, -1*SPEED);
motor(MOTOR0, -1*POWER); // turn motor power to full
// mav(MOTOR0, -1*SPEED);
while(analog(2) < TRAVEL_BOTTOM)
{
printf("2. Slider position %d\n",analog(2));
}
printf("Turn motor off\n");
mav(MOTOR0, 0);
off(MOTOR0);

}

void vMoveMotors()
{
int inches=12, ticks;//inches: distance to travel,
int d=2; //d= diameter of wheel

int iVelocity0 = 1000; //Range 0 - 1000
// int Motor1 = 3;
ticks = (inches/(3.14159*d)*1100); //1100 ticks in circum
ticks = 1100;

clear_motor_position_counter(0);
clear_motor_position_counter(3);

//not sure if this sets power or sets power and turns on motor
motor(MOTOR0, 100); // turn motor power to full
mrp(MOTOR0,iVelocity0,ticks);
//move_to_position(Motor1,300,ticks);
bmd(MOTOR0);
//bmd(Motor1);
printf("Moved forward\n");
// tone(2000, 1);

msleep(1000); //Sleep for 1000 msec

mrp(MOTOR0,iVelocity0,-1100);
//move_to_position(3,300,0);
bmd(MOTOR0);
//bmd(3);
printf("Moved back\n");
// beep();
// beep();

}
void vMoveServos()
{
printf("enable servos\n");
enable_servos(1);
printf("Press B button to open. \nPress A button to close\nPress button C to exit\n");
while(!c_button())
{
if(b_button()) //wait until b_button is pressed
{
printf("You pressed the B button\n");
set_servo_position(1, 200); //Open left claw

msleep(2000);
set_servo_position(1, 2000); //Open left claw
while(b_button())//Wait for b_button to not be pressed
{
msleep(10);
}

}

if(a_button())//Wait until a_button is pressed
{
printf("You pressed the A button\n");
set_servo_position(1, 1800); //Open left claw
printf("Servo position is %d\n",get_servo_position(1));
while(a_button())//Wait for a_button to not be pressed
{
msleep(10);
}
}
printf("Slider position %d\n",analog(2));
printf("Black button position %d\n", black_button());

}
}
void viRobot ()
{
int iBatteryCapacity;
int iCurrentBatteryCharge;
iBatteryCapacity = get_create_battery_capacity();
iCurrentBatteryCharge = get_create_battery_charge();
if( (iBatteryCapacity - (iBatteryCapacity * 0.9)) > iCurrentBatteryCharge)
{
printf("iRobots batter is too low\n");
return;
}

#define SPIN_SPEED 100 //speed of speed of -500 to 500mm/sec.
printf("Press top button to start iRobot\n");
vWaitForTopButtonPress();
printf("starting robot\n");
create_connect();
msleep(1500); // Wait for the connection to complete
// create_start();
// create_spot();
create_spin_CW(SPIN_SPEED); //speed in mm/sec
msleep(3000);
create_stop();
create_disconnect();
printf("disconnecting from Create\n");
}
void vWaitForTopButtonPress()
{
while(black_button()==0)
{
msleep(10);
}
}

geogr0ot
Title: NooBot
Joined: 07/21/2017
Posts:
BotPoints: 6
User offline. Last seen 20 weeks 4 days ago.

I think it is a good idea if we will see the whole test program.
music mix promotion

jonny
Title: NooBot
Joined: 07/22/2017
Posts:
BotPoints: 2
User offline. Last seen 20 weeks 4 days ago.

All you have to do is click the reply button, post something like "I would be glad to have a copy" and then also please include the reason you are asking for a copy. Even though you are considered to be good at programming, you can still say "I could use it for reference" or "I want to make sure best professional cv I am doing things right". There is really no right or wrong answer.

Axwell
Title: NooBot
Joined: 09/04/2017
Posts:
BotPoints: 6
User offline. Last seen 14 weeks 2 days ago.

The generator can give you much more gems. clash royale cheats

linming0303
Title: NooBot
Joined: 10/26/2017
Posts:
BotPoints: 10
User offline. Last seen 6 weeks 1 day ago.

Since hard to explain the problem before we see the whole steps.Here to show you a web to browse various clothes,shoes for women and men.