I am designing a Windows Phone 7 project where I need to determine position changes of the device. I tried to use accelerometer, but it gives info on current orientation of my phone and I don't know how to convert this data to position delta. Here is some example code:
void acc_CurrentValueChanged(object sender, SensorReadingEventArgs<AccelerometerReading> e)
{
AccelerometerReading newdata = e.SensorReading;
Vector3 vect = newdata.Acceleration - data.Acceleration;
//what comes here???
}
The method above is called when accelerometer data is changed. But I don't know how to convert this data to position change of a device (i.e. I move my phone in X direction)
You can't do it.
You get position by integrating the linear acceleration twice but the error is horrible. It is useless in practice.
See the above linked answer to get some ideas what you actually can do.
Related
The probelm I have is that I am trying to position a QGraphicsTextItem on a specific location of my QGraphicsScene , to be precise in the center of the speedometer below. But nothing I tried seems to work properly. Despite I clearly provided the coordinates I want the QGraphicsTextItem, it still anchored on top-left as shown below:
Below the snippet of code:
speedwidget.cpp
SpeedWidget::SpeedWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::SpeedWidget)
{
ui->setupUi(this);
mScene = new Scene(this);
ui->graphicsView->setScene(mScene);
io = new QGraphicsTextItem;
io->setPos(210,240);
QFont *f = new QFont;
f->setPointSize(18);
io->setFont(*f);
mScene->addText("Odometer :")->setDefaultTextColor(Qt::red);
mScene->addItem(io);
}
speedwidget.h
class SpeedWidget : public QWidget
{
Q_OBJECT
public:
SpeedWidget(QWidget *parent = nullptr);
~SpeedWidget();
private:
Ui::SpeedWidget *ui;
Scene *mScene;
QGraphicsTextItem *io;
};
#endif // SPEEDWIDGET_H
What I tried so far to solve the problem was:
I consulted this post which explained the idea but I don't need to change the background color in this example.
This one had a good snippet, but I am not trying to highlight the color. I am only trying to position the text on a specific location.
If I change io->setPos(210,240); and give different numbers, I still see it anchored on top-left.
Thanks for pointing to the right direction for solving this issue.
The Qt Graphics View framework implements a parent-child mechanism. Simply make your QGraphicsTextItem become a child of your odometer's dial item. From then on, your text label's position will be relative to the one of the dial:
io = new QGraphicsTextItem(this);
// Position text item so that it's centered on the dial
...
Furthermore, note that this line:
mScene->addText("Odometer :")->setDefaultTextColor(Qt::red);
Means that you create yet another text item. A pointer to the newly created item is being returned. Either use & retain that one or use the one that you explicitly created with the new expression.
Furthermore you might want to reconsider your choice of using a QGraphicsScene for one simple "widget". While the Qt graphics framework is not necessarily heavy, it certainly brings quite a lot of overhead for just rendering an odometer.
You can simply overwrite the QWidget::paint() function in your SpeedWidget subclass and render everything using QPainter. That will be a lot lighter and also a lot less hassle.
I need to implement a Tello command, which is rc a b c d on a virtual joystick. From different forums, I came to know that for virtual joystick, we need to use rc commands to move the Tello drone. But I don't know how to implement it. In their SDK documentation, they have mentioned it as
a:left/right (-100~100) b: forward/backward (-100~100) c: up/down (-100~100) d: yaw (-100~100)
What do these negative values mean? How can I use the rc command to move the drone?
This is the virtual joystick code which I am using:
JoystickView joystick = (JoystickView) findViewById(R.id.joystickView);
joystick.setOnMoveListener(new JoystickView.OnMoveListener() {
#Override
public void onMove(int angle, int strength) {
// code goes here
}
});
The values -100~100 normally are the velocity for their respective axis. Depending on the coordinate system set and the control modes for the axes, the aircraft move along the axis corresponding to the value. Based on the code you provided I assume the strength value represents the percentage how much the stick is pushed/shifted and the angle value shows the direction into which the stick is pushed.
For the virtual Sticks you need to set the Control modes and coordinate system by accessing the flight Controller:
setRollPitchControlMode(RollPitchControlMode.VELOCITY);
setYawControlMode(YawControlMode.ANGULAR_VELOCITY);
setVerticalControlMode(VerticalControlMode.VELOCITY);
setRollPitchCoordinateSystem(FlightCoordinateSystem.BODY);
The modes chosen above ensure that the virtual controller behaves the same as the default physical remote controller.
Additionally you need to activate the virtual Sticks with the setVirtualStickModeEnabled method before you can use them.
Now for the continuous control over the aircraft you need to send the virtualStickData with at least 5 Hz:
SendVirtualStickDataTask task = new SendVirtualStickDataTask();
this.timer = new Timer();
this.timer.schedule(task, 0, 200);
In this example SendVirtualStickDataTask extends TimerTask and only sends the current pitch, roll, yaw, and vertical throttle values to the drone via the sendVirtualStickFlightControlData method from DJI SDK inside the run() method of TimerTask.
Finally the current pitch, roll, yaw, and vertical throttle values are set inside your onMove() method you posted in your question. E.g. you can use the trigonometric functions sin and cos to determine the x- and y- parts of the strength value, something like this:
pitch = Math.cos(angle)*strength;
roll = Math.sin(angle)*strength;
Please note that the angle needs to be radian and you probably need to cast the angle/strength to float. Furthermore depending on how the angle value is determined you need to adjust the value accordingly.
The second joystick can be used to control the vertical throttle and the yaw. you will need a bit of fine-tuning and testing.
For the control modes/coordinate system, the following DJI SDK Documentation is helpful (scroll down to "Virtual Sticks"):
https://developer.dji.com/mobile-sdk/documentation/introduction/component-guide-flightController.html
DJI also has a basic code example for the virtual Sticks usage:
https://developer.dji.com/mobile-sdk/documentation/android-tutorials/SimulatorDemo.html
I highly recommend using the DJI Flight Assistant 2 Software to test your code before you attempt to fly in the real world.
I am trying to develop a mobile application using DJI Mobile Android SDK. The goal of the application is navigate a Mavic 2 Pro to a target GPS coordinates and automatically center a camera on a vehicle and take a snapshot. After taking off and flying to target altitude a new tracking mission in spotlight mode is called to find an object and center a camera on it.
The first process goes normally after an aircraft is turned on and the mobile application runs the missions. The aircraft is landed manually.
The second trial with the mobile application goes wrong. There is an additional yaw motion that is not in time line mission. I have missed some cleaning method that reset the aircraft to an initial clean state probably.
How to setup the aircraft to a clean state before the application starts the missions please?
I don't understand why there is a yaw 45° motion in a simple
time line mission:
missionControl.scheduleElement(new TakeOffAction());
missionControl.scheduleElement(new GoToAction(2.0f));
missionControl.startTimeline();
Why the aircraft yaw 45° after the takeoff while it is lifting to target
altitude? It's to see https://youtu.be/-gCWFXou-WI
You never share any other code. so below is my list of guess/checklist for a possible solution.
First, clear all other code, e.g disable drone yaw following or any other possible routing with the keyword of tracking/following etc from both code and remote controller screen
The easiest way to check if it caused by this is to call
elements.add(new GoToAction(new LocationCoordinate2D(homeLatitude+0.00001, homeLongitude+0.00001), 5));
elements.add(new GoToAction(new LocationCoordinate2D(homeLatitude-0.00001, homeLongitude-0.00001), 5));
if the camera still follows you while at a multiple location. Then sth at tracking is bothering you. If follow it could be caused by home lock also
Secondly, GoToAction never mentions about the orientation but only 3D position. Theoretically, they can do anything they want. so check API for all orientation method/setting e.g
Use setFlightOrientationMode to set course lock or home lock to get your desired behavior.
method setFlightOrientationMode
void setFlightOrientationMode(#NonNull FlightOrientationMode type,
#Nullable CompletionCallback callback)
Package: dji.sdk.flightcontroller
SDK Key: FlightControllerKey.ORIENTATION_MODE
Description:
Sets the aircraft flight orientation relative to the Aircraft Heading, Course Lock, or Home Lock. See the Flight Controller User Guide for more information about flight orientation.
Last I assume you removed all other possible following modes and it is still not behave according to your wish.
The api given is
GoToAction(LocationCoordinate2D coordinate)
GoToAction(float altitude)
float altitude Target altitude in meters.
GoToAction(LocationCoordinate2D coordinate, float altitude)
If the direct setting altitude has an issue. Can you try the full command to determine it is a bug in the source code or it is sth else
double homeLatitude = get your start gps lat;
double homeLongitude = get your start gps long;
elements.add(new GoToAction(new LocationCoordinate2D(homeLatitude, homeLongitude), 2));
If you are sure that you have no other routing that bothers the drone, and both GoToAction(float altitude) and GoToAction(LocationCoordinate2D coordinate, float altitude) has the same yaw problem. open a ticket in dev#dji.com.
Personally, I don't think it is DJI`s issue. Because you never post the full code so I have no idea what you have done or you haven't have done but should have done. So good luck in finding the solution to your unwanted behavior.
In my app for WP7.5, user can navigate into the university. He can see on the map his initial position acquired by scanning a Qr Code. Map image is Canvas background. Once he chooses the destination whose X and Y coordinates are known, how can I draw on the map the route from user's current location to the destination? I don't know if it is possible.
This is the working code that allows to show user's starting position on the map.
public void MarkLocation(ImageBrush imgmap, int posizioneX, int posizioneY)
{
Canvas.Background = imgmap;
Image imgmarker = new Image();
imgmarker.Source = new BitmapImage(new Uri("Images/marker.png", UriKind.Relative));
Canvas.SetLeft(imgmarker, posizioneX);
Canvas.SetTop(imgmarker, posizioneY);
Canvas.Children.Add(imgmarker);
}
I hope you can help me! Thanks in advance.
If you used the BingMapsDirectionsTask (in WP7) or the MapsDirectionsTask (in WP8) and the user will get a full navigation experience including showing the route and you'll not need to worry about dynamically generating images or overlaying items on a Map control.
I am designing a minesweeper kind of layout for a game in silverlight. Currently, I have used a square user control on the Canvas control. There are properties assigned to it.
I also want to add a functionality at a later stage. It is about curving using the bezier curves and plotting those squares on the curve with the x,y co-ordinates instead of looping through. Then I want to send the square's x,y position in an XML file.
My question is that what way should I use that will be the best optimized combination in terms of least memory consumption, fast and efficient performance as well as easy implementation.
If you experts have any other ideas, please let me know.
Thanks in advance.!
If you can draw everything as shapes and images (i.e. vector graphics) and you'll be able to take advantage of the hardware acceleration for the graphical elements. Also, you'll get better performance if you don't define your squares as UserControls, you should be creating them dynamically in code as shapes containing other shapes and then have an object model that is linked to the shapes based on their position (e.g. Dictionary squares; Dictionary squareElements).
In terms of memory consumption and file access you should keep the square's x,y position in memory as a Point strucutre and serialize to file (XML is fine) only when you need to (i.e. when the player leaves the game).
Well, over the days, I sorted out the answer myself. I continued through my Square user control and used it in the layout.
About plotting of the x/y positions, I used this:
Point point = myElement.TransformToVisual(App.Current.RootVisual as FrameworkElement)).Transform(new Point(0, 0));
There was a glitch in saving XML file because silverlight 4 does not give elevated privileges for in-browser application. But then I used this on my save button click event:
SaveFileDialog dlgSave = new SaveFileDialog();
dlgSave.DefaultExt = "xml";
dlgSave.Filter = "XML Files (XML)|*.xml;";
dlgSave.FilterIndex = 1;
strXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + myXML.ToString();//myXML is the XDocument I created globally and saved data in it
try
{
bool check = (bool)dlgSave.ShowDialog();
if (check)
{
using (Stream stream = dlgSave.OpenFile())
{
StreamWriter sw = new StreamWriter(stream, System.Text.Encoding.UTF8);
sw.Write(strXML);
sw.Close();
stream.Close();
}
MessageBox.Show("XML Saved successfully");
}
catch (SecurityException)
{
MessageBox.Show("There seems to be an issue with saving XML file on the disk, please try again...", "Something's not right", MessageBoxButton.OK);
}
catch (UnauthorizedAccessException)
{
MessageBox.Show("Saving here requires authorised permissions", "Access Denied", MessageBoxButton.OK);
}