Why do I get a parser/syntax error on a variable name in openSCAD? - openscad

I am new to openSCAD and I am trying to recreate a piston animation based on a youtube video I saw by a channel called "mathcodeprint". My code is almost identical, except I had to create the modules myself because he never shows them in the video.
I am getting a parser/syntax error in my code on line 6 where the variable "pin_offset" is defined. However, and if I try to hardcode and remove the variables entirely I get a similar issue on line 9 where "THROW" begins. Can someone please help me determine what the issue is? The code is here:
$fn=200;
//$t=0
crank_rad = 30;
crank_ang = $t*360
pin_offset = 55;
rod_length = 80;
THROW = sqrt((pow(crank_rad,2)+pow(rod_length,2))-(2*crank_rad*rod_length*cos(crank_angle)));
rod_ang = asin(crank_rad*sin(crank_ang)/rod_length);
translate([75,0,0]) text(str(THROW));
translate([75,-20,0]) text(str(rod_ang));
translate([0,0,THROW-rod_length]) piston()
%translate([0,0,THROW-rod_length]) pin()
#translate([0,-5,pin_offset+THROW-rod_length]) rotate([0,-rod_ang,0]) conrod()
translate([0,0,rod_length+pin_offset]) rotate([0,crank_ang,0]) cam();
module piston(){
difference(){
cylinder(h=75,r=50,center=false);
translate([0,0,pin_offset]) rotate([0,90,0]) cylinder(h=60,r=5,center=true);
}
translate([0,0,-5]) cylinder(h=80,r=55,center=false);
}
module pin(){
translate([0,0,pin_offset]) rotate([0,90,0]) cylinder(h=60,r=5,center=true);
}
module conrod(){
hull(){
difference(){
translate([0,-5,pin_offset]) rotate([0,90,0]) cylinder(h=5,r=5,center=false);
translate([0,-5,pin_offset+rod_length]) rotate([0,90,0]) cylinder(h=5,r=5,center=false);
}
translate([0,-5,pin_offset]) rotate([0,90,0]) cylinder(h=5,r=7,center=false);
translate([0,-5,pin_offset+rod_length]) rotate([0,90,0]) cylinder(h=5,r=7,center=false);
}
}
module cam(){
translate([0,-5,pin_offset+rod_length]) rotate([0,90,0]) cylinder(h=10,r=5,center=false);
}

the semicolon is missing in the line before
crank_ang = $t*360;
and line 9 has to be
THROW = sqrt((pow(crank_rad,2)+pow(rod_length,2))-(2*crank_rad*rod_length*cos(crank_ang)));

Related

getting "undefined reference to ledc_cb_register" error

I'm trying to use a callback function with the led controller of esp32, however I'm unable to compile the code. I'm not sure if something is missing or the code has errors, as I have a limited understanding of pointers or coding in general.
I'm using the Arduino framework, however when I hover over the ledc_cb_register text, VSCode will popup some more details/definition of this function, so I would expect that it does see the reference to it.
relevant esp32 documentation:
docs.espressif.com
I'm trying to copy the following example, but make it a bit simpler (using only one channel):
github
It seems this example can be compiled on my side too, but this uses espidf framework.
trying the following code (many lines are not shown here for simplicity)
static bool cb_ledc_fade_end_event(const ledc_cb_param_t *param, void *user_arg)
{
portBASE_TYPE taskAwoken = pdFALSE;
if (param->event == LEDC_FADE_END_EVT) {
isFading = false;
}
return (taskAwoken == pdTRUE);
}
[...]
void setup() {
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_HIGH_SPEED_MODE, // timer mode
.duty_resolution = LEDC_TIMER_13_BIT, // resolution of PWM duty
.timer_num = LEDC_TIMER_0, // timer index
.freq_hz = LED_frequency, // frequency of PWM signal
.clk_cfg = LEDC_AUTO_CLK, // Auto select the source clock
};
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
ledc_channel_config_t ledc_channel = {
.gpio_num = LED_PIN,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.channel = LEDC_CHANNEL_0,
.timer_sel = LEDC_TIMER_0,
.duty = 4000,
.hpoint = 0,
//.flags.output_invert = 0
};
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
ledc_fade_func_install(0);
ledc_cbs_t callbacks = {
.fade_cb = cb_ledc_fade_end_event
};
ledc_cb_register(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, &callbacks, 0);
and getting the following error message:
[..]/.platformio/packages/toolchain-xtensa-esp32#8.4.0+2021r2-patch3/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\src\main.cpp.o:(.literal._Z5setupv+0x78): undefined reference to 'ledc_cb_register(ledc_mode_t, ledc_channel_t, ledc_cbs_t*, void*)'
[..]/.platformio/packages/toolchain-xtensa-esp32#8.4.0+2021r2-patch3/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: .pio\build\esp32dev\src\main.cpp.o: in function 'setup()':
[..]\PlatformIO\Projects\asdf/src/main.cpp:272: undefined reference to 'ledc_cb_register(ledc_mode_t, ledc_channel_t, ledc_cbs_t*, void*)'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\esp32dev\firmware.elf] Error 1
According to the docs, it seems to be a feature that was added in v4.4.4
but the latest Arduino core (2.0.6) is build on v4.4.3.
If you are not on the latest Arduino core, try updating that first and see if it works. If not, then you just have to wait until the Arduino core is updated to use ESP IDF v4.4.4.
Of course, you can use ledc_isr_register(...) to register an ISR handler for the interrupt.
Best of luck!
Update:
I realized that the problem (at least on my side when testing it) was that there is an error in the ledc.h file, where they forgot to add ledc_cb_register in an extern "C" block.
I manually patched it by moving the
#ifdef __cplusplus
}
#endif
part, which was located after the ledc_set_fade_step_and_start function, below ledc_cb_register instead.
So, the end of my ledc.h file looks like this now:
...
esp_err_t ledc_set_fade_step_and_start(ledc_mode_t speed_mode, ledc_channel_t channel, uint32_t target_duty, uint32_t scale, uint32_t cycle_num, ledc_fade_mode_t fade_mode);
/**
* #brief LEDC callback registration function
* ...
*/
esp_err_t ledc_cb_register(ledc_mode_t speed_mode, ledc_channel_t channel, ledc_cbs_t *cbs, void *user_arg);
#ifdef __cplusplus
}
#endif

