0
@Override
public void onIrEvent(IREvent e) {
    // TODO Auto-generated method stub

}


ardrone.addAttitudeUpdateListener(new AttitudeListener() {
        @Override
        public void attitudeUpdated(float pitch, float roll, float yaw, int altitude) {
        System.out.println("altitude : " + altitude);
        }
    });

i want to take the variables altitude from the second constructor and use it in the first constructor. I tried to use it directly and it didnt work. I also tried to construct the 2nd constructor inside the 1st one, but also didn't work. any idea?

thanks before

2 Answers 2

1

create a new class that implements AttitudeListener. Have a instance variable altitude with setter and getter method for the altitude and use it accordingly in your first and second constructor.

Example : in AttitudeListenerImpl.java

class AttitudeListenerImpl implements AttitudeListener
{
    private int altitude;
    public void setAltitude(int altitude)
    {
        this.altitude = altitude;
    }
    public int getAltitude()
    {
        return this.altitude;
    }
    @Override
    public void attitudeUpdated(float pitch, float roll, float yaw, int altitude) 
    {
        setAltitude(altitude);
        System.out.println("altitude : " + altitude);
    }
}

Usage in your other code:

AttitudeListener alti = new AttitudeListenerImpl();
alti.attitudeUpdated(1.0f,1.0f,1.0f,1);
ardrone.addAttitudeUpdateListener(alti);

@Override
public void onIrEvent(IREvent e) 
{
        // TODO Auto-generated method stub
        //to get the altitude:
         System.out.println("altitude : " + alti.getAltitude()); 

}
Sign up to request clarification or add additional context in comments.

2 Comments

where should i put this? main constructor? AttitudeListener alti = new AttitudeListenerImpl(); alti.attitudeUpdated(1.0f,1.0f,1.0f,1); ardrone.addAttitudeUpdateListener(alti);
It depends on what you are trying to achieve!
0

I don't see any constructor here. Are you talking about AttitudeListener? In this case, you would need to create a class implementing this interface.

What you could do then is constructor chaining, like for example:

public class MyAttitudeListener implements AttitudeListener
{
    public MyAttitudeListener()
    {
        this(3); // this is like new MyAttitudeListener(3);
    }
    public MyAttitudeListener(int altitude)
    {
        // do some work
    }        
}

Could you explain further what goal you're trying to achieve?

1 Comment

trying to control a quadcopter using wiimote. i need that altitude variables for the controls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.