[SOLVED] Yaw angle control (FW implementation)

Firmware/software/electronics/mechanics
Post Reply
roeiz
Beginner
Posts: 6
Joined: Thu Dec 06, 2018 1:22 pm

[SOLVED] Yaw angle control (FW implementation)

Post by roeiz » Mon Aug 19, 2019 1:01 pm

Hello dear crazyfliers!

I'm trying to rotate (yaw rotation that is) my crazyfly 2.0 through UART messages received from an external microcontroller.

So far I was able to receive the UART messages, and even change vx, vy, z and yawRate using the setHoverSetpoint function that I've found in this post (code below)
The problem is, when I'm changing this line

Code: Select all

setpoint->mode.yaw = modeVelocity;
with this one

Code: Select all

setpoint->mode.yaw = modeAbs;
and then sending the crazyfly a command to rotate to a certain angle instead of rotating in a certain speed, *nothing happens.
(*When sending the first position command - that is from resting to hovering, it does rotate, but then when sending more rotation commands it won't move)

It almost seems like the crazyfly is trying to rotate but something is holding it back. Trying to go over the code did not yield much, but I think there is another control mechanism that prevents me from using yaw in absolute mode.

Did anyone experience such problems when setting setpoints or does anyone have a lead of what else do I need to change/write in order to use setpoints with yaw as an absolute angle?

setHoverSetpoint code:

Code: Select all

static void setHoverSetpoint(setpoint_t *setpoint, float vx, float vy, float z, float yaw)
{
  setpoint->mode.z = modeAbs;
  setpoint->position.z = z;


  setpoint->mode.yaw = modeAbs;
  setpoint->attitudeRate.yaw = yaw;


  setpoint->mode.x = modeVelocity;
  setpoint->mode.y = modeVelocity;
  setpoint->velocity.x = vx;
  setpoint->velocity.y = vy;

  setpoint->velocity_body = TRUE;
}
My task that is using setHoverSetpoint to rotate the crazyfly:

Code: Select all

static void spinTask(void *var)
{

	int i = 0;
	volatile float newYaw = 0;
	char angle[] = "000\n\r";
	systemWaitStart();

	while (1)
	{
		char *pAngle = &angle[0];
			i = uart1Getchar(pAngle);
			while (*pAngle != 13) {
				i = uart1Getchar(++pAngle);
			}

				newYaw += 10;
				setHoverSetpoint(&setpoint, newVx, 0, 0.2, newYaw);
				commanderSetSetpoint(&setpoint, 3);

	}
}
Both of these are written in the same file, with setpoint being a global variable in that file:

Code: Select all

static setpoint_t setpoint;
Thanks a lot in advance,
Roei

*Edit: It turns out that all I had to do was changing

Code: Select all

setpoint->attitudeRate.yaw = yaw;
to

Code: Select all

setpoint->attitude.yaw = yaw;



Post Reply