How can I continuously load the position data from .txt file?

In Unity3D, I want to load position data from text file.
Here is an example of the text file.
data_01.txt
1; -5; -10
data_ 02.txt
2; 2; 5
data_03.txt
3; 2; 4
...............
all files are 1 line.
I'd like to input these data into a object.
I want to load text file in 30 text files per 1 second.
There is code saving position data.
public void Start()
{
try
{
System.IO.StreamWriter saveFile = new System.IO.StreamWriter("savefile.txt", false);
Transform[] transforms = GameObject.FindObjectsOfType(typeof(Transform)) as Transform[];
foreach (Transform t in transforms)
{
this.saveFile.WriteLine(t.position);
}
}
catch (System.Exception ex)
{
Debug.Log(ex.Message);
}
finally
{
saveFile.Close();
}
}
How can I implement code loading position data in Unity continuously?
You could write some code where you use System.IO and use that to read the text file. Then you could use Regex to split the string at a semicolon. Here is some example code. The code is written on my iPhone so it may not be perfect.
using System.io
using System.Regex
using unityengine;
StreamReader reader = new StreamReader("file name");
String read = reader.Read();
String[] points = Regex.Split(read,";");
//now you can use the points array to visualize your data
You will probably need to put this In a for loop to get all of your files but this should work. Also tell me about any mistakes in my code and I will try to fix them.

Useless use of private variable in void context in simple perl loop, no idea where the error is

if ( $num_of_things > 1) {
my $max_element = $num_of_things -1;
for($max_element; $max_element >= 0; $max_element--) {
$value_array[$max_element] = $starting_hash{$key}[$max_element];
}
All of my variables not initialized in this code snippet have been initialized as part of the larger subroutine (which I don't want to put up due to length). I'm not sure where I'm getting the useless use of private variable in void context error in this code, my compiler is telling me it's the last line (with nothing but the closing brace "}"). All help is hugely appreciated as I've been staring at this loop for almost an hour with no idea what is wrong.
Move initialization (and declaration) of $max_element into for statement.
[see ooga comment ]
for( my $max_element=$num_of_things-1; $max_element>= 0; $max_element--) {
$value_array[$max_element] = $starting_hash{$key}[$max_element];
}

How to call a function of postgis-1.5.dll in c code

I'm creating an Postgresql extension in c that use Postgis Point. when i try to call a function of postgis-1.5.dll after loading it, it fails and i get no error message
Here is a small part of my code:
Point *pt =(Point*) palloc(sizeof(Point));
bool test;
HINSTANCE DLLHandle;
typedef bool(*ST_empty)(Point*);
ST_emptyPtr ST_empty;
pt->x = 0.2;
pt->y = 0.9;
DLLHandle = LoadLibrary(L"postgis-1.5.dll");
ST_empty = (ST_emptyPtr)GetProcAddress(DLLHandle,"LWGEOM_isempty");
if (DLLHandle != NULL){
if(!ST_empty)
elog(ERROR,"null ehhhh");
test = ST_empty(p);
elog(ERROR,"not empty");
}
Could anyone help me?
It may help to look at the source:
lwgeom_is_empty from PostGIS Trunk
Are you sure it's failing? The code above doesn't test the return value from the function call. What does the following do?
if (!ST_empty(p))
elog(ERROR,"not empty");
Brian

How do a make a kMyCustomName = 1 and kMyOtherCustomName = 2 global in my code? [duplicate]

This question already has answers here:
Constants in Objective-C
(14 answers)
Closed 9 years ago.
I have the following function:
+ (int)isCorrectOnServer:(int)num {
// some code performs here...
if (this)
{
result = 2;
}
else if (this2)
{
result = 1;
}
else
{
result = 0;
}
return result; }
I want it to return like this instead:
+ (int)isCorrectOnServer:(int)num {
// some code performs here...
if (this)
{
result = kOnServer;
}
else if (this2)
{
result = kWrongType;
}
else
{
result = kNotOnServer;
}
return result; }
So anywhere in my code I could just call:
if ([Helper isCorrectOnServer:276872] == kOnServer)
to make my code cleaner and not show 0, 1, or 2 as the result. What is the best way to go about doing this?
When in doubt, see what Apple do. Look in any header file in UIKit and you will see enumeration being used for any kind of value with a finite amount of options.
Just put this in the header file:
typedef enum {
MYCustomTypeOne,
MYCustomTypeTwo,
MyCustomTypeEtcetera
} MYCustomType;
Using proper enumerations over defines allow you to do define a method like this:
+(BOOL)isCustomTypeCorrectOnServer:(MYCustomType)type;
Then the argument can be auto completed for you by Xcode. And the compiler can make much better assumptions if you use the value in a switch case for example.
add the contants to the prefix header file of your project, usually named prefix.pch
Or, an even more clean solution, would be to create a contants file, like contants.h and include this file in your prefix header file.
Prefix.pch
#include Contants.h
Contants.h
#define kMyCustomName 1
#define kMyOtherCustomName 2
#define kMyCustomName 1
#define kMyOtherCustomName 2
Within the scope that they will be used, as Felipe Sabino said to make them truly global they should be in the prefix header.