Mission Timeline Problem, only Take Off Command executed - java

I'm trying to move my drone through a set of 2D coordinates like my code below
However, after I pressed the start timeline button, the drone only took off and didn't move to any point
I don't know what happens with my code right now as I've tried to follow DJI Sample Code for the MissionControl part
Please have a check a help me with this
Thanks in advance
Here is my code
private void initTimeline()
{
List<TimelineElement> elements = new ArrayList<>();
mMissionControl = MissionControl.getInstance();
final TimelineEvent preEvent = null;
MissionControl.Listener listener = new MissionControl.Listener()
{
#Override
public void onEvent(#Nullable TimelineElement TimelineElement, TimelineEvent event, DJIError error)
{
updateTimelineStatus(TimelineElement, event, error);
}
};
showToast("Initialize Time Line System");
elements.add(new TakeOffAction());
GoToAction set_altitude = new GoToAction(new LocationCoordinate2D(0,0),2);
elements.add(set_altitude);
GoToAction go_2 = new GoToAction(new LocationCoordinate2D(1,1),2f);
elements.add(go_2);
GoHomeAction go_home = new GoHomeAction();
elements.add(go_home);
mMissionControl.scheduleElements(elements);
mMissionControl.addListener(listener);
}
private void startTimeline()
{
showToast("Start Time Line");
mMissionControl.getInstance().startTimeline();
}
private void stopTimeline()
{
showToast("Stop Time Line");
mMissionControl.getInstance().stopTimeline();
}

I believe that I answered you in email but I see a few issues in your code:
The GoToAction is telling the aircraft to move to location 0, 0 (latitude/longitude) at a elevation 2 meters.
There are a few issues with this move.
First, unless you are flying at location 0, 0 (or very near the location) then the aircraft will return an error similar to "TOO_FAR, indicating the move is beyond the flight distance limits.
The second issue is the altitude, I believe there is a minimum altitude allowable but I'm not certain.
Are you really flying in the middle of the Atlantic, at location 0, 0? If you are not, I suggest trying a GoToAction with a location nearer to where you are taking off. The sample shows a calculation to move 3m and I suggest you could use that and calculate a location 3m away from takeoff (using the aircraft's home location and moving from that).
Also, the mission listener will report errors (the last parameter DjiError) reports any issues with the timeline; when not null, I suggest logging the error and it will inform you what the problem is and make correction easy.
Best of luck!

Related

FRC Java Mecanum Drive

I am the programmer for my FRC Team 4468 and we are using mecanum wheels this year. We are trying to control the robot with two joysticks, one for moving in a direction (mecStick), and another for rotation (rotStick) using this line of code.
myDrive.mecanumDrive_Cartesian(mecStick.getX(), mecStick.getX(), rotStick.getY(), 0);
The robot will move in the Y direction (fowards, backwards), and will rotate but won't move in the X axis. Could someone tell me what i'm doing wrong please.
Thanks :-)
public class RobotTemplate extends SimpleRobot {
RobotDrive myDrive = new RobotDrive(1,2,3,4);
Joystick mecStick = new Joystick(1);
Joystick rotStick = new Joystick(2);
public void robotInit() {
}
public void autonomous() {
}
public void operatorControl() {
//myDrive.setSafetyEnabled(true);
myDrive.mecanumDrive_Cartesian(mecStick.getX(), mecStick.getX(), rotStick.getY(), 0);
Timer.delay(0.01);
}
}
Looks like you pass mecStick.getX() twice, one should probably be mecStick.getY(). I'm not familiar with the RobotDrive class, so I'm not sure which should be switched. The WPILib Javadoc is your friend, you can find a copy hosted by team 2168 at http://team2168.org/javadoc/. Look for RobotDrive on the left bottom list, and check there.
Best of luck from 1902, Exploding Bacon!

How to properly dump ArrayList/RAW-drawn-image memory in Android?

I am (still) working on a game, and as it nears completion, new problems arise. So here's the short story:
After fixing a few bugs and implementing new features, I may -or may not, have run into a small 'memory' issue. Each level has a set amount of time that the player has to solve it. When this time runs out, the level reloads. It is after this reloading, be it after failing to solve a level in time or after completing a level, that the game gradually starts slowing down. My timer ticks every second, the level reloads at the same speed, but when moving objects after X-reloads, they move more sluggish/laggish, as if skipping frames.
I have looked at my ArrayLists, and they are neatly (up for debate) empties, and my Timers are reset aswel. Below is some of the (relevant) code I'm using:
OnTick() in my Update-timer
MoveObjects() moves all objects, updateDraw() updates the screen. This timer has a 15x1000ms timer with a 250ms tickspeed
public void onTick(long millisUntilFinished) {
if(!loadingNewLevel)
MoveObjects();
updateDraw();
}
prepareNewLevel
This function prepares all necessary variables for a new level. It is called at both a level-reset and a level-completion
public void prepareNewLevel(){
level.clear();
movables.clear();
totalSolved = 0;
solvable = 0;
levelWidth = 0;
levelHeight = 0;
allCollided = false;
}
updateDraw(); refreshes the screen
public void updateDraw(){
RelativeLayout rl = (RelativeLayout)findViewById(R.id.game);
rl.removeAllViewsInLayout();
//Level
for(GameObject go : level){
ImageRAW(go.spriteID, R.id.game, go.position.x, go.position.y);
}
for(GameObject go : movables){
ImageRAW(go.spriteID, R.id.game, go.position.x, go.position.y);
}
//Timer
if(remaining_time >= 10000)
TextViewRAW(TIMER_ID, R.id.game, 32, 32, "00:"+String.valueOf(remaining_time/1000)+" Level "+String.valueOf(currLevel+1), 18, 0);
else
TextViewRAW(TIMER_ID, R.id.game, 32, 32, "00:0"+String.valueOf(remaining_time/1000)+" Level "+String.valueOf(currLevel+1), 18, 0);
}
Now, the latter piece of code I posted is why I surmise something is wrong with my memory-management, as I am directly drawing on to the screen from my RAW folder. How do I handle the memory of directly-drawn RAW files, if this is the case?
I will also give you access to some of the relevant Java files:
https://www.dropbox.com/s/kqu7sfi8qnlt9w6/Game.java?dl=0
https://www.dropbox.com/s/9ofpg1xj4anlvi0/UtilLib.java?dl=0
The latter of these files contains functions I'm using throughout the project, such as the ImageRAW() function mentioned earlyer.
-Zubaja

Android AndEngine score += 1 error increases a lot

I am creating sprites that get saved into a list called listSprites each sprite that touches a line (line3) that I made gets detached from the screen. What I want is when It gets detached (collides with line3) the score increases only 1, but now it increases a lot like it reacher 10,218 in 1 minute, once a sprite collides with the line it detaches and the score starts increasing without stopping even though no sprite is coliiding with it.
/* The actual collision-checking. */
mScene.registerUpdateHandler(new IUpdateHandler() {
#Override
public void reset() { }
#Override
public void onUpdate(final float pSecondsElapsed) {
} for(Sprite s: listSprites){
if (s.collidesWith(line3)){
mScore += 1;
mScene.detachChild(s);
mText.setText(" "+mScore+"");
}
}
}
});
}
It looks like collidesWith() doesn't care whether the child is attached or not. If that's the case, and you don't want to remove the sprite from listSprites, you need to check each sprite in the list to see if it's attached in addition to the collision check.
I haven't used andengine much, but from looking at the source and examples, it looks like you could just do something as simple as changing:
if (s.collidesWith(line3)){
to:
if (s.hasParent() && s.collidesWith(line3)){
hasParent() should return false if the sprite is not attached to anything, so check for that.
This assumes that you're not attaching the sprites to a different scene in the meantime.

Slick2d, How can i draw a string on screen for a few seconds?

I've been trying to figure this out, all I want to do is be able to draw a string for longer than just a frame, but when I call it in the method I want it to flash up then disappear immediately, any advice would be appreciated :) I'm using something like this:
g.drawString("You got a Key!", 100, 100);
I'm doing this in a method which is called after an Item is picked up
public void addItemFound(Graphics g){
ip.mainInventory[ip.getFirstEmptyStack()] = getItemStackFound();
System.out.println(this.getItemFound() + " added");
g.drawString("You Got a Key!", 100, 100);
}
That's the full method if you were interested :) Thanks!Also apologies for the dumb question, i'm a newbie to this :P
I believe that the best way to do this project would be to draw the scene at regular intervals e.g. 10 milliseconds using a Thread.sleep(). This way, you can simply add a variable to show the message for, say, 100 loops (1 second) like this:
private LinkedList<String> drawStringList= new LinkedList<>();
private LinkedList<Integer> drawStringTimeout= new LinkedList<>();
private LinkedList<Integer[]> drawStringPos= new LinkedList<>();
public void addText(String stringToWrite, int posX, int posY, int timeOut) {
drawStringList.add(stringToWrite);
int[] pos = new int[2];
pos[0] = posX;
pos[1] = posY;
drawStringPos.add(pos);
drawStringTimeout.add(timeOut);
}
private void mainLoop() {
...items to be drawn here...
for(int i=0;i<drawStringList.size();i++){
g.drawString(drawStringList.get(i),drawStringPos.get(i)[0],drawStringPos.get(i)[1]);
drawStringTimeout.set(i,drawStringTimeout.get(i)-1);
if(drawStringTimeout.get(i)<=0) {
drawStringList.remove(i);
drawStringTimeout.remove(i);
drawStringPos.remove(i);
}
}
try { Thread.sleep(10); } catch (Exception e) {}
}
In this code, you must add the string you want to draw to drawStringList, add the number of loops you want it to stay for to drawStringTimeout and add the position you would like to draw it in to drawStringPos as an array (you could use a point if you wanted to). I have made a method to do this.
I don't know what Dan300 is trying to tell you to do but that's way, way, way over complicated. Slick2D works on gamestates:
http://slick.ninjacave.com/javadoc/org/newdawn/slick/state/GameState.html
The gamestate has a method called render(). The render() is called every single cycle of the loop to update your screen with drawing information. If you want to draw the text on the screen for a longer time you should be drawing the text somewhere within the stack space of this render() function.
What is happening now is you have a function with one specific purpose that only exists every so briefly: add an item to the player. The game comes across this statement and when adding an item within that 1 cycle the text will be drawn. But the next cycle when the player isn't picking up an item it won't come by that drawString statement and you won't have your string on your screen longer than 1 game cycle.

Has anyone done crosshairs that follow the mouse in JFreeChart?

We are using JFreeChart to make XY plots and we have a feature request to do a crosshair that moves along with the mouse and highlights the data point that most closely maps to the x-value of the mouse. You can see a similar example at Google Finance - http://www.google.com/finance?q=INDEXDJX:.DJI,INDEXSP:.INX,INDEXNASDAQ:.IXIC.
Those Google charts only highlight the current value (we want to do that and also show crosshairs), but they show the live mouse interaction we are looking for.
Anyone have any elegant suggestions?
Thanks.
I got this working using a mouse listener and the CrosshairOverlay class. After I get back from holiday travel, I will post my code. It ended up being not too difficult.
Sorry, I forgot about this!
First, you want to calculate the x, y values for where you want your crosshair. For me, I wanted it to move along the points of our line, so I calculated the closest x value and used that data pair for x, y.
Then I call this method:
protected void setCrosshairLocation(double x, Double y) {
Crosshair domainCrosshair;
List domainCrosshairs = crosshairOverlay.getDomainCrosshairs();
if (domainCrosshairs.isEmpty()) {
domainCrosshair = new Crosshair();
domainCrosshair.setPaint(BlueStripeColors.LIGHT_GRAY_C0);
crosshairOverlay.addDomainCrosshair(domainCrosshair);
}
else {
// We only have one at a time
domainCrosshair = (Crosshair) domainCrosshairs.get(0);
}
domainCrosshair.setValue(x);
if (y != null) {
Crosshair rangeCrosshair;
List rangeCrosshairs = crosshairOverlay.getRangeCrosshairs();
if (rangeCrosshairs.isEmpty()) {
rangeCrosshair = new Crosshair();
rangeCrosshair.setPaint(BlueStripeColors.LIGHT_GRAY_C0);
crosshairOverlay.addRangeCrosshair(rangeCrosshair);
}
else {
// We only have one at a time
rangeCrosshair = (Crosshair) rangeCrosshairs.get(0);
}
rangeCrosshair.setValue(y);
}
}
Note that crosshairOverlay is an instance of CrosshairOverlay.
JFreeChart can't render a sub-section of a chart, so you'll want to do something that doesn't require repainting the chart. You could write your chart to a BufferedImage and store that in memory, then have a custom component which uses the buffered chart as the background image, and draws crosshairs and other popup windows over it.
There are methods in JFreeChart to get the data point for a given coordinate on a rendered chart. Don't recall what these are off the top of my head. Depending on your needs, you might consider rendering your own chart data, it's not as hard as you'd think.
The first thing that comes to my mind would be to write a custom Cursor and set it on your chart. It can have a reference to the chart and highlight the x value that's consistent with the Cursor's x/y location.
This worked for me. I set the
chartPanel.addChartMouseListener(new ChartMouseListener() {
public void chartMouseMoved(ChartMouseEvent event)
{
try
{
double[] values = getCrossHairValue(event);
plot.clearRangeMarkers();
plot.clearDomainMarkers();
Marker yMarker = new ValueMarker(values[1]);
yMarker.setPaint(Color.darkGray);
plot.addRangeMarker(yMarker);
Marker xMarker = new ValueMarker(values[0]);
xMarker.setPaint(Color.darkGray);
plot.addDomainMarker(xMarker);
chartPanel.repaint();
} catch (Exception e)
{
}
}
}

Categories