I am develop an application for Rover to management by joystick. I need to create remote control to set direction of moving rover (left, right, forward, back). I'm trying to realize it by following code:
ControlApi.getApi(mDrone).enableManualControl(true, new ControlApi.ManualControlStateListener() {
#Override
public void onManualControlToggled(boolean b) {
}
});
ControlApi.getApi(mDrone).manualControl(0, -0.5f, 0, new AbstractCommandListener() {
#Override
public void onSuccess() {
}
#Override
public void onError(int i) {
}
#Override
public void onTimeout() {
}
});
But I'm getting an error 3 in onError block. Also before that I can't enable manual control it always return false. Can someone tell me what I'm doing wrong, or maybe guide me to the right way?
I would realy apriciate if someone can help me. Regards!
UPDATED
Still no result
Now I'm trying to use
MavLinkCommands.sendManualControl(drone, x, y, z, r, button, new ICommandListener(){...});
But can't run this method because drone is null.
I generate it like this:
MavLinkDroneManager mavLinkDroneManager =
new MavLinkDroneManager(mContext, mConnectionParameter, mHandler);
MavLinkDrone drone = mavLinkDroneManager.getDrone();
and method getDrone always return null.
SOLVED
If someone will encounter a similar problem, then the solution is quite simple. In total, you need to read the python documentation in more detail :)
All you need to do is override the channels using MAVLink command msg_rc_channels_override(); and the code with the solution will look like this:
VehicleApi.getApi(mDrone).setVehicleMode(VehicleMode.ROVER_MANUAL); //be sure the vehicle is in manual mode
VehicleApi.getApi(mDrone).arm(true); // and arm need to be true
by default chanel 1 is left-right, chanel 3 is forward-back.
If it does not work, check on the drones in which channels they are connected.
To move vehicle left set chanel 1 to 2000, right - 1000;
To move forward set chanel 3 - 2000, bacck - 1000;
I tested it on ArduRover but I think it should work with ArduPilot and ArduCopter.
msg_rc_channels_override rc_override = new msg_rc_channels_override();
rc_override.chan1_raw = 1000 //right; 2000 //left
rc_override.chan3_raw = 1000 //back; 2000 //forward
rc_override.target_system = 0;
rc_override.target_component = 0;
ExperimentalApi.getApi(mDrone).sendMavlinkMessage(new MavlinkMessageWrapper(rc_override));
For more instruction check this link
Related
I am trying to use a LookToWalk script in my Unity VR app that should run on my Daydream View. In the "Game" Mode to preview the changes everything works as expected (I configured the script to run forward once the user camera faces 30.0 degrees downwards or more.
However when I try to build the daydream app and install it on my Google Pixel the CharacterController.SimpleMove doesn't seem to work any more.
The logs were showing that the 30.0 degree stuff was triggered as expected but no movement was seen on the daydream.
Do you know why this could be happening? Seems really strange that it runs on the "emulator" but not the 'real' device.
using UnityEngine;
using System.Collections;
public class GVRLookWalk : MonoBehaviour {
public Transform vrCamera;
public float toggleAngle = 30.0f;
public float speed = 3.0f;
private bool shouldWalk;
private CharacterController cc;
// Use this for initialization
void Start () {
cc = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update () {
if (vrCamera.eulerAngles.x >= toggleAngle && vrCamera.eulerAngles.x < 90.0f){
shouldWalk = true;
} else {
shouldWalk = false;
}
if (shouldWalk) {
Vector3 forward = vrCamera.TransformDirection (Vector3.forward);
cc.SimpleMove (forward * speed);
}
}
Is the Camera a child of another transform? You cannot move the camera directly. "you cannot move the camera directly in Unity. Instead, the camera must be a child of another GameObject, and changes to the position and rotation must be applied to the parent’s Transform."
https://unity3d.com/learn/tutorials/topics/virtual-reality/movement-vr
I am following a book on "Rapid Android Development" with Processing 2.0.3 windows 7 64bit, having only api level 10 installed (android 2.3.3).
The example I am at, uses "motionPressure" which was dropped by 2.0b7 http://wiki.processing.org/w/Android#Mouse.2C_Motion.2C_Keys.2C_and_Input
"The motionX, motionY, motionPressure, etc. variables have all been removed. This was sort of a kludge, and it'll be handled better by a later touch API. It should be easy to bring them back with a dozen lines of code in your sketch, if you were relying on them. Instead, just use mouseX/Y for now."
I found a fix here https://forums.pragprog.com/forums/209/topics/11348 but the code doesn't seem to work. When it reaches mouseDragged() "MotionEvent me = (MotionEvent) mouseEvent.getNative();" it stops at this line saying cannot find symbol.
How can I fix this in a simple way? I am just learning to code.
edit: I see motionPressure being used more and more throughout the book, so I am going to need a way of replicating that function that acts the same.
import android.view.MotionEvent;
float maxPressure;
float motionPressure;
void setup()
{
noStroke();
background(0);
}
void draw()
{
fill(motionPressure/maxPressure * 255);
ellipse(mouseX, mouseY, mouseX-pmouseX, mouseY-pmouseY);
println(motionPressure);
if(motionPressure > maxPressure)
maxPressure = motionPressure;
}
void mouseDragged() {
MotionEvent me = (MotionEvent) mouseEvent.getNative();
motionPressure = me.getPressure();
println (motionPressure); // can do stuff with this float now -- mine ranges .4 - 3.6 -- not 0 -1
}
here's a stripped down version of the code from their wiki that seems to work. Thank you for pointing that out to me kevinsa5
import android.view.MotionEvent;
// fix prerequisite
String touchEvent = "";
float pressure = 0.0;
void setup()
{
noStroke();
background(0);
}
void draw() { }
void mouseDragged()
{
fill(pressure * 255);
ellipse(mouseX, mouseY, mouseX-pmouseX, mouseY-pmouseY);
println(pressure);
}
// fix
#Override
public boolean dispatchTouchEvent(MotionEvent event) {
pressure = event.getPressure();
int action = event.getActionMasked();
pressure = event.getPressure();
switch (action) {case MotionEvent.ACTION_UP: pressure = 0.0; break; }
return super.dispatchTouchEvent(event);
}
I am currently developing a game in AndEngine and I have set up my collision detection with the enemies by checking each car against every individaul index of the enemy array as for some reason, a for loop does not work. This is extremely inconvinient as not only does it make increasing and decreasing enemies a chore, but it looks awful! It looks something like this:
if (rManager.getInstance().iceArray[0].getIceSprite().collidesWith(rManager.getInstance().carArray[r].getCarSprite()))
{
rManager.getInstance().carArray[r].setCarSpeed(1f);
} else if (rManager.getInstance().iceArray[1].getIceSprite().collidesWith(rManager.getInstance().carArray[r].getCarSprite())) {
rManager.getInstance().carArray[r].setCarSpeed(1f);
} else if (rManager.getInstance().iceBergArray[0].getIceBergSprite().collidesWith(rManager.getInstance().carArray[r].getCarSprite())) {
rManager.getInstance().carArray[r].setCarSpeed(0f);
} else {
rManager.getInstance().carArray[r].setCarSpeed(0.5f);
}
The for loop I tried was like this with [r] being every car of the car array, but it doesn't seem to do anything.
for (int h = 0; h < rManager.getInstance().snowArray.length; h++)
{
if (rManager.getInstance().snowArray[h].getSnowSprite().collidesWith(rManager.getInstance().carArray[r].getCarSprite())) {
String temp = rManager.getInstance().carArray[r].toString();
Log.e("SNOW", "SNOWWWWW!" + rManager.getInstance().snowArray[h].toString());
rManager.getInstance().carArray[r].setCarSpeed(0.2f);
}
}
Thanks!!
You should use factory pattern or strategy pattern to remove out the if else.
Please see the link below to take reference.
http://www.cumps.be/nl/blog/read/design-patterns-strategy-pattern
or Strategy Pattern with no 'switch' statements?
EDIT :
Base on your code, the startegy pattern should implement follow pesudo code below. I have made some of assumption base on your code already posted above.
You will create a dictionary contains logics and appropriate action as below:
Dictionary<Func<RManager, int, bool>, Action<Car>>
ruleUpdates =
new Dictionary<Func<RManager, int, bool>, Action<Car>>();
Each Func<Ice, Car, bool> you should implement like this
private bool ZeroElementEqualIcePrite(RManager rManager, int r)
{
return rManager.getInstance().iceArray[0].collidesWith(rManager.getInstance().carArray[r].getCarSprite());
}
and Action should implement as below:
public static void DoUpdateOneLevel(Car car)
{
car.setCarSpeed(1f);
}
From there we can implement similar with all of logics following your code with the same way.
You can initialize the dictionary following below
ruleUpdates.Add(FirstElementEqualIcePrite, DoUpdateOneLevel);
ruleUpdates.Add(SecondElementEqualIcePrite, DoUpdateOneLevel);
ruleUpdates.Add(FirstElementEqualIceBergPrite, DoUpdateZeroSpeed);
ruleUpdates.Add(SecondElementEqualIceBergPrite, DoUpdateZeroSpeed);
After that you just loop go through each key of executionList as below.
foreach (KeyValuePair<Func<RManager, int, bool>, Action<Car>>
ruleUpdate in ruleUpdates)
{
if (ruleUpdate.Key.Invoke(rManager, r))
{
ruleUpdate.Value.Invoke(rManager.getInstance().carArray[r]);
break;
}
}
Hope this help. Following the strategy your code will clean and easy to changed does not care much about if / then / else logic as well. You can easy extent it in future.
In the latest version of Libgdx(0.9.7 or libgdx-nightly-20120904),the action listener is removed.So I don't know how to complete my function efficiently:
move a sprite to the destination.
the movement contains many MoveToActions or MoveByActions.
act the following action after the previous is end.
the rest action may be modified before act.
Actually,the main point is how to act the next action after the previous is end,and I think compare the act time is not a wise method.
Can anybody help me? Thanks !
Not sure if this answers your question, but this is one way to simulate an "actions-completed listener":
Action completeAction = new Action(){
public boolean act( float delta ) {
// Do your stuff
return true;
}
};
Action actions = sequence(fadeIn(1f), fadeOut(1f), completeAction);
(Source: http://steigert.blogspot.com.br/2012/07/13-libgdx-tutorial-libgdx-refactoring.html)
I think that the best approach would be to keep it simple. You could poll if the actor has any action left by using
if (actor.getActions().size > 0) {no actions left!!}
A good place to place that code would be near the actor.act();
Anyway, you can execute a secuence of actions using a sequenceAction:
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
...
actor.addAction(sequence(moveTo(200, 100, 2), moveBy(20,30, 3), delay(0.5f), rotateTo(180, 5)));
That would execute those actions one after the other as they finish.
You can check the nightlies documentation for more info here: http://code.google.com/p/libgdx/wiki/scene2d
Is that what you need? (I'm not sure i understood step 4).
If you need something more specific please ask again. You can also take a look at the Actor Class source code to have a better understanding of how actions are handled.
https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/scenes/scene2d/Actor.java
libgdx 0.9.7
Action a = new Action();
render(){
if (a.getTime >= a.getDuration())
Gdx.app.log("a", "is done");
}
Warning in check action isDone:
while
delayAction.getTime > 0 and (delayAction.getTime < delayAction.getDuration)
then
alpha.getTime > alpha.getDuration
until
delayAction.getTime > delayAction.getDuration.
Example:
AlphaAction alpha = new AlphaAction();
alpha.setAlpha(0.2f);
alpha.setDuration(1);
DelayAction delayAction = new DelayAction();
delayAction.setDuration(1);
SequenceAction sequenceAction = new SequenceAction();
sequenceAction.addAction(alpha);
sequenceAction.addAction(delayAction);
More at http://congdongandroid.vn/
use Actions.run :
Action action = Actions.sequence(
Actions.delay(1f),
Actions.run(new Runnable() {
#Override public void run() {
// end of action
}
})
);
Please any one assist me for implement parallax screen in super jumper game because I unnable to implement that. I have seen ParallaxTest.java
of your code but I can't Implement it. I same code in one class(ParallaxTest.java) and write only parallaxCamera class and in WorldRenderer I implement as but produce null pointer exception.
code:
public void renderBackground()
{
// background layer, no parallax, centered around origin
bath1.setProjectionMatrix(ParallaxCam.calculateParallaxMatrix(1, 1));
bath1.disableBlending();
bath1.begin();
bath1.draw(Assets.mainbackgroundRegion,ParallaxCam.position.x - FRUSTUM_WIDTH / 2, ParallaxCam.position.y - FRUSTUM_HEIGHT/2, FRUSTUM_WIDTH, FRUSTUM_HEIGHT);
bath1.end();
in renderer---
if(ParallaxCam.position.y<FRUSTUM_HEIGHT)
{
ParallaxCam.position.y=FRUSTUM_HEIGHT;
//updateCamera = true;
}
And in constructr of WorldRendere--
this.ParallaxCam = new MyParallaxTest().new ParallaxCamera(FRUSTUM_WIDTH, FRUSTUM_HEIGHT);
mcontroller = new OrthoCamController(this.ParallaxCam);
Gdx.input.setInputProcessor(mcontroller);
}
for this see this URL complete implementation is here
http://www.badlogicgames.com/forum/viewtopic.php?f=17&t=1795