DroneKit :Changing groundspeed in AUTO mode/ implementing "MAV_CMD_DO_CHANGE_SPEED" - dronekit-python

I need help figuring out how to set groundspeed in AUTO mode (which is apparently implemented with the Mavlink command "MAV_CMD_DO_CHANGE_SPEED"—but I can't find any examples of this). What I thought would work:
vehicle.commands.add(Command( 0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_DO_CHANGE_SPEED, 0, 0, 1, 0.25, 0, 0, 0, 0, 0))
Based off of:
https://pixhawk.ethz.ch/mavlink/
and
https://github.com/mavlink/mavlink/blob/master/message_definitions/v1.0/common.xml
But it does not work.
Can anyone help me out?

msg = vehicle.message_factory.command_long_encode(
0, 0, # target system, target component
mavutil.mavlink.MAV_CMD_DO_CHANGE_SPEED, #command
0, #confirmation
0, #speed type, ignore on ArduCopter
speed, # speed
0, 0, 0, 0, 0 #ignore other parameters
)
# send command to vehicle
vehicle.send_mavlink(msg)
vehicle.flush()

You can set the parameter 'WPNAV_SPEED' to the desired speed (in cm) before setting the mode to AUTO.
Something like this:
vehicle.parameters['WPNAV_SPEED'] = 500

The following will work:
speed_type = 1 # 0 is airspeed (for plane with airspeed sensor), 1 is groundspeed
speed = 15
throttle_setting = 0
cmds.add( Command( 0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, mavutil.mavlink.MAV_CMD_DO_CHANGE_SPEED, 0, 0, speed_type, speed, throttle_setting, 0, 0, 0, 0) )
You can double check it by running the code then connecting to a GCS and downloading the mission from the vehicle.

Related

Merging on NOT NULL values in SQL Server

I have an empty table consisting of NULL (42 col.) and NOT NULL columns (14 columns). In total 56 columns.
That is Dest table I'd like to merge onto.
I have to update only 4 columns. All the remaining columns I'd like to remain untouched.
How would I achieve that?
My code:
merge into [tempdb].[dbo].[#Correspondence] Dest
using [tempdb].[dbo].[#toBeTransferred] Src
on (Dest.[CaseId] = Src.[CaseId])
when matched and (Dest.[CaseId] != Src.[CaseId])
then
update
set Dest.[CaseId] = Src.[CaseId]
when not matched then
insert ([CaseId],
[Description],
[Date],
[Link],
[RecipientAddressID],
[Faxed],
[CertifiedMail],
[CCRecipientAddressID],
[MergeTemplates],
[BCCRecipientAddressID],
[CorrespondenceFromAddressID],
[RegularMail],
[Sent],
[ExpertsLinked],
[EMailed],
[HandDelivered],
[UseDocusign],
[Privileged]
)
values (Src.[CaseId], Src.[Description], Src.[Date], Src.[Link], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
It works, but I had to use 0 as a workaround to pass the NOT NULL error on the update.
What would be a better way?

Format for sending location data in body

I'm coding in React-Native.
Glympse docs says that location data should be sent in a delta-compressed array. I don't really know what that means. I think I get the idea of each element being the amount of change (delta) from the previous element, but I still don't have a clear picture of how the body should look when I make the POST request.
Can anyone show an example of this process?
Examples of location arrays that are compressed can be found here https://developer.glympse.com/docs/core/api/reference/objects/location-points#examples
The idea behind this format is that the first item in the array contains specific values for each parameter, but each item that comes after that only contains the change (or delta) from the previous point.
[
[1339989715000, 37123450, -112123450, 18000, 55, null, 2, 4],
[1000, 1000000, 1000000, 0, null, 1000, 1, -1],
[1000, 0, 0, 0, 1, 0, 0, 0],
[1000, 0, 0, 0, 0, 0, 0, 0],
[1000, 0, 0, 0, 0, 0, 0, 0]
]
The first parameter is the timestamp, so if we look at the second item it shows 1000 which means it's the first timestamp + 1000ms.
The second parameter is latitude * 10^6. The first item shows latitude 37.123450, and the second item in the array has the value 1000000 which represents 37123450 + 1000000 or the latitude 38.123450. Not likely to have something moving that fast in real data, but that's the idea of how this format works.
Timestamp, latitude, and longitude are the only required fields. A POST body with only the required fields would look like this.
[
[1339989715000, 37123450, -112123450],
[1000, 1000000, 1000000],
[1000, 0, 0],
[1000, 0, 0],
]

Inserting multiple rows of data into SQL Sever 2012 table; Table is an Invalid Object

Pretty new to SQL Server. As the title says, I'm trying to insert multiple rows of data into a table. I've had a look on here (and online elsewhere) and the code part looks correct..?
The problem I have is that the table, which exists in the DB, is apparently an 'Invalid Object', and the same is true for the columns of the table too.
INSERT INTO [EmployeeIDCodes] ([EmployeeForeName], [EmployeeLastName], [EmployeePosition], [EmployeeWorkLocation])
VALUES (1, 0, 0, 0), (0, 0, 1, 0), (0, 0, 0, 0), (0, 0, 1, 0),
(0, 0, 0, 0), (0, 1, 0, 0), (0, 0, 0, 0), (0, 0, 0, 0)
Error:
Msg 208, Level 16, State 1, Line 2
Invalid object name 'EmployeeIDCodes'
If anyone could shed some light as to why I'm getting this error, that would be great.
Make sure that your current context in a right database:
USE [yourDBName];
INSERT INTO [dbo].[EmployeeIDCodes] ....
Include schema name when your refer to table, for instance:
INSERT INTO [dbo].[EmployeeIDCodes] (.....
Perhaps the table was created in another schema than dbo?

Why I cannot see array values on scala worksheet anymore?

I would kindly ask help for values of array. I am going to try explain with examples. When I write
var a = new Array[Int](10) or val a1 = Array(1, 2, 3)
I was able to see values of array. Output was like below on scala worksheet before
a : Array[Int] = Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
But recently I see only
a1: Array[Int] = [I#6b0910c9
How can I change, help me please.

Truth tables in code? How to structure state machine?

I have a (somewhat) large truth table / state machine that I need to implement in my code (embedded C). I anticipate the behavior specification of this state machine to change in the future, and so I'd like to keep this easily modifiable in the future.
My truth table has 4 inputs and 4 outputs. I have it all in an Excel spreadsheet, and if I could just paste that into my code with a little formatting, that would be ideal.
I was thinking I would like to access my truth table like so:
u8 newState[] = decisionTable[input1][input2][input3][input4];
And then I could access the output values with:
setOutputPin( LINE_0, newState[0] );
setOutputPin( LINE_1, newState[1] );
setOutputPin( LINE_2, newState[2] );
setOutputPin( LINE_3, newState[3] );
But in order to get that, it looks like I would have to do a fairly confusing table like so:
static u8 decisionTable[][][][][] =
{{{{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }},
{{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 }}},
{{{ 0, 0, 1, 1 },
{ 0, 1, 1, 1 }},
{{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 }}}},
{{{{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 }},
{{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 }}},
{{{ 0, 1, 1, 1 },
{ 0, 1, 1, 1 }},
{{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 }}}};
Those nested brackets can be somewhat confusing -- does anyone have a better idea for how I can keep a pretty looking table in my code?
Thanks!
Edit based on HUAGHAGUAH's answer:
Using an amalgamation of everyone's input (thanks -- I wish I could "accept" 3 or 4 of these answers), I think I'm going to try it as a two dimensional array. I'll index into my array using a small bit-shifting macro:
#define SM_INPUTS( in0, in1, in2, in3 ) ((in0 << 0) | (in1 << 1) | (in2 << 2) | (in3 << 3))
And that will let my truth table array look like this:
static u8 decisionTable[][] = {
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 0, 0 },
{ 0, 0, 1, 1 },
{ 0, 1, 1, 1 },
{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 },
{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 },
{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 },
{ 0, 1, 1, 1 },
{ 0, 1, 1, 1 },
{ 0, 1, 0, 1 },
{ 1, 1, 1, 1 }};
And I can then access my truth table like so:
decisionTable[ SM_INPUTS( line1, line2, line3, line4 ) ]
I'll give that a shot and see how it works out. I'll also be replacing the 0's and 1's with more helpful #defines that express what each state means, along with /**/ comments that explain the inputs for each line of outputs. Thanks for the help, everyone!
I'd suggest either (preferred approaches first):
Use a macro to intialize each "row" - this will hide the braces within the macro call.
Use comments to break up the rows.
Use an init function to initialize the context explicitly - perhaps use functions to initialize each section. This is similar to the first option above but has a disadvantage that the init function must be invoked before the state machine can be used.
No need for a multidimensional table. With a 4 bit => 4 bit mapping, you can have a single u8[16] array mapping inputs to outputs. State lookups will be much cheaper, and you can extract individual bits with some shift-and-mask ops.
If the algorithm to populate rows is easy to codify, you could #define a macro to populate each row by index number.
Personally, I'd read it from a configuration file. CSV, perhaps, which is easy to export to from Excel. Or you could just copy and paste from Excel into plain text, which gives you space-separated values, which is equally easy to import.
This also means, given that you are working with C, that you won't have to recompile your code each time the decision table changes.
if your truth-table is all booleans, you could just collapse it to a list of pairs, e.g.
1111,0000
1110,0110
...
for data compression, represent the values as bytes (two nybbles)...
where/how to store it for soft-coding in your particular embedded-system configuration, only you can say ;-)
If the truth table is really only 4x4x4x4 then I'd use macros. If it's ever going to grow past that, I'd use Ragel. Chances are it will make smaller, faster C code than you will.
I don't see any reference to the current state in order to get your output state. This means it is not a state machine, but only a truth table. There are four inputs, so there are only 16 possible input combinations. So, a table with 16 positions ought to do it.
Usually when you have a problem like this, one tries to reduce it to a simple boolean formula. I don't see why that wouldn't be the best approach here. It would be much more compact and more readable, plus it has the potential to be faster (I imagine a handful of ANDs and ORs would execute more quickly than the collection of multiplies/shifts + memory access needed for the lookup table approach). The easiest way to reduce this table to a boolean formula is with a K-Map.

Resources