Sphero - How to make Sphero jump? - sphero-api

I just got a Sphero v2.0 and have been playing with the SDK to create android apps in Eclipse for the Sphero.
In the official app there is a function to make the Sphero jump for the ground
https://play.google.com/store/apps/details?id=orbotix.sphero&hl=en
I can control the movement of Sphero but can't find a way to make it Jump via code. Does any one know how to do this?

I have been able to do this on iOS with this macro:
RKMacroObject *macro = [RKMacroObject new];
[macro addCommand:[RKMCRoll commandWithSpeed:0.15 heading:0 delay:0]];
[macro addCommand:[RKMCRawMotor commandWithLeftMode:1 leftSpeed:255 rightMode:1 rightSpeed:253 delay:255]];
[macro addCommand:[RKMCDelay commandWithDelay:1000]];
[macro playMacro];
I guess it would look something like this in Java :)
MacroObject macro = new MacroObject();
macro.addCommand(new Roll(0.15, 0, 0));
macro.addCommand(new RawMotor(1, 255, 1, 253, 255);
macro.addCommand(new Delay(1000));
sphero.executeMacro(macro);
Then, you can tweak the roll speed, delay and differences between speed of left and right motor.

Related

DJI SDK Android - unwanted yaw motion on GoToAction in time line mission

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.

SCNAction.rotateByAngle rotation is inverted in El Capitan or Metal

Using SCNAction.rotateByAngle(…) in my game I would press left/right/up/down keys or swipe to have an object rotate in that direction. But testing my game on El Capitan or with Metal as the renderer causes the 3D object to rotate the other way i.e. left becomes right and up becomes down.
I haven't found any documentation mentioning that the rotation is "inverted" or "reversed" in El Capitan or Metal.
The code is:
Rotate up = SCNVector3(x:1, y:0, z:0)
Rotate down = SCNVector3(x:-1, y:0, z:0)
Rotate left = SCNVector3(x:0, y:1, z:0)
Rotate right = SCNVector3(x:0, y:-1, z:0)
SCNAction.rotateByAngle(CGFloat(M_PI_2), aroundAxis:vector, duration:1)
Pretty simple and straight forward.
Any clues why this is happening?
Should I have to check which OS is running or Metal and then apply the correct rotations?
thx
In the Apple Developer Forums, an Apple employee has confirmed this.
Apple Developer Forum question & answer
This is right. The behavior on rotateByAngle was wrong (inverted)
before 10.11 and iOS9 and it is fixed now. The backward compatibility
is ensured (an application linked before iOS9 / 10.11 will continue to
run the same). If you are building a new application and using this
API and want to support previous builds, then yes you will have to
check the version of the OS you are running. Another option is to use
the "rotateByX:y:z:duration:" variant.

Capture screenshot: native API vs opengl

In my program I am using Qt's function: qApp->primaryScreen()->grabWindow(qApp->desktop()->winId(),x_offset,y_offset,w,h);
But its a little bit slowly for a "main task". So I've collide with a question above. The program able to work under Windows and Mac OS X. I heard about opengl as nice screengrabber since it is closer to GPU than native API plus its a cross platform solution. This is the first knowledge I want to get: Opengl as desktop screengrabber, is it real? I mean like a button "print screen".
If it is, how?If its not:
Windows: can you please give advice how to? BitBlt, GetDC, smthing like this?
Mac OS X: AVFoundation? Please, can you describe this or give some link about how to capture screenshot using this class? (Its a hard way since I know about Objective-C(++) almost nothing)
UPDATE: I read a lot about ways to capture screenshot. There are some knowledge:1. Opengl (maybe) is real as screengrabber, but use it will be irrcorrect for this software. Btw, I don't care, if there is some solution I will accept it.
2. DirectX it is not a way to solve my problem since this software does not work under Mac OS X.
Just to expand on #Zhenyi Luo's answer, here is a code snippet I have used in the past.
It also uses FreeImage for exporting the screenshot.
void Display::SaveScreenShot (std::string FilePath, SCREENSHOT_FORMAT Format){
// Create Pixel Array
GLubyte* pixels = new GLubyte [3 * Window::width * Window::height];
// Read Pixels From Screen And Buffer Into Array
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glReadPixels (0, 0, Window::width, Window::height, GL_BGR, GL_UNSIGNED_BYTE, pixels);
// Convert To FreeImage And Save
FIBITMAP* image = FreeImage_ConvertFromRawBits (pixels, Window::width,
Window::height, 3 * Window::width, 24,
0x0000FF, 0xFF0000, 0x00FF00, false);
FreeImage_Save ((FREE_IMAGE_FORMAT) Format, image, FilePath.c_str (), 0);
// Free Resources
FreeImage_Unload (image);
delete [] (pixels);
}
glReadPixels( GLint x,
GLint y,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
GLvoid * data), would read a block of pixels into client memory starting at location data.

How to make the sphero keep rotate on the spot?

I am new to Sphero development. I saw the app 'Drive' could make Sphero keep rotating before calibration. Anyone have idea how to make it?
I tried [RKRollCommand sendCommandWithHeading:90 velocity:0.01f stopped:YES] to adjust the header, but it just rotate 90 degree, anyway I could make it keep rotating?
Try using a rotate over time command paired with a delay in a macro, this is how we do it in the drive app. MacroLab comes with at least one built in macro that demonstrates this.

OpenGL 3.1+ with Ruby

I followed this post to play with OpenGL (programmable pipeline) on Ruby
Basically, I'm just trying to create a blue window, and here's the code.
Ray::GL.major_version = 3
Ray::GL.minor_version = 2
Ray::GL.core_profile = true # if you want/need one
window = Ray::Window.new("Test Window", [800, 600])
window.make_current
glClearColor(0, 0, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
Instead, I got a white window created. This indicated that I was missing something, but I couldn't figure out what I was missing as the resources for OpenGL on Ruby seemed limited. I have been searching all over the web, but all I found was fixed-pipeline OpenGL stuff for Ruby.
Yes, I could use Ray's built-in functions to set the background color and draw stuff, but I didn't want to do that. I just wanted to use Ray to setup the window, then called OpenGL APIs directly. However, I couldn't figure out what I was missing in the code above.
I would greatly appreciate any hint or pointer to this (maybe I needed to swap the buffer? but then I didn't know how to do it with Ray). Is there any body familiar with using Ray that can give me some hints on this?
Or, are there any other tools that would allow me to setup OpenGL binding (for none fixed-pipeline)?
It would appear that you set the clear color to be blue, then cleared the back buffer to make it blue. But, as you said, you have not swapped the buffers to put the back buffer onto your screen. As far as swapping buffers goes, here's another answer from stack overflow
"Swapping the front and back buffer of a double buffered window is a function provided by the underlying graphics system, i.e. Win32 GDI, or X11 GLX. The function's you're looking for are wglSwapBuffers and/or glXSwapBuffers. On MacOS X NSOpenGLViews are automatically swapped.
However most likely you're using some framework, like GLUT, GLFW or Qt, which provide a portable wrapper around those functions. Read the framework's documentation."
I've never used Ray, so I'd say just keep rooting around in the documentation or look through example projects to see how buffer swapping is done.

Resources