I am trying to use drake within the class of our code. I have declared the drake variables within the class. For this purpose, I initialized the drake variables within header files as
drake::systems::DiagramBuilder<double> builder_;
std::unique_ptr< MultibodyPlant< double > plant_;
drake::multibody::MultibodyPlant<double>* plant_{};
drake::geometry::SceneGraph<double>* scene_graph_{};
std::unique_ptr<drake::systems::Diagram<double>> diagram_;
std::unique_ptr<drake::systems::Context<double>> diagram_context_;
drake::systems::Context<double> *plant_context_;
std::unique_ptr<drake::systems::Simulator<double>> simulator_;
double timestep_;
double time_;
In the source file, I have initialized them as follow
drake::multibody::MultibodyPlantConfig plant_config;
plant_config.time_step = 1e-3;
std::tie(plant_, scene_graph_) = AddMultibodyPlant(plant_config,&builder_);
const std::string urdf = drake::FindResourceOrThrow("drake/urdf/iiwa_description/urdf/iiwa14_no_collision.urdf");
drake::multibody::Parser(plant_).AddModelFromFile(urdf);
const double static_friction = 0.5;
const Eigen::Matrix<double, 4, 1> green(0.5, 1.0, 0.5, 1.0);
plant_->RegisterVisualGeometry(plant_->world_body(), drake::math::RigidTransformd(),
drake::geometry::HalfSpace(), "GroundVisualGeometry", green);
// // For a time-stepping model only static friction is used.
const drake::multibody::CoulombFriction<double> ground_friction(static_friction,
static_friction);
plant_->RegisterCollisionGeometry(plant_->world_body(), RigidTransformd(),
drake::geometry::HalfSpace(),
"GroundCollisionGeometry", ground_friction);
Vector3d gravity;
gravity << 0.0, 0.0, -9.81;
plant_->mutable_gravity_field().set_gravity_vector(gravity);
plant_->WeldFrames(plant_->world_frame(), plant_->GetFrameByName("base"));
plant_->Finalize();
plant_->set_penetration_allowance(1e-3);
plant_->set_stiction_tolerance(1e-3);
// Publish contact results for visualization.
drake::visualization::AddDefaultVisualization(&builder_);
diagram_ = builder_.Build();
// // Create a context for this system:
diagram_context_ = diagram_->CreateDefaultContext();
drake::systems::Context<double>& plant_context = diagram_->GetMutableSubsystemContext(*plant_, diagram_context_.get());
plant_context_ = &(diagram_->GetMutableSubsystemContext(*plant_, diagram_context_.get()));
Eigen::VectorXd tau = Eigen::VectorXd::Zero(plant_->num_actuated_dofs());
plant_->get_actuation_input_port().FixValue(plant_context_, tau);
simulator_ = std::make_unique<drake::systems::Simulator<double>>(*diagram_, std::move(diagram_context_));
simulator_->set_publish_every_time_step(true);
simulator_->set_target_realtime_rate(1.0);
simulator_->Initialize();
timestep_ = 1e-3;
time_ = timestep_;
simulator_->AdvanceTo(time_);
Now it runs fine when simulator_->AdvanceTo(time_) is called within initializer. However, when I try to call simulator_->AdvanceTo(time_) within a callback function (where simulator_ is defined and is visible within the class function), it gives the following error
abort: Failure at geometry/meshcat.cc:606 in ThrowIfWebsocketThreadExited(): condition 'IsThread(main_thread_id_)' failed.
I looked at the code but it do not give much information why the websocketthread is dying. Any help and guidance will be highly appreciated.
The error message is saying that you tried to call the meshcat API from a different thread than the thread which created the meshcat instance. The meshcat class does some nontrivial data sharing with a networking thread, so we currently restrict that the meshcat API is only used from a single thread.
Related
I have a Lenovo Thinkpad that only allows certain hardware to be installed. If there is a piece of hardware connected that is not on the whitelist, BIOS will tell you to remove it and restart. Otherwise the machine will not boot. Now I want to install an unauthorized wifi+bluetooth module, so I need to get rid of that whitelist.
I've been following this guide up to the point where the author suggests the use of the IDA pro software, which I don't want to buy just for this one hack.
Instead, I have dabbled around a bit with the extracted body in Ghidra, and managed to get to locate the hex code for the "Unauthorized network card detected ..." string and to find out that the string is part of some entity called "DAT_000104d0", and the only place that entity is referenced is the following function:
void FUN_00010ec4(undefined8 param_1,undefined *param_2,undefined8 param_3,undefined8 param_4)
{
if (param_2 == (undefined *)0x0) {
param_2 = &DAT_00010ec0;
}
(**(code **)(DAT_00011040 + 0x170))(0x200,param_1,param_2,param_3,&DAT_000104d0,param_4);
return;
}
That function in turn gets called from here:
longlong entry(undefined8 param_1,longlong param_2)
{
longlong lVar1;
undefined8 local_res18;
undefined8 *local_res20;
undefined local_18 [24];
FUN_00010f08(param_1,param_2);
lVar1 = (**(code **)(DAT_00011040 + 0x140))(&LAB_00010480,0,&DAT_00011058);
if (-1 < lVar1) {
lVar1 = (**(code **)(DAT_00011040 + 0x140))(&LAB_00010410,0,&DAT_00011070);
if (-1 < lVar1) {
lVar1 = (**(code **)(DAT_00011040 + 0x140))(&DAT_000103f0,0,&DAT_00011078);
if (-1 < lVar1) {
lVar1 = (**(code **)(DAT_00011040 + 0x140))(&LAB_00010460,0);
if (-1 < lVar1) {
DAT_00011060 = *local_res20;
local_res18 = 0;
_DAT_00011068 = &LAB_00010b54;
(**(code **)(DAT_00011040 + 0x80))(&local_res18,&DAT_000103d0,0,&DAT_00011068);
DAT_00011028 = local_res18;
FUN_00010ec4(0x10,FUN_00010cf8,0,local_18);
lVar1 = 0;
}
}
}
}
return lVar1;
}
Any idea on how I should proceed, hopefully without messing up the whole thing?
I've uploaded the complete bios img and the extracted body here, if anyone wants to have a look at those.
Edit: I used a workaround by googling a lot and eventually finding a modified version of the extracted body that I used experimentally, and it worked. What I googled for was (I think) the name of that section of the BIOS. In the example from the medium guide that would be 11D37... That number will be different for your device though, and I can´t guarantee that there will be such a file for your device at all, or that it will work. Just make sure you backup your original bios multiple times and in multiple places, so you can flash it again.
There's an example of downloading a file with Rusoto S3 here:
How to save a file downloaded from S3 with Rusoto to my hard drive?
The problem is that it looks like it's downloading the whole file into memory and then writing it to disk, because it uses the write_all method which takes an array of bytes, not a stream. How can I use the StreamingBody, which implements futures::Stream to stream the file to disk?
Since StreamingBody implements Stream<Item = Vec<u8>, Error = Error>, we can construct a MCVE that represents that:
extern crate futures; // 0.1.25
use futures::{prelude::*, stream};
type Error = Box<std::error::Error>;
fn streaming_body() -> impl Stream<Item = Vec<u8>, Error = Error> {
const DUMMY_DATA: &[&[u8]] = &[b"0123", b"4567", b"89AB", b"CDEF"];
let iter_of_owned_bytes = DUMMY_DATA.iter().map(|&b| b.to_owned());
stream::iter_ok(iter_of_owned_bytes)
}
We can then get a "streaming body" somehow and use Stream::for_each to process each element in the Stream. Here, we just call write_all with some provided output location:
use std::{fs::File, io::Write};
fn save_to_disk(mut file: impl Write) -> impl Future<Item = (), Error = Error> {
streaming_body().for_each(move |chunk| file.write_all(&chunk).map_err(Into::into))
}
We can then write a little testing main:
fn main() {
let mut file = Vec::new();
{
let fut = save_to_disk(&mut file);
fut.wait().expect("Could not drive future");
}
assert_eq!(file, b"0123456789ABCDEF");
}
Important notes about the quality of this naïve implementation:
The call to write_all may potentially block, which you should not do in an asynchronous program. It would be better to hand off that blocking work to a threadpool.
The usage of Future::wait forces the thread to block until the future is done, which is great for tests but may not be correct for your real use case.
See also:
What is the best approach to encapsulate blocking I/O in future-rs?
How do I synchronously return a value calculated in an asynchronous Future in stable Rust?
I've tried to implement a delay feature on my bot to display multiple messages one after the other. The delay feature is displaying in my Flow Bot Builder diagram, but when I test in the conversation tester, and proxy bot on Messenger, the delay doesn't actually happen - all the messages display at once.
I have added the delay code in the IDE to the default.scr file:
[main]
label_dych:Hi! I'm delay-bot and I'm here to help you with any questions you have.:continue
((delay 2000))
label_gthk:I'll never need to take any personal or financial information from you, so as we chat please don't tell me any!:continue
((delay 1000))
label_ylbn:{"name":"quickreply","type":"quick_reply","alias":"What can I help you with?","msgid":"117af569-5188-ff7e-9b48-8c553c2f36cb","content":{"type":"text","text":"What can I help you with?"},"options":[{"type":"text","title":"My Page","iconurl":"","id":"ac49ad32-c9bc-469f-2152-c7c842bad8ea","isDuplicate":false,"name":"user"},{"type":"text","title":"Team Spaces","iconurl":"","id":"8a2017ac-2fc3-0901-be8d-1fad5a2dba12","isDuplicate":false,"name":"user"},{"type":"text","title":"Offline Support","iconurl":"","id":"70861407-e706-17a3-207b-c43958fde83e","isDuplicate":false,"name":"user"},{"type":"text","title":"Something else","iconurl":"","id":"d3f7b6b4-e70a-098d-dde9-1da3e8cc08dc","isDuplicate":false,"name":"user"}]}
I've also added the options.apikey line of code to the index.js file as instructed to do here: https://www.gupshup.io/developer/docs/bot-platform/guide/sending-multiple-messages-botscript
function ScriptHandler(context, event){
var options = Object.assign({}, scr_config);
options.current_dir = __dirname;
//options.default_message = "Sorry Some Error Occurred.";
// You can add any start point by just mentioning the
<script_file_name>.<section_name>
// options.start_section = "default.main";
options.success = function(opm){
context.sendResponse(JSON.stringify(opm));
};
options.error = function(err) {
console.log(err.stack);
context.sendResponse(options.default_message);
};
botScriptExecutor.execute(options, event, context);
options.apikey = "1mbccef47ab24dacad3f99557cb35643";
}
Is there any obvious reason why the delay effect wouldn't be working in between messages? I've used the apikey that is displayed for my gupshup account when I click the logo in the top right.
You have placed the API key after the scripting tool execute function is called. Place the API Key anywhere before the botScriptExecutor.execute and the delay should work.
Also, the timing of the delay is in milliseconds.
Sample:
function ScriptHandler(context, event){
var options = Object.assign({}, scr_config);
options.current_dir = __dirname;
//options.default_message = "Sorry Some Error Occurred.";
options.apikey = "1mbccef47ab24dacad3f99557cb35643";
// You can add any start point by just mentioning the
<script_file_name>.<section_name>
// options.start_section = "default.main";
options.success = function(opm){
context.sendResponse(JSON.stringify(opm));
};
options.error = function(err) {
console.log(err.stack);
context.sendResponse(options.default_message);
};
botScriptExecutor.execute(options, event, context);
}
I am new in createjs and jquery mobile. This may be a simple question, but I do not know how to do it and have not found any answer online.
I created a canvas object using the Flash toolkit for CreateJS. I want to control it with a jQuery Mobile slider.
This is my html code:
<canvas id="canvas" width="200" height="200" style="background-color:#ffffff"></canvas>
<input type="range" name="slider-1" id="slider-1" value="1" min="1" max="6" data-highlight="true" />
The name of the instance that I want to control is squareB1, its timeline has 6 frames, see the fragments whole of code below. Notice that the slider has 6 values, the same number of frames.
(function (lib, img, cjs) {
var p; // shortcut to reference prototypes
// stage content:
(lib.squareB = function() {
this.initialize();
// Layer 1
this.instance = new lib.squareB1();
this.instance.setTransform(100,100,1,1,0,0,0,19.4,60.5);
this.addChild(this.instance);
}).prototype = p = new cjs.Container();
p.nominalBounds = new cjs.Rectangle(80.6,39.5,38.9,121);
// symbols:
(lib.squareB1 = function(mode,startPosition,loop) {
this.initialize(mode,startPosition,loop,{thiner:0,thin:1,mean:2,thick:3,thicker:4},true);
// timeline functions:
this.frame_0 = function() {
this.stop();
}
// actions tween:
this.timeline.addTween(cjs.Tween.get(this).call(this.frame_0).wait(4));
// Layer 1
this.shape = new cjs.Shape();
this.shape.graphics.f("rgba(71,31,7,0.2)").s("#1A1A1A").ss(1,1,1).p("ADCpcIAAS5ImDAAIAAy5IGDAA").cp();
this.shape.setTransform(19.5,60.5);
this.shape_1 = new cjs.Shape();
this.shape_1.graphics.f("rgba(71,31,7,0.2)").s("#1A1A1A").ss(1,1,1).p("Ak3pcIJvAAIAAS5IpvAAIAAy5").cp();
this.shape_1.setTransform(19.4,60.5);
this.shape_2 = new cjs.Shape();
this.shape_2.graphics.f("rgba(71,31,7,0.2)").s("#1A1A1A").ss(1,1,1).p("AmtpcINbAAIAAS5ItbAAIAAy5").cp();
this.shape_2.setTransform(19.4,60.5);
this.shape_3 = new cjs.Shape();
this.shape_3.graphics.f("rgba(71,31,7,0.2)").s("#1A1A1A").ss(1,1,1).p("AojpcIRHAAIAAS5IxHAAIAAy5").cp();
this.shape_3.setTransform(19.4,60.5);
this.shape_4 = new cjs.Shape();
this.shape_4.graphics.f("rgba(71,31,7,0.2)").s("#1A1A1A").ss(1,1,1).p("AKaJdI0zAAIAAy5IUzAAIAAS5").cp();
this.shape_4.setTransform(19.4,60.5);
this.timeline.addTween(cjs.Tween.get({}).to({state:[{t:this.shape}]}).to({state:[{t:this.shape_1}]},1).to({state:[{t:this.shape_2}]},1).to({state:[{t:this.shape_3}]},1).to({state:[{t:this.shape_4}]},1).wait(1));
}).prototype = p = new cjs.MovieClip();
p.nominalBounds = new cjs.Rectangle(-35.3,0,109.7,121);
})(lib = lib||{}, images = images||{}, createjs = createjs||{});
var lib, images, createjs;
Then, I am doing something like this in jQuery, this is part of another JS file:
var canvas, stage, exportRoot;
function init() {
canvas = document.getElementById("canvas");
exportRoot = new lib.squareB();
stage = new createjs.Stage(canvas);
stage.addChild(exportRoot);
stage.update();
createjs.Ticker.setFPS(24);
createjs.Ticker.addListener(stage);
}
$('#slider-1').live('change', function(){
var slider_value = $(this).slider().val();
if(slider_value==1){
}
else if(slider_value==2){
//here is the issue, squareB1 is the symbol instance
exportRoot.squareB1.gotoAndStop(1);
}
else if...
}
My question is how to go to an specific frame of instance in the canvas object using the slider.
I appreciate any answer!
Feel free to post CreateJS questions on the support forum http://community.createjs.com
This looks like Toolkit for CreateJS output. The possible reason this isn't working is because unless you have created a variable named "canvas", which is the export root from Flash, then squareB1 is not defined. Elements that live on the stage in Flash, are exported as children of the exportRoot, which you can see in the generated HTML bootstrap file that gets created. The squareB1 child likely lives in that scope.
Can you post more code that shows where the export root is created, or describe your setup a little more?
The flash stage of toolkit is usually the name of your FLA, which is the first library definition in the generated JavaScript file. Usually it is created for you as "exportRoot" in the HTML that Toolkit creates. In your case, it is probably an instance of "SquareB" (note the "stage content" comment).
var exportRoot = new lib.SquareB();
exportRoot.instance.gotoAndStop(1);
This script is getting Microsoft JScript runtime error: Object expected on If (out_params.bGranted) line. It seems like this is related to a syntax error, but I can't find it. This code, in its current form, was basically copied from Invoking functions with `out` arguments, passing arguments by reference in JScript.
function main()
{
var provider_name = "StdRegProv";
var func_name = "CheckAccess";
var services = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\default"); // connect to WMI
var registry = services.Get(provider_name); // get provider
var in_params = registry.Methods_(func_name).InParameters.SpawnInstance_();
in_params.hDefKey = 0x80000001;
in_params.sSubKeyName = "Software\\Microsoft\\Shared Tools\\Proofing Tools\\1.0\\Override";
in_params.uRequired = 65536;
var out_params = services.ExecMethod(provider_name, func_name, in_params);
If (out_params.bGranted)
{
WScript.Echo("Has DELETE Access Rights on HKCU " + strKeyPath);
registry.DeleteKey (HKCU, strKeyPath);
}
Else
{
WScript.Echo("No DELETE Access Rights on HKCU " + strKeyPath);
}
}
main();
In JScript, keywords (and identifiers) are case-sensitive, so you cannot use If instead of if, Elseinstead of else, and so on.
In your example the script engine interprets If (out_params.bGranted) as a function call, which results in a runtime error since you obviously did not defined an If function.